【问题标题】:Show post with enough of upvotes on homepage在主页上显示具有足够赞成票的帖子
【发布时间】:2013-03-25 17:27:13
【问题描述】:

所以我将 wordpress 与 updownupdown 插件(用于支持/反对帖子的插件)一起使用。我想要做的是在主页上显示帖子,假设至少有 10 个赞,并隐藏没有足够积分的帖子。

我尝试在 index.php 中使用这段代码

if (have_posts()) :
    while (have_posts()) : the_post();
        if (up_down_post_votesscore(  get_the_ID()) > 10){
        //content
        }
    endwhile;
endif;

它有点工作,它隐藏了所有少于 10 个赞的帖子,但它不会将所有符合条件的帖子放在一个页面中(主页有分页),所以假设有 2 页有 5 个帖子并且每页有 2 个帖子需要点赞数,因此不是将这 4 个帖子放在一个页面中,而是在每个页面中仅显示 2 个符合条件的帖子。

【问题讨论】:

    标签: php wordpress indexing posts


    【解决方案1】:

    听起来您的帖子检索有限。您可能希望使用以下方法更改获得的帖子数:

    query_posts( 'posts_per_page=20' );
    

    参考:http://codex.wordpress.org/Function_Reference/query_posts

    如果您使用的是get_posts,请执行以下操作:

    $args = array(
    'posts_per_page'  => 20
    );
    get_posts( $args );
    

    参考:http://codex.wordpress.org/Template_Tags/get_posts

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-11
      • 1970-01-01
      • 1970-01-01
      • 2020-12-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多