【问题标题】:How to call limit post of author on author page (wordpress)如何在作者页面(wordpress)上调用作者的限制帖子
【发布时间】:2014-08-11 22:43:30
【问题描述】:

我想在作者页面显示作者有限的posttitles。 我正在使用 wordpress loop 之外的代码来显示作者的有限帖子,代码是 <?php query_posts('posts_per_page=20'); ?> 。但它显示的是最近的帖子,我只想要作者的帖子。

如何做到这一点,有人知道吗?

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    示例代码

    <?php   
    
    $the_query = new WP_Query(array('posts_per_page'=>20,'author'=>$put_author_id_here) );
    
    while ( $the_query->have_posts() ) : the_post();
    
    /* display the post as you do in loop*/
    
    endwhile;
    
    wp_reset_postdata();
    
    ?>
    

    【讨论】:

    • 如果有多个作者,如何工作。
    • 只有一个作者可以发帖,所以作者的ID只有一个值
    • 只需创建一个以作者 ID 作为参数的函数来获取该作者的帖子并在任何仅传递作者 ID 的地方使用它
    【解决方案2】:

    使用

    query_posts('posts_per_page=20&author=$ID'); 
    

    或使用

    query_posts('posts_per_page=20&author_name="admin"');  
    

    【讨论】:

    • 它只显示最近的帖子,我想要作者的帖子:(
    • 使用我所说的或使用 wp_query 代替
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-20
    相关资源
    最近更新 更多