나는이 문제에 대한 해결책을 1 주 이상 찾고 있었고 같은 문제로 다른 사람을 찾을 수 없었습니다.WordPress 페이지 매기기가 페이지를 전환하지 않습니다
나는 다른 사람이 만든 사용자 지정 WP 테마로 작업 중입니다. 보조 루프 중 하나에 대해 페이징을 구현해야하는 단일 페이지 템플릿이 있습니다. 나는 내장 된 paginate_links()
기능과 다른 방법을 사용하려고 시도했다. 페이지 매김 링크가 나타나지만, 페이지 매김 링크를 클릭하면 페이지 매김의 해당 페이지로 이동하지 않습니다. 대신 원본 페이지가 다시로드됩니다 (예 : thewebsite.com/my-page/page/2/로 이동하지 않고 thewebsite.com/my-page/을 다시로드합니다).
이전 dev에 올바른 템플릿로드 functions.php에서이 필터를 사용 :
add_filter('single_template', create_function('$t', 'foreach((array) get_the_category() as $cat) { if (file_exists(TEMPLATEPATH . "/single-{$cat->slug}.php")) return TEMPLATEPATH . "/single-{$cat->slug}.php"; } return $t;'));
을 그리고 여기 내 템플릿 파일 : 워드 프레스의 전체 은하가 나는 실현
<?php
/**
* Template Name: Project Template
*/
get_header('news'); ?>
<article role="main" class="projectpage">
<div class="container">
<section class="pagecontent">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<section class="overview">
<h1><?php the_title(); ?></h1>
<div>
<?php the_content(); ?>
</div>
<div>
<?php if(get_post_meta($post->ID, 'pagelink', true)): ?>
<a href ="<?php echo get_post_meta($post->ID, 'pagelink', true); ?>" class="ctabutton2"> Read the Overview </a>
<?php endif; ?>
</div>
</div><!--end row-->
</section><!--end overview-->
<?php endwhile ?>
<?php wp_reset_postdata() ?>
<? endif ?>
<section class="related">
<div>
<h1> Related Resources </h1>
<h2> Explore our library of articles and resources </h2>
</div>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 relatedlinks">
<section class="projectcategories">
<h3> Categories </h3>
<ul>
<?php wp_list_categories(array(
'orderby' => 'id',
'show_count' => true,
'use_desc_for_title' => false,
'child_of' => 93,
'title_li' => ' '
)); ?>
</ul>
</section>
<section class="project-search" role="search">
<form method="get" action="<?php echo esc_url(home_url('/')); ?>">
<input type="hidden" name="cat" id="cat" value="93" />
<input type="text" size="16" name="s" placeholder="search keywords" class="search-box" />
<input type="submit" value="Go" class="go"/>
</form>
</section>
<section class="otherprojects">
<h3> Other Projects </h3>
<?php
$args = array(
'category__in' => 91,
'post__not_in' => array($post->ID)
);
// the query
$query = new WP_Query($args);
$temp_query = $wp_query;
$wp_query = NULL;
$wp_query = $query;
// The Loop
if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
<a href="<?php the_permalink();?>"><?php the_title(); ?></a>
<? endwhile ;
/* Restore original Post Data */
wp_reset_postdata();
endif;
$wp_query = NULL;
$wp_query = $temp_query;
?>
</section>
</div><!--end col 1-->
<div class="col-lg-9 col-md-9 col-sm-9 col-xs-9">
<section class="articles">
<?php
// THIS IS THE SECTION WHERE I NEED THE PAGINATION
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = [
'posts_per_page' => 3,
'paged' => $paged,
'post_type' => 'post',
'order' => 'DESC',
'post__not_in' => array($post->ID),
'tax_query' => [
[
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => '93',
],
],
];
$custom_query = new WP_Query($args);
$temp_query = $wp_query;
$wp_query = NULL;
$wp_query = $custom_query;
if ($custom_query->have_posts()) {
while ($custom_query->have_posts()) {
$custom_query->the_post(); ?>
<div class="row">
<div class="col-md-2 col-sm-2 col-xs-2 divider">
<p class="date"><?php the_time('M j') ?></p>
</div><!--end col-->
<div class="col-md-4 col-sm-4 col-xs-4">
<div class="articleimg">
<?php if (has_post_thumbnail()) {?>
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('blog-thumb'); ?></a>
<?php } ?>
</div><!--end blogimg-->
</div><!--end col-->
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="blogcontent">
<h3><?php the_title();?></h3>
<p><?php the_excerpt(); ?></p>
<a href="<?php the_permalink(); ?>" class="readmore"> // read more </a>
</div><!--end blogcontent-->
</div><!--end col-->
</div><!--end row-->
<?php }
}
echo paginate_links(array(
'total' => $wp_query->max_num_pages
));
$wp_query = NULL;
$wp_query = $temp_query;
wp_reset_postdata(); ?>
</section><!--end articles-->
</div><!--end col 2-->
</div> <!--end row-->
</section><!--end related-->
<!-- ANNOUNCEMENTS -->
<!--ANNOUNCEMENT SECTION -->
<!-- dynamic content --filters posts by category and only shows 'member' posts with a limit of six posts being
displayed-->
<section id="announcement-front" class="clearfix">
<div class="container">
<div>
<?php $query = new WP_Query('posts_per_page=1&category_name=advertisement');
if ($query->have_posts()) :
while ($query->have_posts()) : $query->the_post(); ?>
<a href="<?php the_permalink()?>" <?php the_content();?> </a>
<?php endwhile ?>
<? endif ?>
<?php wp_reset_postdata() ?>
</div><!--end row-->
</div><!--container-->
</section><!--end announcement-->
</section> <!--end page content -->
</div><!--end container-->
</article>
<?php get_footer(); ?>
페이지 매김 자습서와 스레드가 있지만이 특정 문제를 해결하는 아직 찾지 못했습니다.
감사 :
여기에 코드입니다. 이것은 실제로 내가 원래 작업했던 코드이고,'$ wp_query'를 저장하고 전환하는 방법에 대한 튜토리얼을 읽고 그것을 시도했습니다. 생성 된 페이지 매김 링크가 잘 될 것으로 보인다 : '<스팬 클래스 = "페이지 번호 현재">3 Next »' 2 1하지만 그것은 단지 원래의 페이지를로드를 클릭합니다. – Devon
아하나. 문제가되는 것은 페이징 링크가 아니며 페이지를 클릭 할 때 페이지가 리디렉션되는 방식입니다. 먼저 영구 링크를 비우십시오 (설정 -> 영구 링크로 이동하여 저장을 클릭하십시오). 작동하지 않으면 아이디어 링크를 클릭하십시오. https://wordpress.org/support/topic/pagination-on-singlephp-causing-301-redirect/?replies=10 –