반응형
query_페이지가 작동하지 않는 posts
다음 코드로 호출을 실행하려고 하지만 성공하지 못합니다.
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'cat' => '5',
'post_type' => 'post',
'posts_per_page' => 6,
'paged' => $page,
);
query_posts($args);
while(have_posts()) {
the_post(); ?>
<div class="project_item">
<div class="dotted">
<hr />
</div>
<div class="project_thumb"><a href="<?php echo get_permalink(); ?>"><img src="<?php getCustomField('news_thumbnail'); ?>" /></a></div>
<div class="project_entry"><h4><a href="<?php echo get_permalink(); ?>"><?php getCustomField('news_title'); ?></a></h4>
<?php getCustomField('news_excerpt'); ?>
<a href="<?php echo get_permalink(); ?>" class="readmore">Read more..</a>
</div>
</div>
<?php }
wp_reset_query(); // Restore global post data
루프 후에 이전 및 다음 링크를 추가해야 했습니다.
<div class="navigation">
<div class="alignleft"><?php previous_posts_link('« Previous') ?></div>
<div class="alignright"><?php next_posts_link('More »') ?></div>
</div>
전체 코드:
<?php
$args = array(
'cat' => '5',
'post_type' => 'post',
'posts_per_page' => 6,
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
);
query_posts($args);
while (have_posts()) : the_post();
/* Do whatever you want to do for every page... */
?>
<div class="project_item">
<div class="dotted">
<hr />
</div>
<div class="project_thumb"><a href="<?php echo get_permalink(); ?>"><img src="<?php getCustomField('news_thumbnail'); ?>" /></a></div>
<div class="project_entry"><h4><a href="<?php echo get_permalink(); ?>"><?php getCustomField('news_title'); ?></a></h4>
<?php getCustomField('news_excerpt'); ?>
<a href="<?php echo get_permalink(); ?>" class="readmore">Read more..</a> </div>
</div>
<?php
endwhile;
?><div class="navigation">
<div class="alignleft"><?php previous_posts_link('« Previous') ?></div>
<div class="alignright"><?php next_posts_link('More »') ?></div>
</div>
<?php
wp_reset_query(); // Restore global post data
?>
다음은 모든 페이지 플러그인과 함께 작동하도록 수정하는 방법입니다.
global $wp_query;
query_posts(
array_merge(
array(
'category__not_in' => 69, //ifu want to exclude some category
'posts_per_page' => 9
),
$wp_query->query
)
);
언급URL : https://stackoverflow.com/questions/4648956/query-posts-with-pagination-not-working
반응형
'programing' 카테고리의 다른 글
jQuery는 모든 텍스트 필드의 값의 합을 계산합니다. (0) | 2023.10.09 |
---|---|
control.registerOnChange is not function" 오류의 원인 (0) | 2023.10.09 |
Shared Object Module(lib*.so) 내용을 볼 수 있는 명령줄 (0) | 2023.10.09 |
WordPress user with custom role cannot view list page for custom post types without the "create_posts" capabililty (0) | 2023.10.09 |
Laravel Valet Linux: MariaDB/Mysql을 연결할 수 없습니다. (0) | 2023.10.09 |