• Resolved ghaib

    (@ghaib)


    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!

Viewing 15 replies - 1 through 15 (of 15 total)
  • link?

    Thread Starter ghaib

    (@ghaib)

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

    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.

    nah, this is probably what you want.

    Peter

    Thread Starter ghaib

    (@ghaib)

    @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)?

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

    Thread Starter ghaib

    (@ghaib)

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

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

    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?

    Thread Starter ghaib

    (@ghaib)

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

    Thread Starter ghaib

    (@ghaib)

    bump

    Example:

    <?php if( strpos( $post->post_content , "<!--more-->" ) != false ) { ?>
    	<div>
    		<a href="<?php the_permalink(); ?>">Read more</a>
    	</div>
    	<?php } ?>

    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.

    Thanks t31os_

    worked for me 🙂

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

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Separate “Read more” from “php the_content”’ is closed to new replies.