dou6495 2014-09-24 11:18
浏览 36
已采纳

从两个类别获取Wordpress帖子

I am trying to display posts from two categories on one page (6 & 7). It should include posts from either category as well as the ones matching both. Unfortunately I have so far only found solutions for the latter which is why I am asking you for help now. This is my current code:

<div class="sponsoren_container_wrapper">
<?php $args = array ( 'posts_per_page' => -1, 'category' => 6 );
    $myposts = get_posts ( $args );
    foreach ($myposts as $post) : setup_postdata( $post ); ?>
    <div class="gallery_image_container">
        <a href="<?php
$content = get_the_content();
print $content;
?>" title="<?php the_title_attribute(); ?>">
            <div class="gallery_image_thumb">
                <?php the_post_thumbnail('thumbnail'); ?>
            </div>
            <div class="gallery_title">
                <h2>
                    <?php the_title(); ?>
                </h2>
            </div>
        </a>
    </div>
<?php endforeach; wp_reset_postdata(); ?>

</div> 

How would I be adding the category ID "7" to that code to make everything work as explained above? Thanks in advance!

  • 写回答

3条回答 默认 最新

  • dongyutan1703 2014-09-24 11:25
    关注

    use a comma seperated string:

    $args = array ( 'posts_per_page' => -1, 'category' => '6,7' );
    

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含