Wordpress: the_excerpt not working -
i updated wordpress , content outputting module, except "the_excerpt()"
<?php function blog_feed_content(){ ?> <ul id="blog_list" class="jscroll"> <?php global $post; $args = array('category' => 4 ); $myposts = get_posts( $args ); foreach( $myposts $post ) : setup_postdata($post); ?> <li class="post clearfix" id="post-<?php the_id(); ?>"> <div class="post-content clearfix"> <h2 class="post-title"><?php the_title(); ?></h2> <div class="post-date"><?php the_time('f y') ?></div> <div class="post-text"> <?php the_excerpt(); ?> </div> </div> </li> <?php endforeach; ?> </ul> <?php } function widget_blog_feed($args){ extract($args); echo $before_widget; echo $before_title;?>blog feed<?php echo $after_title; blog_feed_content(); echo $after_widget; } function init_blog_feed() { register_sidebar_widget(__('blog_widget'), 'widget_blog_feed'); } add_action("plugins_loaded", "init_blog_feed"); ?>
why on earth isn't outputting 1 piece of content?
you're awesome. thanks.
setup_postdata
not same using normal wp_query
the_post()
not template tags work expected method of displaying posts.
you should rewrite code use custom wp_query
, traditional loop rather using foreach
iterate through post objects.
something like:
$myposts = new wp_query('cat=4'); if( $myposts->have_posts() ) : while( $myposts->have_posts() ) : $myposts->the_post(); ?> <li class="post clearfix" id="post-<?php the_id(); ?>"> <div class="post-content clearfix"> <h2 class="post-title"><?php the_title(); ?></h2> <div class="post-date"><?php the_time('f y') ?></div> <div class="post-text"> <?php the_excerpt(); ?> </div> </div> </li> <?php endwhile; wp_reset_query; endif; ?>
that should point in right direction. if set on sticking foreach
, get_posts
method use simple string functions (i.e. substr()
truncate little excerpt post_content
property of $post
object, replacing <?php the_content(); ?>
line with:
<?php echo substr($post->the_content, 0, 80); // displays first 80 chars of post ?>
Comments
Post a Comment