Wordpress 如何按新闻类别显示帖子名称
我想按新闻类别显示帖子名称。我使用以下代码,但不工作Wordpress 如何按新闻类别显示帖子名称,wordpress,posts,Wordpress,Posts,我想按新闻类别显示帖子名称。我使用以下代码,但不工作 <?php query_posts(array('&category_name=News&showposts=5')); while (have_posts()) : the_post(); the_title(); endwhile; ?> 试试这个 <?php $args = array('cat' => 5); //pass new
<?php
query_posts(array('&category_name=News&showposts=5'));
while (have_posts()) : the_post();
the_title();
endwhile;
?>
试试这个
<?php
$args = array('cat' => 5); //pass news category Id.
// The Query
query_posts( $args );
// The Loop
while ( have_posts() ) : the_post();
echo '<li>';
the_title();
echo '</li>';
endwhile;
// Reset Query
wp_reset_query();
?>
尝试posts\u per\u page
而不是showposts
不工作它显示所有没有分类的帖子在管理中,您的分类名称(名称,而不是标签)可能不是新闻
,可能是news
。我们应该停止使用query\u posts
或者首先可以检查函数引用/查询posts。检查下面的链接。我将在那里获得新闻类别id。我无法在仪表板上找到。请阅读此[链接]它现在正在工作,但请检查您是否传递了args而不是arg。谢谢是的,谢谢@tushar的通知。