【问题标题】:Wordpress Pagination does not workWordpress 分页不起作用
【发布时间】:2018-09-07 04:33:20
【问题描述】:

我正在尝试创建一个 wordpress 主题,但我无法在实时版本上进行分页。在本地主机上它按预期工作,但在实时版本上它每次都会提供 404 页面。我知道关于这个主题有很多答案,但我无法解决我的问题。我已经尝试过以下主题,还有很多其他主题,但没有一个对我有帮助:

我想知道你们是否可以帮助我弄清楚我在这里缺少什么。我正在尝试在索引文件(我的博客页面)上显示我的导航面板。

get_header(); ?>

<div id="primary" class="container">
    <main id="main" class="col-xs-12">
        <h3 class="title text-center">Notícias:</h3>

        <?php 
            global $wp_query;
            query_posts(
                array_merge( array(
                    'post_type' => 'news',
                    'orderby' => 'date',
                    'order' => 'DESC',
                    'posts_per_page' => 3
                ),$wp_query->query)
            );

            while($wp_query->have_posts()) :
            $wp_query->the_post();

            get_template_part('template-parts/content', 'news');

            endwhile; 
        ?>
        <div class="text-center paginate">
            <?php 
                if(function_exists('wp_paginate')):
                    wp_paginate();  
                endif;
             ?>
        </div> <!-- .tect-center / Paginate-->
        <?php  wp_reset_postdata();  ?>
    </main><!-- #main -->
</div><!-- #primary -->
<?php
get_footer();

现在我正在使用Wp-paginate 插件,但使用paginate_links() 函数会给我同样的错误,但它们都在本地主机上工作。对于分页链接,我使用了文档中的示例:

https://codex.wordpress.org/Function_Reference/paginate_links.

请问有人能帮我吗?

【问题讨论】:

  • 尝试重置永久链接。
  • 请重置永久链接

标签: php wordpress wordpress-theming


【解决方案1】:

尝试使用下面的代码。

我已经使用 WP_Query 函数来获得想要的结果 - https://codex.wordpress.org/Class_Reference/WP_Query

<?php 

$args = array(
    'post_type' => 'post',
    'orderby' => 'date',
    'order' => 'DESC',
    'posts_per_page' => 3
    );

$the_query = new WP_Query($args);

while($the_query->have_posts()) :
    $the_query->the_post();

    get_template_part('template-parts/content', 'news');

endwhile; ?>
<div class="text-center paginate">
    <?php 
        if(function_exists('wp_paginate')):
            wp_paginate();  
        endif;
     ?>
 </div> <!-- .tect-center / Paginate-->
<?php  wp_reset_postdata();  ?>

【讨论】:

  • 还要确保您的页面 slug 和内容类型 slug 不同。
  • 我已经尝试了上面的代码,但现在它没有显示 wp_paginate 链接。我将使用 paginate_links() 尝试使用您的代码。
  • 您需要安装 wp paginate 插件并激活它。
  • 我的 Slug 与内容不同
  • 还要确保 Apache 重写模块已启用,并且 .htaccess 是最新的,并且有适当的行以使用自定义永久链接结构。
【解决方案2】:

由于它在您的本地主机上工作,因此刷新永久链接可能会解决您的问题。

第 1 步:在 wordpress 仪表板“设置 > 固定链接”中。

第 2 步:向下滚动并点击“保存更改”,无需更改任何内容。

完成后,重写规则和永久链接将被刷新。

【讨论】:

  • 感谢 Ali,但不幸的是,这并没有解决我的问题。
  • 好吧,你能说得更具体一点,是显示分页但点击时重定向到 404,还是什么都不显示。
  • 将我重定向到 404 页面
猜你喜欢
  • 2013-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-19
相关资源
最近更新 更多