2011-04-02 51 views
0

無法解決此問題。我爲我的wordpress主題設置了一個自定義模板,並試圖將目前有類別鏈接和標題回顯的位更改爲帖子標題的回顯。Wordpress在循環問題中回顯the_title問題

目前反響:

echo '<h2><a href="'.$catLink.'" title="'.$category->name.'">'.$category->name.'</a></h2>'; 

誰能幫助嗎?

整版代碼:

<div id="older-posts"> 
<?php 
// Get the current category 
foreach((get_the_category()) as $category) 
{ 
    $current_cat_id = $category->cat_ID; 
    break; 
} 

// Set the category to only the category selected 
$args = array(
    'category__in' => array($current_cat_id), 
    'orderby' => 'date', 
    'order' => 'DESC' 
); 

$posts = new WP_Query(); 
$posts->query($args); 

if ($posts->have_posts()) 
{ 
    while ($posts->have_posts()) 
    { 
     echo '<div class="result">'; 
     echo '<h2><a href="'.$catLink.'" title="'.$category->name.'">'.$category->name.'</a></h2>'; 
     $posts->the_post(); 
     ?> 
     <div class="thumbnail"> 
       <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"> 
        <h3><?php the_title(); ?></h3> 
        <?php //get thumnbnail (custom field) ?> 
        <?php $image = get_post_meta($post->ID, 'thumbnail', true); ?> 
        <img src="<?php echo $image; ?>" title="<?php the_title(); ?>" /> 
        <?php the_post_thumbnail(); ?> 
       </a> 
     </div> </div> 
     <?php 

    } 
} 

// Reset global query 
wp_reset_query(); 
?> 

</div> 

回答

0

我不明白你的意思。但試試這個

//just after while() start 
       $posts->the_post(); 
?> 
    <div class="result"> 
    <h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> 
       <div class="thumbnail"> 
         <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"> 
          <h3><?php the_title(); ?></h3> 
          <?php //get thumnbnail (custom field) ?> 
          <?php $image = get_post_meta($post->ID, 'thumbnail', true); ?> 
          <img src="<?php echo $image; ?>" title="<?php the_title(); ?>" /> 
          <?php the_post_thumbnail(); ?> 
         </a> 
       </div> 
</div> 
+0

完美。正如你所建議的在$ posts-> the_post();之後移動帖子標題和鏈接。訣竅。非常感謝! – Jac 2011-04-03 10:09:27

+0

不客氣! – 2011-04-04 02:58:00