0

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 :-/

  • Then try my approach, it does not the same. – fuxia Dec 30 '12 at 19:50
0

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.

  • @cachaito Good to read that. :) Click the check mark to mark this answer as The Solution, so later readers know it works. – fuxia Jan 1 '13 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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