我似乎不能让the_excerpt函数工作。
下面是我使用的代码
我没有调用正确的循环吗?我没有在the_excerpt的functions.php中使用任何过滤器。
任何一个都是很棒的。
$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>发布于 2012-01-17 04:47:41
对于我一直坚持的循环:
query_posts('cat=6&showposts=10');
while ( have_posts() ) {
the_post();
// do stuff
the_excerpt();
}发布于 2012-09-03 16:03:19
为了调用post,您可以使用以下代码
<?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字符,请使用以下代码
<a href="<?php the_permalink(); ?>"><?php substr($post->post_content, 0, XY); ?> ...</a>更改要显示的字符数(XY) ...
https://stackoverflow.com/questions/8886002
复制相似问题