WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Separate "Read more" from "php the_content" (16 posts)

  1. ghaib
    Member
    Posted 4 years ago #

    Hi, I'm doing a theme where the text (eg. content) is wrapped in a div with a bg color.

    I'd like to separate the "Read more" button in a new div below, is that possible? To separate "Read more" from the standard php the_content line:

    <?php the_content('Read more &raquo;'); ?>

    Thanks!

  2. kiano.ro
    Member
    Posted 4 years ago #

    link?

  3. ghaib
    Member
    Posted 4 years ago #

    I don't have a link at the moment, just doing some testing and research.

    Basically, is there a php string in WP to call the "read more button", which is separated from the get_content string?

    E.g. this:

    <?php the_content('Read more &raquo;'); ?>

    Becomes:

    <?php the_content(); ?> and this <?php ('Read more &raquo;'); ?>

  4. kiano.ro
    Member
    Posted 4 years ago #

    yes, it's possible to do that. but i need to see your theme and your codes. until then i cannot tell you anything about the way you can do it.

  5. Peter Boosten
    Member
    Posted 4 years ago #

    nah, this is probably what you want.

    Peter

  6. ghaib
    Member
    Posted 4 years ago #

    @kiano.ro: I posted the code, I'm basically looking to separate the two, there isn't more to it, it's not theme specific.

    Is there a code which resembles <?php ('Read more &raquo;'); ?> (without the "get_content" part)?

  7. jrav001
    Member
    Posted 4 years ago #

    In your new div, but within the same loop, put:
    <a href="<?php the_permalink(); ?>Read More</a>

  8. ghaib
    Member
    Posted 4 years ago #

    @jrav001: Thanks for the tip, it works, however, it always displays the "Read more" button, even if read more isn't used in the post.

  9. jrav001
    Member
    Posted 4 years ago #

    You can add code to the string....
    <?php the_content('<div>Read more &raquo;</div>'); ?>

  10. Mark / t31os
    Moderator
    Posted 4 years ago #

    If you're trying to end the content DIV and start a new one, then you could use..

    <?php the_content('</div><div>Read more &raquo;'); ?>

    The first closing DIV will close the current DIV (the one the content is in i assume), then open a new, which would be closed by the contents regular closing tag..

    So rather then having..

    <div>
    some content
    <div> more </div>
    </div>

    you'd end up with..

    <div>
    some content
    </div><div> more
    </div>

    ..is that what you mean?

  11. ghaib
    Member
    Posted 4 years ago #

    @t31os_

    Yep, that's exactly what I mean. I solved it partially by doing this:

    <?php the_content(''); ?>

    And then this, in a separate div:

    <a href="<?php the_permalink(); ?>">Read more</a>

    However, a new problem emerges: the "Read more" button will always be present, linking to the post, whether <!--more--> is specified in the post or not.

  12. ghaib
    Member
    Posted 4 years ago #

    bump

  13. Mark / t31os
    Moderator
    Posted 4 years ago #

    Example:

    <?php if( strpos( $post->post_content , "<!--more-->" ) != false ) { ?>
    	<div>
    		<a href="<?php the_permalink(); ?>">Read more</a>
    	</div>
    	<?php } ?>
  14. Mark / t31os
    Moderator
    Posted 4 years ago #

    To add to the above, the reasoning for using $post->post_content over get_the_content is simple.

    With get_the_content, the data has already had the shortcodes processed, therefore <!--more--> will not exist, the same does not ring true for $post->post_content.

    ghaib please mark your thread as resolved if the information supplied was sufficient.

  15. Gunjan Jaswal
    Member
    Posted 4 years ago #

    Thanks t31os_

    worked for me :)

  16. bonx
    Member
    Posted 4 years ago #

    jrav001 nearly had it but use span with display:block; not div otherwise code will not validate ;)...

    PHP:

    <?php the_content('<span class="more">Read More &raquo; </span>'); ?>

    CSS:

    .more {
      display:block;
      margin-top:10px;
      text-align:right;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags