Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to determine if the current post has a "more" tag. I'm currently using

$pos=strpos($post->post_content, '<!--more-->');

Am I missing a built in method similar to has_excerpt()?

share|improve this question
    
Not sure exactly where you're trying to run your code, but if you're on a single post view the $pages global should hold a value representing the number of pages(if the post is paged, ie. has content that spans pages, eg. it has more!).. –  t31os Jan 6 '12 at 19:28
add comment

2 Answers

up vote 1 down vote accepted

Quite simply put: there is no built in function that does the same thing as your code above.

Bonus content: More tag tricks

share|improve this answer
add comment

Making a quick note of the codes we could use to show the_content(); if the More tag exists, and the_excerpt(); if it doesn't.

Code #1 (Recommended)

<?php
    if( strpos( $post->post_content, '<!--more-->' ) ) {
        the_content();
    }
    else {
        the_excerpt();
    }
?>

(Credit: MichaelH)

Code #2

<?php
    if( strpos( get_the_content(), 'more-link' ) === false ) {
        the_excerpt();
    }
    else {
        the_content();
    }
?>

(Credit: Michael) Basically does #1 the other way around.

Code #3

<?php
    if( preg_match( '/<!--more(.*?)?-->/', $post->post_content ) ) {
        the_content();
    }
    else {
        the_excerpt();
    }
?>

(Credit: helgatheviking) For use only in edge cases where you cannot use strpos(). Generally strpos() is more efficient than preg_match().


Making it more conditional:

<?php
    if ( is_home() || is_archive() || is_search() ) {
        if( strpos( $post->post_content, '<!--more-->' ) ) {
            the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) );
        }
        else {
            the_excerpt();
        }
    }
    else {
        the_content();
    }
?>

What does it do? If the page shown is home, archive or search results page, then show the_content(); if the More tag exists, the_excerpt(); if it doesn't, and simply show the_excerpt(); on all other pages.

share|improve this answer
    
The idea of posting this answer here was to get all the codes in one place. :) –  its_me Jul 22 '12 at 4:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.