显示Wordpress中类别帖子的摘录

时间:2012-11-27 13:46:59

标签: wordpress

我正在尝试从推荐滑块中的某个类别中的帖子中显示摘录。我有上面的代码,我使用高级自定义字段自定义帖子,以显示头像,名称和报价。我将代码添加到footer.php,其中存在滑块,但出现的帖子是“Uncategorized”部分中的帖子。知道我做错了吗?

<?php $posts = query_posts('cat=testimonials&showposts=1'); foreach($posts as $post) { ?>
<?php the_excerpt(); ?>
<?php } ?>

1 个答案:

答案 0 :(得分:0)

  query_posts('cat=testimonials&showposts=1');
  while (have_posts()) : the_post();
  the_excerpt();
  endwhile;

query_posts( '猫=推荐&安培; showposts = 1');

或尝试

query_posts( '猫= CATID&安培; showposts = 1'); CATID&gt;&gt;替换为您的猫咪

更新了答案

然后尝试使用get_post

来查询query_posts
global $post;
$args = array( 'numberposts' => -1, 'category' => 1 );
$myposts = get_posts( $args );
foreach( $myposts as $post ){ echo $post->post_excerpt; }

可能对你有所帮助......

相关问题