Probably it's not the best approach because it requires introducing a global variable but here's the idea:
In Posts_in_Page
plugin there are 2 filters, one is fired before output of these items posts_in_page_pre_loop
, and one after output end posts_in_page_post_loop
. So the plan is to create global variable which will be set to true
when you are in this plugin's loop and to false
when it's outside, so in your excerpt filter you'll be able to check it.
So here's how it can be done:
/*
* Sets our global flag that we are inside this plugin's specific loop. And returns content untouched.
*/
function my_custom_set_in_posts_pages_loop($output){
global $custom_loop_is_in_posts_in_page_post_loop;
$custom_loop_is_in_posts_in_page_post_loop = true;
return $output; // output is untouched we return it as is, because we only switch our flag.
}
add_filter('posts_in_page_pre_loop', 'my_custom_set_in_posts_pages_loop');
/*
* Sets our global flag that we are inside this plugin's specific loop. And returns content untouched.
*/
function my_custom_set_out_of_posts_pages_loop($output){
global $custom_loop_is_in_posts_in_page_post_loop;
$custom_loop_is_in_posts_in_page_post_loop = false;
return $output; // output is untouched we return it as is, because we only switch our flag.
}
add_filter('posts_in_page_post_loop', 'my_custom_set_out_of_posts_pages_loop');
function the_readmore_excerpt( $excerpt ) {
global $custom_loop_is_in_posts_in_page_post_loop;
if( isset($custom_loop_is_in_posts_in_page_post_loop) && $custom_loop_is_in_posts_in_page_post_loop ){
return $excerpt. '.. <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">' . __('Mehr lesen', 'baskerville') . ' →</a>';
}
return $excerpt; // return default excerpt if we are not in this custom plugin's loop.
}
add_filter('get_the_excerpt', 'the_readmore_excerpt');
Again it's probably not a perfect solution because of introducing a global variable, but it will work.
Plugin's filters hooks are got from here https://github.com/ivycat/posts-in-page/blob/master/includes/class-page-posts.php (lines 364, 373)
read more
in thepost-in-page-loop
from here github.com/ivycat/posts-in-page/blob/master/templates/… and the other would stay used by the system.