简体   繁体   English

此WordPress代码有什么问题?

[英]What's wrong with this WordPress code?

I want the following code to show the pagination if there are more than, or equal to, five wordpress posts on a page. 如果页面上有五个以上的wordpress帖子,我希望以下代码显示分页。 I don't know how to select the post. 我不知道该如何选择该职位。 This is basically why I need to do this: For example, If I go to a category that has 6 posts, and click on the bottom navigation to go see the last post from that category—since I only allow 5 posts per page—the nav works perfectly! 这基本上就是为什么我需要这样做的原因:例如,如果我转到具有6个帖子的类别,然后单击底部导航以查看该类别的最后一个帖子(因为每页只允许5个帖子),导航完美! BUT..if there is a category that only has 2 posts, and I allow 5, the styling for that nav still shows up. 但是..如果有一个类别只有2个帖子,而我允许5个,则该导航的样式仍会显示。 Is there an if/else statement that allows me to say, "if page displays < 5 posts, show this footer (without the posts_nav_link included) ?" 是否有if / else语句让我说:“如果页面显示<5个帖子,请显示此页脚(不包括posts_nav_link)?”

div class="wrapper">
<div class="pagination">
<?if(count($yourpostvariable)>=5){?>    
<li id="left">
      <?php posts_nav_link('','<span class="previous">&rarr;</span>','<span class="next">&larr;</span>'); ?>
   </li>
  <?};?>
</div><!-- end .pagination -->
</div><!-- end .wrapper -->
<?php
$args = array( 'numberposts' => '5' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){

echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look'.esc_attr($recent["post_title"]).'" >' .   $recent["post_title"].'</a> </li> ';

}
?>

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

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