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.

Is there any way to create "more" link for excerpt only for posts in a specific category? For example only posts in "news" category should have a more link. If there's no option for that, maybe posts in specified WP Query?

I am using this code for creating "more" link for excerpts but it works for all posts:

function excerpt_read_more_link( $output ) {
   global $post;
   return $output . '<a href="'. get_permalink( $post->ID ) . '">more</a>';
}
add_filter( 'the_excerpt', 'excerpt_read_more_link' );

toscho thak You for reply. I will check Your solution, but I remeber that I used this code:

if (in_category('news')) { 
function excerpt_read_more_link( $output ) {
   global $post;
   return $output . '<a href="'. get_permalink( $post->ID ) . '">more</a>';

add_filter( 'the_excerpt', 'excerpt_read_more_link' );
}

and this didn't work :-/

share|improve this question
    
Then try my approach, it does not the same. –  toscho Dec 30 '12 at 19:50

1 Answer 1

up vote 0 down vote accepted

Modify the callback and check the post category:

function excerpt_read_more_link( $output ) {
    global $post;

    if ( in_category( 'news', $post ) )
        return $output . '<a href="'. get_permalink( $post->ID ) . '">more</a>';

    return $output;
}

And you should prefix the function name. In its current form it is not safe enough.

share|improve this answer
    
Yes, it works! Thank You toscho :-) –  cachaito Jan 1 '13 at 15:50
    
@cachaito Good to read that. :) Click the check mark to mark this answer as The Solution, so later readers know it works. –  toscho Jan 1 '13 at 16:17

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.