WordPress.org

Ready to get started?Download WordPress

Forums

grab more link as variable? (4 posts)

  1. Doodlebee
    Member
    Posted 4 years ago #

    This is a bizarre question, I know... but I wanted to know if I could possibly grab the more link (i.e. the_content('read more');) as a variable to see if it's being applied?

    basically I need to put the link in a weird spot that isn't customizable via CSS (which is how I normally do it). Instead of at the end of the post content, I need it to be in the post meta section. Right now, I basically used $strip_teaser to make it invisible at the end of the post, and hard-coded a read more link in the post meta. However, now the link shows up on ALL posts - whether <--more--> is used or not. SO I was wondering if there was a way to grab it as some kind of variable and either echo it out in a new spot, or check to see if <!--more--> was used and if so, have the link display.

    I know I could probably do this with a filter, but I was hoping for a cleaner (and faster) method?

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    Could you use a combination of get_the_content and strpos to check for a class="more-link"?

  3. Doodlebee
    Member
    Posted 4 years ago #

    Yeah, that *is* what I ended up doing, but for some reason, it's not taking. I'm troubleshooting more (there's got to be some odd reason as to why - maybe a good night's sleep has helped and I'll see it), but i was hoping for something a little simpler than that. Oh well, whatever works I guess ;) If I figure out why my code isn't taking, I'll post the solution.

    Thanks! :)

  4. revmitcz
    Member
    Posted 4 years ago #

    esmi had it right. I had to do this same thing for a theme to display a custom thumbnail only for posts which used "<!--more-->" and the code I used was :

    <?php if(strpos(get_the_content(),'class="more-link"') !== false) : ?><img src="<?php $key="thumbnail"; echo get_post_meta($post->ID, $key, true); ?>" alt="thumbnail" class="thumbnail" /><?php endif; ?>

    Worked out perfectly. Thanks, esmi.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.