the_content() ignores <!--more--> when using get_posts and setup_postdata (5 posts)

  1. stianthaulow
    Posted 8 years ago #

    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...

  2. JesseG5
    Posted 8 years ago #

    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.

  3. stianthaulow
    Posted 8 years ago #

    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

  4. lordyama
    Posted 7 years ago #

    Solution at: http://wordpress.org/support/topic/164560

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

  5. analogue40
    Posted 7 years ago #

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

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

Topic Closed

This topic has been closed to new replies.

About this Topic