帖子/博客页面的ID
-
-
不是发挥搜索引擎帮助程序的最大贡献,但是,这可能适用于:$postspage_id=get_option('page_for_posts');`来自:http://www.blog.highub.com/cms/wordpress/wordpress-front-page-posts-page-id/not the best contribution playing search engine helper, however, this might apply: `$postspage_id = get_option('page_for_posts');` from: http://www.blog.highub.com/cms/wordpress/wordpress-front-page-posts-page-id/
- 0
- 2012-02-25
- Michael
-
@Michael-将其发布为答案吗?@Michael - post this as an answer?
- 0
- 2012-02-25
- Stephen Harris
-
将建议转化为答案.moved the suggestion into an answer.
- 0
- 2012-02-25
- Michael
-
2 个回答
- 投票数
-
- 2012-02-25
考虑使用:
$postspage_id = get_option('page_for_posts');
,然后将代码中的相应行更改为:
$leftSidebar = get_post_meta( $postspage_id, '_my_meta', true );
来自: http://www.blog.highub.com/cms/wordpress/wordpress-front-page-posts-page-id/
consider to use:
$postspage_id = get_option('page_for_posts');
and then change the rspective line in your code to:
$leftSidebar = get_post_meta( $postspage_id, '_my_meta', true );
from: http://www.blog.highub.com/cms/wordpress/wordpress-front-page-posts-page-id/
-
谢谢上面它对我有用.我只需要检查当前查看的页面是否是博客页面.这可以通过`if(is_home($postpage_id))`来完成,如果所查看的页面是博客/帖子页面,则评估结果为true.使用`is_home`进行检查是一个至关重要的难题,因为`is_page`等不适用于博客页面.我在此[post](http://wordpress.stackexchange.com/questions/14768/determine-if-page-is-the-posts-page)上找到了相关信息.我将其标记为答案.Thanks the above it works for me. I just have to do a check if the current page I am viewing is the blog page. This can be done by `if (is_home($postpage_id))` which will evaluate to true if the page viewed is the blog/posts page. Using `is_home` to check was a vital piece of the puzzle because `is_page` etc. do not work for the blog page. I found out about this at this [post](http://wordpress.stackexchange.com/questions/14768/determine-if-page-is-the-posts-page). I am marking this as an answer.
- 0
- 2012-02-26
- navanitachora
-
- 2012-02-25
如果您使用的是
query_posts
(由于它会更改主循环,因此有一些缺点),因为法典说,如果必须使用query_posts(),请确保在完成后调用wp_reset_query().
(例如,参见
wp_reset_query()
)// The Query query_posts( $args ); //your $args // The Loop while ( have_posts() ) : the_post(); //Display title, content here etc. endwhile; // Reset Query afterwards wp_reset_query();
如果您不使用
query_posts
,则可能仍需要使用wp_reset_postdata()
其中...遍历单独的查询后,此函数将$post全局值还原到主查询中的当前帖子.
If you are using
query_posts
(which has some drawbacks since it alters the main loop), as the Codex says,If you must use query_posts(), make sure you call wp_reset_query() after you're done.
(See codex
wp_reset_query()
)for For example// The Query query_posts( $args ); //your $args // The Loop while ( have_posts() ) : the_post(); //Display title, content here etc. endwhile; // Reset Query afterwards wp_reset_query();
If you are not using
query_posts
you may still need to usewp_reset_postdata()
which...After looping through a separate query, this function restores the $post global to the current post in the main query.
-
我没有使用query_posts,并且尝试了wp_reset_query()和wp_reset_postdata(),但均无济于事.是否有其他选择可以使我的博客页面识别为博客页面.I am not using query_posts and I have tried both wp_reset_query() and wp_reset_postdata() but to no avail. Are there any alternatives that will make my blog page recognize itself as the blog page.
- 0
- 2012-02-25
- navanitachora
-
您必须更新您的问题并提供用于循环的代码,否则很难说错了.You'll have to update your question and provide the code you are using for the Loop, hard to say what's wrong otherwise.
- 0
- 2012-02-25
- Stephen Harris
-
我已经用循环代码更新了问题.I have updated the question with the code for the loop.
- 0
- 2012-02-25
- navanitachora
我有一个网站,该网站有一个静态首页和一个显示所有博客的博客页面.
我正在使用自己的主题,并基于
$post->ID
的返回值创建了一些自定义的meta框,它们在边栏中显示内容.我得到的有趣的行为是$post->ID
给了我第一个博客的ID,而不是博客页面本身的ID.我在循环外使用$post并已将其声明为全局,但无济于事.我也尝试过使用$wp_query->post->ID
,但这会给我最后一篇文章的ID.相关的代码是我使用$post的地方,下面的这段代码位于footer.php中:
用于循环的代码在下面,并放置在index.php中:
如果需要任何其他信息,请告诉我.如果有一种方法可以通过编程方式找到博客页面的ID,并使该博客页面将自己识别为博客页面,而不是第一个解决我认为的问题的帖子.
谢谢.