嗨有一个问题,我无法在静态首页上工作,查看wordpress codex并完成它所说的内置但仍然没有快乐,
任何帮助非常感谢
<?php
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$type = 'Galleries';
$args=array(
'category_name' => 'Gallery',
'post_status' => 'publish',
'posts_per_page' => 2,
'paged' => $paged
);
$my_query = null;
$my_query = new WP_Query($args);
?>
<section id="maincontent" class="twelve columns">
<ul id="gallery_menu">
<?php if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li class="gallery_titleframe">
<div class="gallery_titleborder">
<div class="gallery_titleimage">
<?php $str = get_the_ID() ; ?>
<a href="<?php the_permalink() ?>" title="<?php echo get_post_meta($str, 'gallery1', true); ?>">
<img src="<?php echo get_post_meta($str, 'gallery1', true); ?>" width="256" height="186">
</a>
</div>
</div>
<div class="gallery_titletext">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
</div>
</li>
<?php endwhile;
} ?>
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php next_posts_link(); ?></div>
<div class="nav-next"><?php previous_posts_link(); ?></div>
</div><!-- #nav-below -->
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
答案 0 :(得分:2)
next_posts_link
和previous_posts_link
取决于全球$wp_query
。在调用之前,您可以暂时将自定义查询分配给全局。
<?php
$temp = $wp_query;
$wp_query = null;
$wp_query = $my_query;
?>
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php next_posts_link(); ?></div>
<div class="nav-next"><?php previous_posts_link(); ?></div>
</div><!-- #nav-below -->
<?php
$wp_query = null;
$wp_query = $temp;
wp_reset_query();
?>
答案 1 :(得分:1)
替换此
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
用这个
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}