Forums

[resolved] Display content after More tag (10 posts)

  1. dOoBiX
    Member
    Posted 3 years ago #

    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?

  2. MichaelH
    Volunteer
    Posted 3 years ago #

    In a loop try this:

    $aftermore = 11 + strpos($post->post_content, '<!--more-->');
    echo 'this is after the more >' . substr($post->post_content,$aftermore);
  3. safaris
    Member
    Posted 3 years ago #

    Thanks. Was having that problem too.

  4. dOoBiX
    Member
    Posted 3 years ago #

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

  5. Sunira
    Member
    Posted 3 years ago #

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

  6. Three-Star Dave
    Member
    Posted 2 years ago #

    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?

  7. Three-Star Dave
    Member
    Posted 2 years ago #

    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; ?>

  8. cooperanet
    Member
    Posted 2 years ago #

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

    Any ideas to avoid this problem?

  9. Hiranthi Molhoek-Herlaar
    Member
    Posted 2 years ago #

    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.

  10. peterjharrison
    Member
    Posted 2 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic