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 have this code for the_excerpt :

function get_excerpt(){
    $excerpt = get_the_content();
    $excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
    $excerpt = strip_shortcodes($excerpt);
    $excerpt = strip_tags($excerpt);
    $excerpt = substr($excerpt, 0, 640);
    $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
    $excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
    $excerpt = $excerpt.'<a class="read-more" <a href="'. get_permalink($post->ID) . '">read more.</a>';
    return $excerpt;
}`

I want to disable from one post the_excerpt. I think that this part of function helps but this is not happened.

if( in_array( $post->ID, array(post_ID) ) ) 
    get_the_content();
else
    get_excerpt();
share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

First of all, WordPress already includes a function for displaying excerpts: the_excerpt()

Secondly, your second piece of code isn't actually displaying anything. You need to use the echo statement for displaying text on the page. However, WordPress provides functions that actually display the content and excerpt on the page: the_content() and the_excerpt(), respectively.

if( in_array( $post->ID, array(post_ID) ) ) 
    the_content();
else
    the_excerpt();
share|improve this answer
    
thanks for the answer. In the second piece of code , i don't want to display anything. Actually, i want this : If the post have this post_ID, then apply the_content, else apply the_excerpt. What i am doing wrong? –  MikeD Dec 8 '12 at 10:34
    
I write this part of code, inside the loop of my index.php <?php if(in_array( $post->ID,array(333))) { the_content(); } else { echo get_the_excerpt();}?> and for this case has enabled the [..] of the_excerpt(), and i don't want this. –  MikeD Dec 8 '12 at 13:09
    
Oh i have done a big mistake. In my functions.php, i have this code : function get_excerpt(){ $excerpt = get_the_content(); and in the loop of index.php : echo get_the_content(); } else { echo get_excerpt();}. I replaced the variables correctly and it' works. :) –  MikeD Dec 8 '12 at 13:38
    
This code applied for post, how to enable for categories? –  MikeD Dec 8 '12 at 14:59
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.