我在Wordpress中有一个名为'cases'的自定义帖子类型.对于单个页面,我创建了一个单case.php,所有这些都有效,但有一件事:
在While循环之外,我正在尝试使用'Next'和'Previous'链接,如下所示:
<?php next_post_link('%link', 'next item >') ?>
<?php previous_post_link('%link', '< previous item') ?>
Run Code Online (Sandbox Code Playgroud)
但他们陷入了困境.一旦它到达某篇文章,Wordpress就会被卡住并一遍又一遍地循环相同的两篇文章.
这是完整的(剥离的)模板:
... Header ...
<?php while (have_posts()) : the_post(); ?>
<div class="row content">
<div class="span4">
<?php if(count($aImages)) : ?>
<?php foreach($aImages as $aImage) : ?>
....
<?php endforeach; ?>
<?php endif; ?>
</div>
<div class="span7">
<div class="case-title"><?php the_title();?></div>
<?php the_content(); ?>
</div>
</div>
<?php endwhile; ?>
... Footer ...
<div class="next-posts pull-right"><?php next_post_link('%link', 'volgend item >') ?></div>
<div class="prev-posts pull-left"><?php previous_post_link('%link', '< vorig item') ?></div>
Run Code Online (Sandbox Code Playgroud)
UPDATE
出于某种原因,这解决了我的问题:
<div class="prev-posts pull-left">
<?php
$prev_post = get_previous_post();
if($prev_post) {
$prev_title = strip_tags(str_replace('"', '', $prev_post->post_title));
echo "\t" . '<a rel="prev" href="' . get_permalink($prev_post->ID) . '" title="' . $prev_title. '" class=" "><strong><<< "'. $prev_title . '"</strong></a>' . "\n";
}
?>
</div>
<div class="next-posts pull-right">
<?
$next_post = get_next_post();
if($next_post) {
$next_title = strip_tags(str_replace('"', '', $next_post->post_title));
echo "\t" . '<a rel="next" href="' . get_permalink($next_post->ID) . '" title="' . $next_title. '" class=" "><strong>"'. $next_title . '" >>></strong></a>' . "\n";
}
?>
</div>
Run Code Online (Sandbox Code Playgroud)
<div class="prev-posts pull-left">
<?php
$prev_post = get_previous_post();
if($prev_post) {
$prev_title = strip_tags(str_replace('"', '', $prev_post->post_title));
echo "\t" . '<a rel="prev" href="' . get_permalink($prev_post->ID) . '" title="' . $prev_title. '" class=" "><strong><<< "'. $prev_title . '"</strong></a>' . "\n";
}
?>
</div>
<div class="next-posts pull-right">
<?php
$next_post = get_next_post();
if($next_post) {
$next_title = strip_tags(str_replace('"', '', $next_post->post_title));
echo "\t" . '<a rel="next" href="' . get_permalink($next_post->ID) . '" title="' . $next_title. '" class=" "><strong>"'. $next_title . '" >>></strong></a>' . "\n";
}
?>
</div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6977 次 |
| 最近记录: |