WordPress分页不工作-页面url更改但内容不更改

piok6c0g  于 11个月前  发布在  WordPress
关注(0)|答案(1)|浏览(268)

主页显示所有的职位,我想为此分页。在分页链接页面编号的URL,但相同的内容显示在所有页面上点击后的变化,也分页链接的数字显示只有1选择。就像如果我选择分页链接3,URL显示页/3,但页码是1,内容甚至不改变。
x1c 0d1x的数据


<?php
/**
 * Genesis Sample.
 *
 * This file adds the landing page template to the Genesis Sample Theme.
 *
 * Template Name: Home
 *
 * @package Genesis Sample
 * @author  StudioPress
 * @license GPL-2.0-or-later
 * @link    https://www.studiopress.com/
 */
get_header();

$paged = (isset($_GET['paged'])) ? intval($_GET['paged']) : 1;
$paged = (get_query_var('paged')) ? get_query_var('paged') : $paged;

$args = array(
  'post_type' => 'post',
  'post_status' => 'publish',
  'posts_per_page' => 9,
  'paged' => $paged,
);
$wp_query = new WP_Query($args);
?>

<div class="body-container">
  <div class="blogs-banner">
    <?php
    $image = get_field('image');
    if (!empty($image)) : ?>
      <img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" class="img-main" />
    <?php endif; ?>
  </div>
  <div class="about-container">
    <div class="blog-list">
      <div class="row-same-height" id="postContainer" data-type="post" data-count="<?php echo $wp_query->found_posts; ?>">
        <?php
        if ( $wp_query->have_posts() ) :
          while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
            <a href="" class="link-post">
              <div class="col-same-height">
                <div class="content">
                  <div class="TopArticleCard-Container">
                    <div class="img-container">
                      <?php
                      $thumbnail = get_post_meta(get_the_id(), 'large_img', true);
                      if ( $thumbnail ) { ?>
                        <img src="<?php echo $thumbnail; ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" loading="lazy"/>
                      <?php } else if ( has_post_thumbnail() ) {
                        the_post_thumbnail('large', ['title' => get_the_title()], ['alt' => get_the_title()]); ?>
                      <?php
                      } else { ?>
                        <img src="<?php echo get_site_url(); ?>/wp-content/uploads/2020/09/default.jpg" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" loading="lazy"/>
                      <?php } ?>
                    </div>
                    <div class="article-description">
                      <div class="article-tag">
                        <?php $cat = get_the_category(); echo $cat[0]->cat_name; ?>
                      </div>
                      <div class="content">
                        <div class="article-title">
                          <?php the_title(); ?>
                        </div>
                     </div>
                </div>
              </div>
            </div>
          </div>
        </a>
        <?php endwhile;
    // post_pagination($query);
  endif;
  wp_reset_postdata();
  ?>
</div>
<nav class="pagination-nav">
  <ul class="pagination">
    <?php
    if ( $wp_query->have_posts() ) :
      $currentPage = (get_query_var('paged')) ? get_query_var('paged') : 1;
      $pagination_args = array(
        'base' => str_replace(999999999, '%#%', esc_url(get_pagenum_link(999999999))),
        'format' => '/page/%#%',
        'current' => $currentPage,
        'total' => $wp_query->max_num_pages,
        'prev_text' => 'Prev',
        'next_text' => 'Next',
      );

      echo paginate_links(array_merge($pagination_args, array('query' => $wp_query)));
    endif;
    ?>
  </ul>
</nav>



      </div>
    </div>


  </div>
</div>

<?php get_footer();

字符串

yrefmtwq

yrefmtwq1#

我通过在初始查询数组中添加一行来实现我的工作:

'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),

字符串
它看起来是这样的:

global $wp_query;

query_posts(array(
    'post_type'             => 'gallery',
    'post_status'           => 'publish',
    'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
    'order'                     => 'DESC',
));


我认为我的问题出在分页上,但是,问题出在对查询的初始调用上

相关问题