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

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

1 Answer 1

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.

1
  • @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, 2013 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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