【问题标题】:Wordpress select posts which have the category name the same as the titleWordpress 选择类别名称与标题相同的帖子
【发布时间】:2012-12-27 21:10:49
【问题描述】:

所以, 我创建了一个名为滑块的帖子类型,我使用此代码来检索它的帖子:

 query_posts(array('post_type'=>'slider',
                      'posts_per_page'=>'20'
                      ));

    //loop
    if(have_posts()) : 
        while (have_posts()) : the_post();

我在某处发现,此代码可以显示来自与页面标题同名的类别的所有帖子:

<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

如何将这两者结合起来? 我需要帖子滑块类型,这个幻灯片我已经划分了类别,所以我只需要获取以类别名称作为标题的滑块帖子类型。

谢谢

【问题讨论】:

    标签: wordpress


    【解决方案1】:
    query_posts(array('post_type'=>'slider',
                      'posts_per_page'=>'20',
                      'category_name='.get_the_title()
                ));
    

    并查看完整的文档:

    Function Reference/query posts

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-28
      相关资源
      最近更新 更多