Reputation: 2087
I've been trying to put a read more.. at the end of excerpt so far no luck.
I've tried this which works okay but it put the read more... at the bottom of the excerpt.
the_excerpt();
echo '<a class="read-more" href="'. get_permalink( get_the_ID() ) . '">Read More...</a>';
is there a way to do it like
the_excerpt("Read more..");
Upvotes: 0
Views: 1361
Reputation: 365
I got another way to display limited excerpt by character. Here is the functions.php file code.
function get_excerpt(){
$excerpt = get_the_content();
$excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
$excerpt = strip_shortcodes($excerpt);
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, 100);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
$excerpt = $excerpt.'... <a href="'.get_the_permalink().'">Read More</a>';
return $excerpt;
}
After this you need to add where you want to display your customized character by character.
<?php echo get_excerpt(); ?>
@ http://www.e2soft.com/forum/question/how-to-set-custom-excerpt-and-content-limit-wordpress/
Upvotes: 0
Reputation: 365
Add the following code to your functions.php file.
<?php
// Custom Excerpt
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
}
?>
Usage :
<?php echo excerpt(25); ?>
Source: http://www.e2soft.com/blog/custom-excerpt-and-content-limit-wordpress/
Upvotes: 0
Reputation: 1615
You can simply try the recommended way provided by WordPress ::
Excerpts (teasers) can be shown on WordPress through two methods:
Keeping the the_content() template tag and inserting a quicktag called more
at your desired "cut-off" point when editing the post.
By replacing the the_content() template tag with the_excerpt().
And for changing the "Read More" text link you can make use of the parameters used with the_content
like this
<?php the_content( $more_link_text , $strip_teaser ); ?>
Source => http://codex.wordpress.org/Customizing_the_Read_More
Hope it helps
Upvotes: 0
Reputation: 2265
put the following in your theme's functions.php.
function new_excerpt_more( $more ) {
return ' <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">' . __('Read More', 'your-text-domain') . '</a>';
}
add_filter( 'excerpt_more', 'new_excerpt_more' );
Upvotes: 1
Reputation: 1007
here is what you want
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
}
function content($limit) {
$content = explode(' ', get_the_content(), $limit);
if (count($content)>=$limit) {
array_pop($content);
$content = implode(" ",$content).'...';
} else {
$content = implode(" ",$content);
}
$content = preg_replace('/\[.+\]/','', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
Usage :
<?php echo excerpt(25); ?>
Source : http://bavotasan.com/tutorials/limiting-the-number-of-words-in-your-excerpt-or-content-in-wordpress/
Upvotes: 0