2012-05-31 30 views
0

我在WordPress中有一個類別的代碼。當我希望它顯示帖子的標題時,它顯示類別的名稱。我如何獲得它顯示正確的職位的標題。Wordpress中的類別標題顯示問題

<? query_posts('category_name=implants'); 
?> 
<h3><?php single_cat_title(); ?></h3> 
<?php if (have_posts()) : while (have_posts()) : 

the_post(); ?> 
<?php the_content(__('Read the 

rest of this page »', 'template')); ?> 
<?php endwhile; endif; ?></p> 

回答

2
  1. Do not use query_posts,除非你有意修改 默認WordPress的循環。使用WP_Query代替標準Wordpress 查詢。
  2. 看看你的代碼。你在調用single_cat_title()。這意味着 正是它的樣子:您正在拉取查詢的 類別的標題。您想調用the_title()來獲取帖子標題。
  3. 不像上面那麼重要,但你的開標籤是<?而不是 而不是<?php。您應該習慣於指定您的服務器端語言,以避免將來可能出現的問題,儘管它可能並不明顯。

下面是修改後的循環應該是什麼樣子:

<?php 
$query = new WP_Query('category_name=implants'); 
if($query->have_posts()) : while($query->have_posts()) : $query->the_post(); 
?> 
<h3><?php the_title(); ?></h3> 
<?php 
the_content(__('Read the rest of this page »', 'template')); 
endwhile; endif; 
wp_reset_postdata(); 
?> 
+0

Maiorano感謝您的回答和校正,它的工作完美。 –