WordPress博客分页不工作

时间:2015-09-22 14:35:03

标签: php wordpress pagination blogs

我仍然坚持这个问题..

我的WordPress博客上的分页无效 - http://www.example.com/news

当您点击其他页码时,它会正确更新网址(和页面标题),但不会显示不同的帖子。

我试过了:

  • 禁用所有插件
  • 更改永久链接结构
  • 更改设置>阅读
  • 中显示的博文数量
  • http://www.example.com/recall-news更改为其他路径以避免与名为“news”的帖子类别冲突

没有什么对我有用。

我见过很多自定义查询的解决方案,但我使用的是您在设置>阅读>帖子页面中设置的帖子页面,因此我没有编写任何代码来显示此页面上的帖子。

  • 在这种情况下,我修改了什么WordPress文件来修复博客分页?我猜我可以在functions.php中添加一些内容,但我还没有找到解决方案。

更新:我还没有找到解决方案。我知道我可以通过编写自己的查询来实现,但我想坚持使用默认的WP博客。

8 个答案:

答案 0 :(得分:1)

检查category.php文件(又名archive.php)中的WP循环。它必须包含以下内容:

if (have_posts()) : while (have_posts()) : the_post();

并完成:

endwhile; endif;

答案 1 :(得分:1)

无法保证您的问题与WordPress有关。但是,因为你没有给出一个非常笼统的问题,我将给你一个非常一般的答案。这应该可以帮助你找出问题并自己解决。

  1. 查看underscores。下载并查看模板(例如index.phparchive.php等),看看您是否遗漏了下划线包含的内容。下划线的好处在于,它是创建正在运行的主题所需的所有基本内容,没有多余的装饰。因此,如果它存在于您的代码中,那么可能值得探索。特别注意与have_posts

  2. 相关的任何代码块
  3. 您的主题可能实际上没有任何问题。尝试测试另一个主题(例如,您可以方便地下载的下划线),看看它是否具有分页功能和完整。如果确实如此,那么,你很幸运...这意味着你只需要深入挖掘一下,以便用你的下划线来解决你的代码错误。

  4. 如果您发现自己的主题没有问题,但实际上您的服务器配置有问题,那么这也是一种解脱,请讲。这意味着您理论上应该能够在其他地方测试您的安装,或重新安装您的服务器,并使其工作。在走这么远之前,尝试简单地重新安装您的WordPress版本。谁知道......它可以发挥作用。

答案 2 :(得分:1)

您应该在query_post函数中传递“page”/“paged”var:

if ( get_query_var('paged') ) {
 $paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
 $paged = get_query_var('page');
} else {
 $paged = 1;
}
query_posts(array('paged' => $paged));
if (have_posts()) : while ( have_posts() ) : the_post(); ?>
<!--Your HTML-->.
<?php endwhile; endif;  wp_reset_query(); ?>

答案 3 :(得分:0)

我也玩过“帖子页面”,但我没有结果。

对我来说,唯一可行的解​​决方案是与Page-Navi插件结合使用的客户查询。

在我的模板中,我有以下代码:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
        'post_type'         => 'post',
        'orderby'           => 'date',
        'order'             => 'DESC',
        'post_status'       => 'publish',
        'posts_per_page'    => 5,
        'paged'             => $paged,
    );
    $q = new WP_Query( $args );

    if ( $q->have_posts() ) {
        $displaylist = '<div class="list-group">';

        while ( $q->have_posts() ) {
            $q->the_post();

            // build up your entry

            unset( $displayTag );
        }

        $displaylist .= '</div>';

        echo( $displaylist );

        wp_pagenavi( array( 'query' => $q ) );

        wp_reset_postdata();
    }
?>

使用post_per_page i管理每个站点的条目。在while循环中,我构建了应该显示的条目。

答案 4 :(得分:0)

您可以尝试使用Wp-Pagenavi来生成分页吗?这样我们至少可以检查问题是默认分页还是编码中的某些错误,而不是正确填充分页变量

答案 5 :(得分:0)

试试这个

    global $wpdb;

    $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
    $limit = 20;
    $offset = ( $pagenum - 1 ) * $limit;
    //$entries = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}design_information LIMIT $offset, $limit" );
     $entries = $wpdb->get_results("Select * From design_information ORDER BY id DESC LIMIT $offset, $limit",ARRAY_A);

echo '<div class="wrap">';
<table class="widefat">
    <thead>
        <tr>
           <th>SNo.</th><th>Layout</th><th>Org Description</th>
        </tr>
    </thead>

    <tbody>
        <?php if( $entries ) { ?>

            <?php
            $count = 1;
            $class = '';
    //echo "<pre>";
    //print_r($entries);
    for($i=0;$i<count($entries); $i++)
    {

$pid=$entries[$i]['id'];
                $class = ( $count % 2 == 0 ) ? ' class="alternate"' : '';
          ?>
            <tr<?php echo $class; ?>>
                <td>
              <?php echo $entries[$i]['id'];
                //echo $count; 
                $count++;?>
          </td>
<td>
      <?php echo $entries[$i]['layout'];?>
  </td>
  <td> 
      <?php echo $entries[$i]['org_description'];?>
  </td>

  </tr>
</table>

答案 6 :(得分:0)

在主题中创建文件archive-learning.php。

这意味着post_type是“学习”

<?php
if ( get_query_var( 'paged' ) ) {
        $paged = get_query_var( 'paged' );
    } elseif ( get_query_var( 'page' ) ) {
        $paged = get_query_var( 'page' );
    } else {
        $paged = 1;
    } 


<?php
$custom_args = array(
        'post_type'     => 'learning',
        'post_status'   => 'public',
        'orderby'       =>  'date',
        'order'         =>'DESC',    
         'posts_per_page'=>12,//limit 6
         'paged' => $paged
    );
$wp_query = new WP_Query( $custom_args );
$getPosts =  get_posts($custom_args);

?>
<?php if ($getPosts) : ?>
				<?php global $post,$wp_query;?>
				<?php foreach ($getPosts as $post): ?>
				<?php setup_postdata($post);?>
				<?php echo "your content here";?>
				<?php endforeach;?>
					
				<?php
				else :
					
					

				endif;
			?>
<div class="pagenation"><?php if (function_exists(custom_pagination)) {custom_pagination($wp_query->max_num_pages,"",$paged);} ?></div></div>
    <?php wp_reset_postdata(); ?>
转到文件functions.php并创建函数custom_pagination

function custom_pagination($numpages = '', $pagerange = '', $paged='') {

  if (empty($pagerange)) {
    $pagerange = 2;
  }

  /*
   * This first part of our function is a fallback
   * for custom pagination inside a regular loop that
   * uses the global $paged and global $wp_query variables.
   * 
   * It's good because we can now override default pagination
   * in our theme, and use this function in default queries
   * and custom queries.
   */
  global $paged;
  if (empty($paged)) {
    $paged = 1;
  }
  if ($numpages == '') {
    global $wp_query;
    $numpages = $wp_query->max_num_pages;
    if(!$numpages) {
        $numpages = 1;
    }
  }

  /** 
   * We construct the pagination arguments to enter into our paginate_links
   * function. 
   */
  
  $pagination_args = array(
  'base'           =>add_query_arg('page','%#%'),
  'format'          => 'page/%#%',
  'total'           => $numpages,
  'current'         => $paged,
  'show_all'        => False,
  'end_size'        => 1,
  'mid_size'        => $pagerange,
  'prev_next'       => True,
  'prev_text'       => __('&laquo;'),
  'next_text'       => __('&raquo;'),
  'type'            => 'plain',
  'add_args'        => false,
  'add_fragment'    => ''
);

  $paginate_links = paginate_links($pagination_args);

  if ($paginate_links) {
    echo "<nav class='custom-pagination'>";
      //echo "<span class='page-numbers page-num'>Page " . $paged . " of " . $numpages . "</span> ";
      echo $paginate_links;
    echo "</nav>";
  }

}

答案 7 :(得分:0)

当您使用自定义永久链接结构 /%category%/%postname%/ 这确实是我的情况时,通常会发生这种情况。

This videoits text version 为我修复了它就像一个魅力。

简而言之,安装这个插件解决了我的问题:

https://wordpress.org/plugins/post-category-prev-next-link-fix/#description

相关问题