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 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.

share|improve this question
    
You've got the answers, but you can always refer to the_excerpt(); on WP Codex. –  its_me Jul 16 '12 at 8:38
1  
No question in this question. –  toscho Jul 16 '12 at 9:42

3 Answers 3

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); ?>
share|improve this answer

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');
share|improve this answer

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');
share|improve this answer
    
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

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.