如果我删除'cat'=>,我在获取所有带有类别(“案例”)的帖子时遇到问题$ cat_id line我收到posttype“Feed”的所有帖子
如何只查看“案例”类别的帖子?
$cat_id = get_cat_ID('case');
var_dump($cat_id); //responce is 40
$args = array(
'post_type' => 'Feed',
'posts_per_page' => -1,
'cat' => $cat_id,
);
while ( $loop->have_posts() ) : $loop->the_post();
var_dump($loop);
endwhile;
wp_reset_query();
答案 0 :(得分:0)
<ul>
<?php
global $post;
$args = array( 'category' => 'your category name id''offset'=> 1, );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<li class="testimonial"><?php the_content(); ?></li><br/>
<?php endforeach; ?>
</ul>
<?php } ?>
了解更多信息,请查看https://codex.wordpress.org/Template_Tags/get_posts
答案 1 :(得分:0)
请尝试以下代码: 更改您的类别ID或发布ID
<?php if (is_category('3') ) { ?>
<?php query_posts('p=17'); ?>
<?php while (have_posts()) : the_post(); ?>
<h4><?php the_title(); ?></h4>
<?php the_content(); ?>
<?php endwhile;
} elseif (is_category('13') ) { ?>
<?php query_posts('p=11'); ?>
<?php while (have_posts()) : the_post(); ?>
<h4><?php the_title(); ?></h4>
<?php the_content(); ?>
<?php endwhile;
} else { ?>
//whatever goes in here
<?php } ?>