【问题标题】:Wordpress Pagination links on Page not Found找不到页面上的 Wordpress 分页链接
【发布时间】:2013-01-31 15:25:37
【问题描述】:

我的 wordpress 主题有点问题。所以我刚刚创建了一个类别主题,并为我的永久链接使用以下结构:/%year%/%monthnum%/%postname%/。

Pagination 一开始没有用,但现在我终于设法让它运行了。链接

             <div class="pagination">
            <div class="alignleft"><?php previous_posts_link('&laquo; neuere Artikel') ?></div>
            <div class="alignright"><?php next_posts_link('ältere Artikel &raquo;','') ?></div>
         </div>

正在展示。

主要问题是当我点击“next_posts”-Link 或 previous_posts-Link 时,我会得到 404。

这是我的代码:

    <?
        $temp = $wp_query; 
$wp_query = null; 
$wp_query = new WP_Query();  
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $wp_query->query(array(
    'posts_per_page' => 5,
    'orderby'=> 'menu_order',
    'paged'=>$paged
    ) );
?>

<?php if (have_posts()) : ?>
        <?php  while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
            <div class="type-post">
                <h2><a href="<?php echo get_permalink(); ?>"><?php echo get_the_title(); ?></a></h2>
                <div class="blog-date">
                    <a  class="admin" href="<?php echo get_author_posts_url(get_the_author_meta( 'ID' )); ?>"><?php the_author_meta('display_name'); ?></a> 
                    <a href="#" class="date"><?php the_time('j. F, Y'); ?></a> 
                    <a href="<?php comments_link(); ?>" class="comments"><?php comments_number('0 Kommentare','1 Kommentar','% Kommentare'); ?></a>
                </div><!-- close .blog-date -->

                <p><? echo wp_trim_words( get_the_content(), 100 ); ?> </p>
                <p class="alignright"><a href="blog-single.php" class="button">Read more</a></p>
            <div class="clearfix"></div>
            </div>
                <?php endwhile; ?>
            <!-- END Single Content -->
         <div class="pagination">
            <div class="alignleft"><?php previous_posts_link('&laquo; neuere Artikel') ?></div>
            <div class="alignright"><?php next_posts_link('ältere Artikel &raquo;','') ?></div>
         </div>
        <?php endif; ?>
            <div class="clearfix"></div>

<!-- END CONTENT -->
<?php   $wp_query = null; 
$wp_query = $temp;  ?>

但它仍然不起作用。有人可以帮我吗?提前致谢。

【问题讨论】:

    标签: wordpress pagination wordpress-theming http-status-code-404 custom-post-type


    【解决方案1】:

    前往

    Settings -> Reading
    

    并将Blog pages show at mostSyndication feeds show the most recent 设置为与wp_query-&gt;query 中的posts_per_page 选项相同。

    【讨论】:

      【解决方案2】:

      在您的代码中 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

      get_query_var('paged') 替换为 get_query_var('page')

      【讨论】:

      • 我不工作。我改变了 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;到 $paged = (get_query_var('page')) ? get_query_var('page') : 1;,但错误依然存在。
      • 在我的网站 $page = (get_query_var('page')) ? get_query_var('page') : 1; $my_query = new WP_Query(array('cat' => $catId, 'paged' => $page));其中 $catId 是您的类别 ID。
      • 你在哪些文件中使用这个?我在archive.php 中尝试过,它仍然无法正常工作。我不明白为什么。此外,您的代码上方的链接消失了。
      【解决方案3】:
      <?php
      global $wp_query;
      $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
      $args = array(  
                  'post_type' => 'your post type', //Post type
                  'posts_per_page' => 5, //How many post u want to display per page
                  'paged' => $paged  ,
                  'orderby'=> 'menu_order',                    
                  );
      $the_query = new WP_Query( $args );
       if (have_posts()) : ?>
              <?php  while ($the_query->have_posts()) : $the_query->the_post(); ?>
                  <div class="type-post">
                      <h2><a href="<?php echo get_permalink(); ?>"><?php echo get_the_title(); ?></a></h2>
                      <div class="blog-date">
                          <a  class="admin" href="<?php echo get_author_posts_url(get_the_author_meta( 'ID' )); ?>"><?php the_author_meta('display_name'); ?></a> 
                          <a href="#" class="date"><?php the_time('j. F, Y'); ?></a> 
                          <a href="<?php comments_link(); ?>" class="comments"><?php comments_number('0 Kommentare','1 Kommentar','% Kommentare'); ?></a>
                      </div><!-- close .blog-date -->
      
                      <p><? echo wp_trim_words( get_the_content(), 100 ); ?> </p>
                      <p class="alignright"><a href="blog-single.php" class="button">Read more</a></p>
                  <div class="clearfix"></div>
                  </div>
                      <?php endwhile; ?>
                  <!-- END Single Content -->
              <?php endif; ?>
      <div class="pagination">
      <?php             
          global $wp_query;
      
          $big = 999999999; // need an unlikely integer
      
          echo paginate_links( array(
              'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
              'format' => '?paged=%#%',
              'current' => max( 1, get_query_var('paged') ),
              'total' => $wp_query->max_num_pages
          ) );
      ?>
      </div>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-09-06
        • 1970-01-01
        • 1970-01-01
        • 2016-12-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多