Print_r如果放在侧边栏或single.php中,则显示两个不同的post-gt; ID

时间:2012-01-08 19:16:05

标签: wordpress post tags

如果是print_r,我的网站会显示同一帖子的两个不同的ID。 如果我问:

<?php 
 echo $post->ID;?>
</div>

在single.php中它给了我一个数字。如果我在侧边栏中做同样的事情,它会给我一个完全不同的东西。

这是我在single.php

上使用print_r得到的
stdClass Object ( [ID] => 59 [post_author] => 1 [post_date] => 2012-01-01 20:29:18 
[post_date_gmt] => 2012-01-01 20:29:18 [post_content] => È universalmente
riconosciuto (...) [post_title] => fdsfdsfs [show_in_menu] => 1 [link_link] => 1
[no_follow_link] => 0 [alt_link_text] => [custom_link_class] => [redirect_url] =>
[target_blank] => 0 [alt_title_attribute] => [post_excerpt] => [post_status] => publish
[comment_status] => closed [ping_status] => closed [post_password] =>
[post_name] => fdsfdsfs [to_ping] => [pinged] => [post_modified] => 2012-01-07 19:53:44
[post_modified_gmt] => 2012-01-07 19:53:44 [post_content_filtered] =>
[post_parent] => 0 [guid] => http://www.museidibra.it/prova/?p=59 [menu_order] => 0
[post_type] => post [post_mime_type] => [comment_count] => 0
[ancestors] => Array ( ) [filter] => raw )

虽然这是我从侧边栏中得到的:

stdClass Object ( [ID] => 93 [post_author] => 1 [post_date] => 2012-01-02 08:39:29
[post_date_gmt] => 2012-01-02 08:39:29 [post_content] => prova 3 (...)
[post_title] => prova 3 [show_in_menu] => 1 [link_link] => 1 [no_follow_link] => 0
[alt_link_text] => [custom_link_class] => [redirect_url] => [target_blank] => 0
[alt_title_attribute] => [post_excerpt] => [post_status] => publish
[comment_status] => closed [ping_status] => closed [post_password] =>
[post_name] => prova-3 [to_ping] => [pinged] => [post_modified] => 2012-01-07 13:06:15
[post_modified_gmt] => 2012-01-07 13:06:15 [post_content_filtered] =>
[post_parent] => 0 [guid] => http://www.museidibra.it/prova/?p=93 [menu_order] => 0
[post_type] => post [post_mime_type] => [comment_count] => 0 [filter] => raw )

这基本上是两个不同的帖子。

注意:这件事只发生在我标记的帖子中。如果我没有标记帖子,结果ID将是相同的。

请帮助,这件事让我感到非常震惊。

由于

1 个答案:

答案 0 :(得分:0)

好的,最后我解决了问题!我需要wp_reset_query(),因为我根据页面底部的标记加载其他帖子,侧边栏中帖子的ID是最后加载的帖子。重置后,它开始显示正确的ID。