简体   繁体   English

WordPress的下一个/上一个帖子ID

[英]Wordpress next/previous post id

I'm trying to add the post id's to the next and previous posts. 我正在尝试将帖子ID添加到下一个和上一个帖子中。 Currently using the following code gives me the undesired effect of post id of the page displayed. 当前使用以下代码给我所显示页面的帖子ID的不良影响。

<div id="post-<?php the_ID(); ?>" class="project-tile nextproject">
    <a href="#"><?php next_post('%','', TRUE, '1'); ?></a></h2>
</div><!-- /project-tile -->

<div class="project-tile previousproject">
    <a href="#"><?php previous_post('%','', TRUE, '1'); ?></a>
</div><!-- /project-tile -->
// Works inside and outside of the Loop
function function_name() {
global $post;
$thePostID = $post->ID;
}
//or
echo $post->ID

Outside of the loop, use the post object WP post ID outside of loop or you can use just the one call if you don't want to set up a function. 在循环外部,请在循环外部使用post对象WP po​​st ID,或者,如果您不想设置函数,则可以只使用一个调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM