-3

I wanted limited excerpt (40 words) with readmore link...I used this code below:

<?php echo apply_filters('the_excerpt',get_the_excerpt().'<a href="'.get_permalink().'"> read more </a>'); ?>

any help appreciated.

4

You can use the default filter for the length of the_excerpt

// Changing excerpt length
function new_excerpt_length($length) {
    return 40;
}
add_filter('excerpt_length', 'new_excerpt_length');
  • thanks bueltge, It' not working...because my code...can u tell me what's wrong... My code is: <?php $text = $post->post_excerpt;if (strlen($text) > 40) { $text = substr($text,0,strpos($text,' ',40)); } ; $text = $text . ''; echo apply_filters('the_excerpt',get_the_excerpt().'<a href="'.get_permalink().'"> Read More </a>'); ?> please help me... – Gopal Bhattacharjee Jul 20 '12 at 16:34
  • all your code is wrong for your question; use my code on the answer and put in a plugin or copy in your functions.php of your theme and it works. – bueltge Jul 23 '12 at 13:38
2

Just an addition to Bültge's answer. You can also alter the "Read more" text:

function replaceMoreText() {
    global $post; // may be you don't need this, it depends
    return '<p class="new-read-more-text"><a href="'. get_permalink($post->ID) . '">' . __('New read more text') . '</a></p>';
}
add_filter('excerpt_more', 'replaceMoreText');
0

thanks everybody,

I solved my problem....

in function.php

function get_excerpt($count){
$permalink = get_permalink($post->ID);
$excerpt = get_the_content();
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, $count);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = $excerpt.'... <a href="'.$permalink.'">Read More</a>';
return $excerpt;
}

in category.php

<?php echo get_excerpt(40); ?>

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.