我目前正在使用loop\\u end钩住我的插件并从页面获取帖子id。这很好用,除了它还在最近的帖子小部件中显示我的插件,我不想这样。
有没有更好的方法来做到这一点,使其只显示在页面内容上,而不显示小部件?
我目前正在使用loop\\u end钩住我的插件并从页面获取帖子id。这很好用,除了它还在最近的帖子小部件中显示我的插件,我不想这样。
有没有更好的方法来做到这一点,使其只显示在页面内容上,而不显示小部件?
loop_end
钩子正在通过WP_Query
对象作为参数。您可以使用is_main_query()
方法(不要与同名函数混淆),它只对主查询有效,对辅助查询无效。
在期间获取IDtemplate_redirect
在调用任何小部件之前:
add_action( \'template_redirect\', function(){
$my_plugin = new My_Plugin;
$my_plugin->get_id();
});
class My_Plugin
{
protected $post_id;
public function get_id()
{
if ( is_page() )
$this->post_id = get_the_ID();
}
}
现在您可以使用$post_id
在同一类的后续方法中。I would like to have to query loops running on my blog homepage:Featured posts on top displaying 3 posts from the category : \"Featured\"Underneath it just the basic loop of wordpress which display the latest (10 or other, whatever is selected within the