嘿,我将此代码添加到WordPress页面中,此插件获取特定类别的所有帖子,其工作正常,我想在此代码上添加分页,但我不知道该怎么做。
<?php
$catquery = new WP_Query( 'cat=124&posts_per_page=10' );
while($catquery->have_posts()) : $catquery->the_post()?><div class="main-box">
<div class="photos">
<ul class="photo-data">
<li><?php the_post_thumbnail(); ?></li>
</ul>
</div>
<div class="title_desc">
<ul>
<li style="list-style-type: none;">
<h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
<?php $content = get_the_content();
echo substr($content, 0, 50); ?>
<a href="<?php the_permalink() ?>" rel="bookmark">...Read More</a>
</li>
</ul>
</div></div><?php endwhile; ?>`
答案 0 :(得分:-1)
尝试此代码,
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$catquery = new WP_Query( 'cat=7&posts_per_page=5&paged='.$paged);
global $wp_query;
$tmp_query = $wp_query;
$wp_query = null;
$wp_query = $catquery;
while($catquery->have_posts()) : $catquery->the_post()?>
<div class="main-box">
<div class="photos">
<ul class="photo-data">
<li>
<?php the_post_thumbnail(); ?>
</li>
</ul>
</div>
<div class="title_desc">
<ul>
<li style="list-style-type: none;">
<h3><a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?>
</a></h3>
<?php $content = get_the_content();
echo substr($content, 0, 50); ?>
<a href="<?php the_permalink() ?>" rel="bookmark">...Read More</a>
</li>
</ul>
</div>
</div>
<?php endwhile; ?>
<div class="pagination">
<?php previous_posts_link('« Newer') ?>
<?php next_posts_link('Older »') ?>
</div>