我在自定义帖子类型模板中遇到了一个关于分页的自定义查询的大问题。
由于某种原因,上一篇文章、下一篇文章的链接显示为空白。如果我这样做“www.domainname.com/wolf/spot/paged/2/,它会显示404页。
代码如下。。。如上所述,这是一个自定义查询,位于自定义帖子类型模板中。
<div id="content">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h1 class="pageName"><?php the_title(); ?></h1>
<div class="entry">
<?php the_content(\'<p class="serif">Read the rest of this entry »</p>\'); ?>
<!-- BEG Wolf Logs -->
<h3>Recent Logs for <?php the_title(); ?>:</h3>
<?php
wp_reset_postdata();
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
if (isset($_GET[\'show\'])) {
$ppp = $_GET[\'show\'];
} else {
$ppp = 10;
}
if (isset($_GET[\'archyear\'])) {
$archYear = $_GET[\'archyear\'];
} else {
$archYear = date("Y");
}
$wolf = strtolower(get_the_title());
$logArgs = array(
\'post_type\' => \'wolf-log\',
\'post_status\' => \'publish\',
\'orderby\' => \'meta_value_num\',
\'meta_key\' => \'observationDate\',
\'posts_per_page\'=> $ppp,
\'meta_query\' => array(
\'relation\' => \'AND\',
array(
\'key\' => \'wolf\',
\'value\' => $wolf,
\'compare\' => \'=\'
),
array(
\'key\' => \'observationDate\',
\'type\' => \'numeric\',
\'value\' => array($archYear.\'0101\',$archYear.\'1231\'),
\'compare\' => \'BETWEEN\'
)
),
\'order\' => \'DESC\',
\'paged\' => $paged
);
$wlQuery = new WP_Query($logArgs);
if ($wlQuery->have_posts()) {
while ($wlQuery->have_posts()) {
$wlQuery->the_post();
get_template_part(\'loop\', \'wolflogs\');
} // endwhile
?>
<div id="postFooter">
<div class="navigation">
<p><?php next_posts_link(\'< Older Posts\', $wlQuery->max_num_pages); ?></p>
<p><?php previous_posts_link(\'Newer Posts >\', $wlQuery->max_num_pages); ?></p>
</div>
<?php
} else {
echo \'<h2>No current logs, check back later.</h2>\';
}
// Restore original Post Data
wp_reset_postdata();
?>
<div class="pageControls">
<?php
$archArray = array();
$archArgs = array(
\'post_type\' => \'wolf-log\',
\'post_status\' => \'publish\',
\'meta_key\' => \'wolf\',
\'meta_value\' => $wolf,
\'order\' => \'DESC\',
\'posts_per_page\' => -1
);
$archQuery = new WP_Query($archArgs);
if ($archQuery->have_posts()) {
while($archQuery->have_posts()) {
$archQuery->the_post();
$obDate = get_post_meta($post->ID, \'observationDate\', true);
$obDate = strtotime($obDate);
$obDate = date("Y", $obDate);
$archArray[$obDate] = $obDate;
}
} else {
echo \'No Archives\';
}
wp_reset_postdata();
?>
<div class="styled-select">
<select name="archivesPager" id="archivesPager">
<option value="">Archive</option>
<?php
arsort($archArray);
foreach($archArray as $archYear) {
echo \'<option value="?archyear=\'.$archYear.\'">\'.$archYear.\'</option>\';
}
?>
</select>
</div>
</div>
<div class="clearFix"></div>
</div><!-- END postFooter -->
<?php
// Restore original Post Data
wp_reset_postdata();
?>
<!-- END Wolf Logs -->
</div>
</div>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
</div>