我正在使用WordPress在表格中显示一些帖子,与此同时我也有一个分页。该表包含一个名为“ Number”的列和一个帖子标题列。我的问题是,当我进入下一页时,我不知道如何为每个帖子编号,因为帖子的数量从头开始,而不是从剩余的数量开始。我该如何解决?
当我转到下一页时,它并不是从应该开始的地方开始计数的。我的代码:
<?php
require('wp-load.php');
if ( is_user_logged_in() ) {
global $wp_query;
$paged = (isset($_GET['pagina'])) ? $_GET['pagina'] : 1;
$args = array(
'posts_per_page' => 2,
'paged' => $paged,
'post_type' => 'post'
);
$the_query = new WP_Query( $args );
echo '<table>';
$count = $paged - 1;
echo '<tr>
<td width="100">Number</td>
<td width="200">Title</td>
<tr>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
$count++;
//var_dump($count);
echo '<tr>';
echo '<td>'.$count .'</td>';
echo '<td>'.the_title().'</td>';
echo '</tr>';
}
echo '</table>';
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'format' => '?pagina=%#%',
'current' => max( 1, $paged ),
'total' => $the_query->max_num_pages,
'prev_next' => True,
'prev_text' => __('Previous'),
'next_text' => __('Next'),
) );
}
?>
$count = (($paged -1) * 2) + 1;
其中“ 2”是posts_per_page值。
编辑:这是整个代码:
$count = (($paged -1) * 2) + 1;
echo '<tr>
<td width="100">Number</td>
<td width="200">Title</td>
<tr>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<tr>';
echo '<td>'.$count .'</td>';
echo '<td>'.the_title().'</td>';
echo '</tr>';
$count++;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句