• Resolved doobix

    (@doobix)


    On my home page, i have the posts showing the content before the <!–more–> tag.

    When users click the post to read more, i only want the content after the <!–more–> tag to be displayed. How can I do this?

Viewing 9 replies - 1 through 9 (of 9 total)
  • In a loop try this:

    $aftermore = 11 + strpos($post->post_content, '<!--more-->');
    echo 'this is after the more >' . substr($post->post_content,$aftermore);

    Thanks. Was having that problem too.

    Thread Starter doobix

    (@doobix)

    Thank you MichaelH! May I ask what does the “11 +” before the strpos do?

    Oh my god, thanks so much! I was pulling my hairs out a bit with this one.

    Also, dOoBiX, the 11 is the number of characters the <–more–> quicktag is. MichaelH is starting his content substring after the more tag when he does that.

    A small tweak would be to change the code as such:

    $aftermore = 3 + strpos($post->post_content, ‘–>’);
    echo ‘this is after the more >’ . substr($post->post_content,$aftermore);

    This way you can use custom more tags. Of course, this means no putting –>’s in your posts by themselves but most of us can live with that, I think. 😉

    three-star-dave

    (@three-star-dave)

    The above works … if there is, in fact, More text. If there’s no more text, it repeats the whole post. Is there a way to test for that situation?

    three-star-dave

    (@three-star-dave)

    Answering my own question here:

    <?php if (strpos($post->post_content, ‘–>’)) : ?>
    <?php $aftermore = 3 + strpos($post->post_content, ‘–>’);
    echo substr($post->post_content,$aftermore);
    ?>
    <?php endif; ?>

    Great work! But it seems that using this solution breaks the content layout like captions, list, etc.

    Any ideas to avoid this problem?

    You can also use something like this:

    <?php
    $morestring = '<!--more-->';
    $explodemore = explode($morestring, $post->post_content);
    echo $explodemore[0]; // before the more-tag
    echo $explodemore[1]; // after the more-tag
    ?>

    However, you should watch where you’re putting the more-tag though.

    I have used this and it works great apart from one thing. Does any one know how you can get it to work when you have page codes in the content after the more tag.

    Instead of reading the page code and rendering my content, it just displays the page code in the content.

    Cheers
    Pete

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Display content after More tag’ is closed to new replies.