简体   繁体   English

WordPress的下一个和上一个帖子链接?

[英]wordpress next and previous post link?

i want add next post and previous post link my each post. 我想添加下一个帖子上一个帖子链接我的每个帖子。 i already do it. 我已经做到了。 but i want when last post that time next post link will hide and first post time previous post will be hide 但我想在上次发布时隐藏下一个发布链接,而上次发布前一个帖子将隐藏

bellow my code is working ... 下面我的代码正在工作...

 <?php
     $prev_post = get_previous_post();
     if (!empty( $prev_post )): ?>
      <a href="<?php echo get_permalink( $prev_post->ID ); ?>" title="<?php echo $prev_post->post_title; ?>" class="prev-post">
      <span class="left_arrow"></span> <?php _e("Previous Post", "twentytwelve"); ?></a>
    <?php endif; ?>


    <?php
    $next_post = get_next_post();
    if (!empty( $next_post )): ?>
    <a href="<?php echo get_permalink( $next_post->ID ); ?>" title="<?php echo $next_post->post_title; ?>" class="next-post">
    <?php _e("Next Post", "twentytwelve"); ?>&nbsp; <span class="right_arrow"></span></a>
    <?php endif; ?>

bellow one suppose to work to but not. 在下面的人应该工作,但没有。

<?php if($show_prevnext_post == 1) { ?>

    <?php
     $prev_post = get_previous_post();
     if (!empty( $prev_post )): ?>
      <a href="<?php echo get_permalink( $prev_post->ID ); ?>" title="<?php echo $prev_post->post_title; ?>" class="prev-post">
      <span class="left_arrow"></span> <?php _e("Previous Post", "twentytwelve"); ?></a>
    <?php endif; ?>



    <?php
    $next_post = get_next_post();
    if (!empty( $next_post )): ?>
    <a href="<?php echo get_permalink( $next_post->ID ); ?>" title="<?php echo $next_post->post_title; ?>" class="next-post">
    <?php _e("Next Post", "twentytwelve"); ?>&nbsp; <span class="right_arrow"></span></a>
    <?php endif; ?>


    <?php } ?>

i don't understan why this is not working. 我不明白为什么这不起作用。 should i need to anything in function.php 我应该在function.php中需要什么吗

Take a look at WordPress's previous_post_link () and next_post_link () functions. 看一下WordPress的previous_post_link ()和next_post_link ()函数。 They will only output a link if there's a prev/next post. 仅当有上一个/下一个帖子时,他们才会输出链接。 But it will only work if you use them in the WordPress Post Loop 但是,只有在WordPress Post Loop中使用它们时,它才有效

Hope that helps :-) 希望有帮助:-)

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

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