WordPress의 개발을 배우기 위해, 저는 처음부터 WordPress 테마를 만들고 있습니다. 이제 내 카테고리 페이지에 페이지 매김을 추가하고 싶지만 문제는 다음과 같습니다. 이전 게시물 링크를 클릭하면 "http://localhost/wordpress4/category/bloc1/"에서 "http://localhost/wordpress4/category/bloc1/page/2/"로 변경됩니다. 그러나 다른 페이지를 표시하는 대신 빈 페이지로 이동합니다 게시물. 2 페이지의 WordPress 매김 페이지 빈 페이지 (처음부터 테마 만들기)
이
내가 눈치 category.php<?php get_header(); ?>
<div class="container">
<?php
$counter = 1; //start counter
$grids = 3; //Grids per row
global $query_string; //Need this to make pagination work
/*Setting up our custom query (In here we are setting it to show 12 posts per page and eliminate all sticky posts) */
query_posts($query_string . '&caller_get_posts=1&posts_per_page=4');
if(have_posts()) : while(have_posts()) : the_post();
?>
<?php
//Show the left hand side column
if($counter == 1) :
?>
<div class="row">
<div class="col-md-4">
<div class="center">
<div class="postimage">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_custom_logo(); ?></a>
</div>
<h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<h4><?php the_category(); ?></h4>
</div>
</div>
<?php
elseif($counter == 2) :
?>
<div class="col-md-4 border2">
<div class="center">
<div class="postimage">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_custom_logo(); ?></a>
</div>
<h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<h4><?php the_category(); ?></h4>
</div>
</div>
<?php
elseif($counter == $grids) :
?>
<div class="col-md-4">
<div class="center">
<div class="postimage">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_custom_logo(); ?></a>
</div>
<h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<h4><?php the_category(); ?></h4>
</div>
</div>
</div>
<div class="clear"></div>
<?php
$counter = 0;
endif;
$counter++;
endwhile;
?>
<div class="row">
<div class="col-xs-6 text-left">
<?php next_posts_link('<< Older post'); ?>
</div>
<div class="col-xs-6 text-right">
<?php previous_posts_link('Newer post >>'); ?>
</div>
<?php
endif;
?>
</div>
</div>
<?php get_footer(); ?>
의 코드입니다 내가 카테고리 페이지도 내 index.php를 아래의 페이지 매김 작업을 코드를 추가합니다. 두 번째 카테고리 페이지 ("http://localhost/wordpress4/category/bloc1/page/2/")는 index.php의 마크 업을 사용하므로 게시물은 첫 번째 카테고리 페이지와 같은 그리드 형식이 아니게됩니다.
카테고리 페이지에도 이전 링크가 페이지 하단에 표시되는 대신 행 사이에 표시됩니다.
마침내이
<?php get_header(); ?>
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-8">
<?php
if(have_posts()):
while(have_posts()): the_post(); ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<h3><?php the_title(); ?></h3>
<small><?php the_category(); ?></small>
</a>
<p><?php the_content(); ?></p>
<hr/>
<?php endwhile;
endif;
?>
</div>
<div class="col-xs-12 col-sm-4">
<?php get_sidebar(); ?>
</div>
</div>
</div>
<?php get_footer(); ?>
이 감사 제의 index.php에 코드입니다.
pre_get_posts 쿼리 변수 개체가 만들어진 후 실제 쿼리가 실행되기 전에 호출 된 후크입니다. 당신은 사용 참조 때문에 무언가를 돌려 줄 필요가 없습니다. pre_get_posts hook은 백엔드 do_action_ref_array ('pre_get_posts', WP_Query) 함수를 실행합니다. 자세한 내용을 알고 싶다면 https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts 및 https://developer.wordpress.org/reference/hooks/pre_get_posts/ –
감사합니다. @NahidHasan –