Support » Fixing WordPress » the_content() ignores <!–more–> when using get_posts and setup_postdata

  • I’m using a static page to list all the posts of one category like this:

    <?php $posts = get_posts('category=1');
    	foreach($posts as $post) :
    		setup_postdata($post); ?>
    		<div class="post">
    			<h2><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></h2>
    			<? the_content(); ?>
    			<small><?php the_time('F jS, Y') ?></small>
    			<p class="postmetadata"><?php edit_post_link('Edit', '', ''); ?>
    	<?php endforeach; ?>

    But the_content() seems to ignore the <!–more–> tags when getting posts this way… All posts are shown in full length…

Viewing 4 replies - 1 through 4 (of 4 total)
  • I am not using a static page but when I insert the <!–more–> tag using the_content it breaks fine. However it does cause other problems. My background color dissapears and my sidebar moves to the bottom of site. Wierd.

    Yeah, I forgot to say: the <!–more–> tag works fine when using the_content() in the regular loop on the ordinary posts page (the one using the index.php template from my theme)

    It’s only when I override the query (after the page is fetched) by using get_posts() and setup_postdata() that the_content() ignores <!–more–>

    @jesseg5: check if you’ve got any html start-tags in your posts, if the <!–more–> comes before the end-tags, it can mess up your site



    Solution at:

    You need to use <?php global $more; $more = 0; the_content(); ?>

    cheers for the tip, took me a few mins before realising

    $more = 0; turns more on
    $more = 1; turns more off

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘the_content() ignores <!–more–> when using get_posts and setup_postdata’ is closed to new replies.