Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 如何按新闻类别显示帖子名称_Wordpress_Posts - Fatal编程技术网

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的通知。