首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wordpress the_excerpt不工作

wordpress the_excerpt不工作
EN

Stack Overflow用户
提问于 2012-01-17 04:42:33
回答 2查看 2.3K关注 0票数 0

我似乎不能让the_excerpt函数工作。

下面是我使用的代码

我没有调用正确的循环吗?我没有在the_excerpt的functions.php中使用任何过滤器。

任何一个都是很棒的。

代码语言:javascript
复制
$col = 0;
$col_count = 3;
$cols = array();
// $my_query = new WP_Query( 'category_name=projects&posts_per_page=3');
// while ($my_query->have_posts()) : $my_query->the_post();
global $post;
$args = array( 'numberposts' => 3, 'offset'=> 0, 'category_name' => 'projects' );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :  setup_postdata($post); 
  if($col >= $col_count) $col = 0;
  ob_start();
  ?>
  <div class="post" id="post-'<?php the_ID(); ?>'">
    <span class="title"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></span>
    <div class="descr"><img src="<?php bloginfo( 'template_url' ); ?>/lib/img/clock.png"> <?php the_time('F, jS'); ?>, <span class="author"><?php the_time('Y'); ?> by <?php the_author_posts_link() ?></span></div>
    <div class="entry">
      <?php the_excerpt(); ?>
    </div>
  </div>
  <?php
  $output = ob_get_contents();
  ob_end_clean();
  $cols[$col++] .= $output;
 endforeach; wp_reset_postdata();
?>
<div class="columns">
<?php
foreach($cols as $key => $col)
  echo '<div class="column column' . $key . '">' . $col . '</div>';
?>
</div>
EN

回答 2

Stack Overflow用户

发布于 2012-01-17 04:47:41

对于我一直坚持的循环:

代码语言:javascript
复制
query_posts('cat=6&showposts=10');

while ( have_posts() ) {
    the_post();

    // do stuff
    the_excerpt();

}
票数 1
EN

Stack Overflow用户

发布于 2012-09-03 16:03:19

为了调用post,您可以使用以下代码

代码语言:javascript
复制
<?php
global $post;
$args = array( 'numberposts' => 5, 'category' => 3 );


$myposts = get_posts( $args );
foreach( $myposts as $post ) :
setup_postdata($post); ?>

<?php the_title(); ?>
<?php the_content(); ?>

<?php endforeach; ?>

替换您要显示的Cat ID和帖子编号。

要限制post字符,请使用以下代码

代码语言:javascript
复制
<a href="<?php the_permalink(); ?>"><?php substr($post->post_content, 0, XY); ?> ...</a>

更改要显示的字符数(XY) ...

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8886002

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档