【问题标题】:Display Excerpt from Category post in Wordpress在 Wordpress 中显示类别帖子的摘录
【发布时间】:2012-11-27 13:46:59
【问题描述】:

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

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

【问题讨论】:

  • 也尝试了以下方法,但没有成功:code

标签: wordpress


【解决方案1】:
  query_posts('cat=testimonials&showposts=1');
  while (have_posts()) : the_post();
  the_excerpt();
  endwhile;

query_posts('cat=testimonials&showposts=1');

或者试试

query_posts('cat=CATID&showposts=1'); CATID >> 替换为您的猫 ID

更新答案

然后尝试使用 get_post 代替 query_posts

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

或许能帮到你……

【讨论】:

    • 5, 'offset'=> 1, 'category' => 1); $myposts = get_posts($args); foreach( $myposts as $post ){
猜你喜欢
  • 2012-08-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多