I have used excerpt_more
filter in a theme's functions.php and in a plugin's functions.php. Here is the code for the theme
function theme_excerpt_more( $more ) {
return '...';
}
add_filter('excerpt_more', 'theme_excerpt_more');
and here is the code for the plugin
function newsbox_excerpt_more($more) {
global $post;
$options = get_option('newsbox_plugin_display_options');
if(isset($options['read_more_text'])){
$read_more_text = $options['read_more_text'];
}
else{
$read_more_text = "Read More »";
}
return '...<a href="'. get_permalink($post->ID) . '">' . $read_more_text . '</a>';
}
add_filter('excerpt_more', 'newsbox_excerpt_more');
But only the theme's excerpt_more
is working. I want the plugin excerpt_more
to work on the post that will set in the shortcode. This is the shortcode
[news_box posts_per_page=-1 news_box_title="Latest News" post_type="latest_news" category ="Uncategorized"]
If I don't set post_type
, then the plugin's excerpt_more
will work on the default post.
Any suggestions to achieve this?
Edit: Full code
function newsbox_new_loading_shortcod($atts){
extract(shortcode_atts(array(
'posts_per_page'=>'-1',
'news_box_title'=>'Latest News',
'post_type'=>'post',
'category'=>''
),$atts,'news_box'));
$q = new WP_Query(
array('posts_per_page' => $posts_per_page,'post_type'=>array($post_type),'category_name'=>$category));
$list = '<div class="panel panel-default">
<div class="panel-heading"> <span class="glyphicon glyphicon-list-alt"></span><b>'.$news_box_title.'</b></div>
<div class="panel-body">
<div class="row">
<div class="col-xs-12">
<ul class="news_list">';
while($q->have_posts()) : $q->the_post();
$newsbox_post_img_src = wp_get_attachment_image_src( get_post_thumbnail_id(), '', false );
$list .= '<li class="news-item">
<table cellpadding="4">
<tr>
<td><img src="'.$newsbox_post_img_src[0].'" width="100" class="img-circle" /></td>
<td>'.get_the_excerpt().'</td>
</tr>
</table>
</li>';
endwhile;
wp_reset_postdata();
return $list . '</ul>
</div>
</div>
</div>
<div class="panel-footer"> </div>
</div>';
}
add_shortcode('news_box','newsbox_new_loading_shortcod');
$post
object, so you can check with$post->post_type
. – Chittaranjan Sep 2 '14 at 8:13excerpt_more
to there plugin and also use my plugin then it will make a conflict. For that reason i need to check that. @Chittaranjan – Alamin Sep 2 '14 at 8:26add_filter('excerpt_more', 'newsbox_excerpt_more', 100);
– Nilambar Sharma Sep 2 '14 at 11:32