如何获取当前的博客ID

时间:2013-04-06 12:43:31

标签: wordpress

我有一个页面名称“博客”,它包含一个帖子列表。

在设置 - >阅读 - >“帖子页面:”我选择了“博客”。

如何从模板中获取博客的ID。

2 个答案:

答案 0 :(得分:1)

要获取在“设置” - >“阅读” - >“帖子页面:”中选择的页面的ID,请尝试以下代码:

$frontpost_id = get_option('page_for_posts');

答案 1 :(得分:0)

如果您必须选择“博客”作为帖子页面,则必须是您之前在“页面”部分中创建的页面。

要获取当前页面的ID,您只需在页面模板中输入帖子循环后再执行$ post-> ID。首先,你做global $post。像这样:

<?php
global $post;
$current_page_id = $post->ID;
// Whatever else you're going to do
?>