Wordpress插件不显示用户ID和页面ID

时间:2013-11-29 03:59:41

标签: php wordpress plugins

我正在Wordpress中创建一个插件,我需要当前用户ID和当前页面的ID。我已经尝试了我在网上找到的所有代码,但是他们要么没有显示任何内容,要么根本没有加载页面。

例如,当我输入:

global $wp_query;
$page = $wp_query->get_queried_object();
$page_id = $page->ID;

页面根本没有加载;只是空白。

我发现唯一有用的是如果我使用了一个钩子,但这只会使ID显示在内容中,这使我无法将它们存储在单独的变量中。

所以我进入了:

add_filter('the_content', 'post_page');

function post_page($content){
global $post;
if($post->post_type == 'page'){
    $content .= '<br /> This item is a page and the ID is: '.$post->ID;
} elseif($post->post_type == 'post') {
    $content .= '<br /> This item is a post and the ID is: '.$post->ID;
}
return $content;
}

ID显示,但它在帖子本身。我似乎无法将它们存储在我可以随时调用的变量中。

0 个答案:

没有答案