简体   繁体   English

WordPress发布分页不起作用

[英]WordPress Posts Pagination Not Working

I am having problems with the post pagination of this certain category. 我在某些类别的分页中遇到问题。 I have this working 'Previous' and 'Next' using the previous_post_link() and next_post_link() . 我使用previous_post_link()next_post_link()使此“ Previous”和“ Next” next_post_link() I have several issues regarding this. 我对此有几个问题。 I'll just number it so it will be organized. 我将对其编号,以便将其组织起来。

  1. 'First' - when clicked, it will go to the first post or the newest post in Wordpress and same goes to the 'Last'. “第一”-单击后将转到Wordpress中的第一篇文章或最新文章,而到“最后”文章。 I was looking for a PHP call for this. 我正在为此寻找一个PHP调用。
  2. 2 3 4 5 - pagination numbers in between 'Previous' and 'Next'. 2 3 4 5-在“上一个”和“下一个”之间的分页号。 I am looking for a PHP call to do this. 我正在寻找一个PHP调用来做到这一点。 Is there? 在那儿?
  3. I want to retrieve the current page number of the post and the total number of post. 我想检索帖子的当前页码和帖子总数。 I went through the code of the plugin wp_pagenavi but I am having a hard time with it. 我浏览了插件wp_pagenavi的代码,但是我很难过。

Please see image of what I wanted to achieve, hope someone can give me a link of a tutorial that does that. 请查看我想要实现的图像,希望有人可以给我提供该链接的教程。 I am open to plugins. 我对插件持开放态度。

在此处输入图片说明

Thanks in advance for the help, hope I did not confuse any of you of these several problems. 在此先感谢您的帮助,希望我不要让您对这几个问题感到困惑。

I found the solution for item #1. 我找到了第一项的解决方案。 I stumbled upon this code: 我偶然发现了以下代码:

<?php
   $args = array(
     'cat' => 39,
     'posts_per_page' => 1,
     'order' => 'ASC'
);
$my_query = new WP_Query($args);
while ($my_query->have_posts()) {
  $my_query->the_post(); ?>
  <a href='<?php the_permalink(); ?> ' >First Page</a> |
<?php }
wp_reset_query(); ?>
<?php previous_post_link('%link', '<< Previous', TRUE); ?> |
<?php next_post_link('%link', 'Next >>', TRUE); ?>
<?php $args['order'] = 'DESC';
$my_query = new WP_Query($args);
while ($my_query->have_posts()) {
  $my_query->the_post(); ?>
   | <a href='<?php the_permalink(); ?> ' >Last Page</a>
  <?php } ?>

This is the link of the site: http://wordpress.org/support/topic/link-to-most-recent-post-in-one-category 这是网站的链接: http : //wordpress.org/support/topic/link-to-most-recent-post-in-one-category

Pagination Like : Prev 1 2 3 Next 分页像:上一页1 2 3下一页

<?php 
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$news= new WP_Query(array(
    'post_type'=>'post',
    'posts_per_page' => 3,
    'paged' => $paged,
));

if($news->have_posts()) :
    while($news->have_posts())  : $news->the_post();
            the_title();
    endwhile;

    $total_pages = $news->max_num_pages;

    if ($total_pages > 1){

        $current_page = max(1, get_query_var('paged'));

        echo paginate_links(array(
            'base' => get_pagenum_link(1) . '%_%',
            'format' => '/page/%#%',
            'current' => $current_page,
            'total' => $total_pages,
            'prev_text'    => __('« prev'),
            'next_text'    => __('next »'),
        ));
    }
    ?>    
<?php else :?>
<h3><?php _e('404 Error&#58; Not Found', ''); ?></h3>
<?php endif; ?>
<?php wp_reset_postdata();?>

Would you please check above code? 您能检查一下上面的代码吗?

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

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