我正在WordPress上开发一个照片页面,我希望每页显示一定数量的图像,然后在底部显示导航。我可以正确显示图像而没有任何问题,但导航根本不会显示。这是我在模板页面中的内容:
$args = array(
'showposts' => 12,
'post_type' => 'attachment',
'paged' => $paged
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo '<li>';
echo '<a class="th" title="';
echo apply_filters( 'the_title', $attachment->post_title );
echo '" href="';
echo apply_filters( 'the_permalink', '?attachment_id='.$attachment->ID );
echo '">';
echo wp_get_attachment_image( $attachment->ID, 'thumbnail' );
echo '</a>';
echo '</li>';
}
}
?>
</ul>
<nav>
<?php previous_posts_link('« Newer') ?>
<?php next_posts_link('Older »') ?>
</nav>
答案 0 :(得分:0)
添加$ paged变量:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 24,
'post_type' => 'attachment',
'paged' => $paged
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo '<li>';
echo '<a class="th" title="';
echo apply_filters( 'the_title', $attachment->post_title );
echo '" href="';
echo apply_filters( 'the_permalink', '?attachment_id='.$attachment->ID );
echo '">';
echo wp_get_attachment_image( $attachment->ID, 'thumbnail' );
echo '</a>';
echo '</li>';
}
}
?>
</ul>
<nav>
<?php previous_posts_link('« Newer') ?>
<?php next_posts_link('Older »') ?>
</nav>