大家好,我正在创建一个插件,其中我正在制作一个自定义的post-type季节。现在,我想在基于数据库查询的季节单页上回显一些内容。我已经解决了查询和逻辑问题,但我只想在季节性插件文件的单个页面上进行回应,而不是创建单个模板,然后使用类似过滤器的帖子类型模板。如果你能给echo看“你好,世界”;只有在post\\u type=“season”这才是最好的。谢谢
Edit single page from plugin
1 个回复
最合适的回答,由SO网友:Jeroen Schmit 整理而成
你可以用the_content
过滤器:
/**
* Adds some text to bottom of the content on \'season\' pages.
*
* @param string $content The current content of the season page.
* @return string The new content of the season page.
*/
function add_season_content( $content ) {
if ( is_singular( \'season\' ) && is_main_query() ) {
// collect your season data over here...
$season_data = \'Hello world\';
$content .= $season_data;
}
return $content;
}
add_filter( \'the_content\', \'add_season_content\' );
将此代码放在插件文件中的任意位置。