WP - 按类别获取帖子? [英] WP -- Get posts by category?

查看:28
本文介绍了WP - 按类别获取帖子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的页面模板中使用它来按类别获取帖子:

I'm using this in my page template to get posts by their category:

<?php 
        if (is_page(19)){
            ?>
            <ul>
            <?php
                global $post;
                $args = array( 'category' => 'Testimonial' );
                $myposts = get_posts( $args );
                foreach( $myposts as $post ) :  setup_postdata($post); ?>
                    <li class="testimonial"><?php the_content(); ?></li><br/>
                <?php endforeach; ?>
            </ul>
        <?php } ?>

但它正在检索所有帖子.不仅仅是那些标记为推荐的.知道我做错了什么吗?

but it's retrieving all posts instead. Not just the ones labeled Testimonial. Any idea what I'm doing wrong?

推荐答案

在这里查看:http://codex.wordpress.org/Template_Tags/get_posts

注意:category参数需要是category的ID,并且不是类别名称.

Note: The category parameter needs to be the ID of the category, and not the category name.

这篇关于WP - 按类别获取帖子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆