Forums

Place "Read More" link outside of post content (5 posts)

  1. ericcarl
    Member
    Posted 8 months ago #

    I'm building a theme that needs to have the "Read More" link placed outside of the post content. Right now my code looks like this:

    <?php the_content('Read More'); ?>

    Which results in this:

    <p>The post content. <a href="..." class="more-link">Read More</a></p>

    ... but this is what I need:

    <p>The post content.</p>
    <a href="..." class="more-link">Read More</a>

    I can't set more-link as a block element because I need it to float, which causes it to interact incorrectly with the paragraph content its contained in. I would prefer not to use the_excerpt unless I have to.

    Is there maybe some way to do this in the theme's functions.php? Thanks for any help!

  2. esmi
    Theme Diva & Forum Moderator
    Posted 8 months ago #

    <?php the_content('', false,'');?>
    <a href="<?php the_permalink();?>#more-<?php echo $post->ID;?>"><?php _e('Read more');?></a>
  3. ericcarl
    Member
    Posted 8 months ago #

    Thanks esmi! That does work but it also includes the "Read More" link on every post, not just on the ones using the "Read More" quicktag. Is there a way to do something like this, that checks to see if the Read More link is necessary or not?

    <if read more is used in the post><a>Read More</a></if>

  4. esmi
    Theme Diva & Forum Moderator
    Posted 8 months ago #

    So far, I've not found a foolproof way of doing this that wouldn't have a pretty big performance hit as you'd have to parse the content of every post for the <--more--> tag.

  5. ericcarl
    Member
    Posted 8 months ago #

    All right, thanks for the help!

Reply

You must log in to post.

About this Topic

Tags