2013-05-07 154 views
0

我試圖在slidesow中使用一組8張貼圖精選圖像縮略圖下的自定義字段來顯示一個替代的縮短的帖子標題。我可以用這個代碼片段顯示這些縮略圖下的相應文章的標題:

<?php $titletext = get_the_title(); echo($arr[$i]['titletext']); ?> 

,我還可以在循環中顯示的自定義字段:

<?php $key="short_title"; echo get_post_meta($post->ID, $key, true); ?> 

但是,這兩個是我的任意組合已經在循環之外嘗試過,沒有返回任何內容,或者在每個縮略圖下返回「Array」。解決方案感覺很明顯,但它避開了我。有人能告訴我如何正確地做到這一點?

添加更多的代碼澄清:

<?php if (have_posts()) : while (have_posts()) : the_post(); 
    global $post; ?> 
     <?php if ($responsive) { ?> 
      <li class="slide"> 
     <?php } else { ?> 
      <div class="slide"> 
     <?php } ?> 
       <?php 
       $width = $responsive ? 560 : 558; 
       $height = 340; 
       $small_width = 110; 
       $small_height = 63; 
       $titletext = get_the_title(); 

       $thumbnail = get_thumbnail($width,$height,'',$titletext,$titletext,false,'Featured'); 

       $arr[$i]['thumbnail'] = get_thumbnail($small_width,$small_height,'',$titletext,$titletext,false,'Small'); 
       $arr[$i]['titletext'] = $titletext; 

       $thumb = $thumbnail["thumb"]; 
       print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height); ?> 
       <div class="featured-top-shadow"></div> 
       <div class="featured-bottom-shadow"></div> 
       <div class="featured-description scrollcustom"> 
       <div class="feat_desc"> 
        <h2 class="featured-title"><a href="<?php the_permalink(); ?>"><?php the_title() ?></a></h2> 

         <p>     <?php $key="short_title"; echo $shorttitle; ?> <?php the_content(); ?></p> 
        </div> 

       </div> <!-- end .description --> 

     <?php if ($responsive) { ?> 
      </li> <!-- end .slide --> 
     <?php } else { ?> 
      </div> <!-- end .slide --> 
     <?php } ?> 
     <?php $i++; endwhile; endif; wp_reset_query(); ?> 
<?php if ($responsive) { ?> 
    </ul> <!-- end .slides --> 
<?php } else { ?> 
    </div> <!-- end #slides --> 
<?php } ?> 
</div> <!-- end #featured --> 

<div id="controllers" class="clearfix"> 
    <ul> 
     <?php for ($i = 0; $i < $featured_num; $i++) { ?> 
      <li> 
       <div class="controller " > 
        <a href="#"<?php if ($i == 0) echo ' class="active"'; ?>> 
        <?php $titletext ?> 
         <?php print_thumbnail($arr[$i]['thumbnail']['thumb'], $arr[$i]['thumbnail']["use_timthumb"], $arr[$i]['titletext'], $small_width, $small_height); ?> 
        <span class="overlay"></span><br> 
            <?php echo($arr[$i]['titletext']); ?> 
        </a> 
       </div> 
      </li> 
     <?php } ?> 
+1

粘貼整個循環碼之外。 – 2013-05-07 15:27:54

+0

它在循環之外,所以我不確定這會有所幫助。然而,增加澄清。 – EllieMental 2013-05-07 18:47:39

+0

@ user1279351粘貼與您的問題相關的破解代碼,並指明破壞的位置。 – montrealist 2013-05-07 21:22:20

回答

0

你需要global $post,如果你是循環

+1

這幾乎沒有答案。 – montrealist 2013-05-07 16:40:17

+0

@dalbaed這是答案。 'global $ post'是一個保存查詢的全局變量。如果你在循環中,你不需要它。 – 2013-05-07 17:59:12