wordpress the_excerpt 不工作
我似乎无法让 the_excerpt 函数工作。
这是我正在使用的代码
我没有调用循环吗? 我没有在 Functions.php 中对 the_excerpt 使用任何过滤器。
任何任何都会很棒。
$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>
I can not seem to ger the_excerpt function to work.
Here is the code I am using
Am I not calling the loop right?
I am not using any filters in my functions.php for the_excerpt.
Any any would be great.
$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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于循环我始终坚持:
For the loop I always stick to:
对于调用帖子,您可以使用此代码
替换 Cat ID 和您要显示的帖子数量。
为了限制后字符,请使用此代码
更改要显示的字符数 (XY)...
For calling post you can use this code
Replace the Cat ID and number of post you want to display.
And for limiting the post character use this code
Change the number of character (XY) you want to dispaly...