开放的single.php并重命名previous_post_link到custom_previous_post_link和next_post_link到custom_next_post_link。然后通过以下到您的functions.php文件:
function custom_adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true)
{
if ($previous && is_attachment()) $post = get_post(get_post()->post_parent);
else $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
if (!$post)
{
$args = array(
'posts_per_page' => 1,
'orderby' => 'date',
'ignore_sticky_posts' => 1
);
if ($previous) $args['order'] = 'DESC';
else $args['order'] = 'ASC';
$adjposts = get_posts($args);
$post = $adjposts[0];
}
$title = $post->post_title;
if (empty($post->post_title)) $title = $previous ? __('Previous Post') : __('Next Post');
$title = apply_filters('the_title', $title, $post->ID);
$date = mysql2date(get_option('date_format') , $post->post_date);
$rel = $previous ? 'prev' : 'next';
$string = '<a href="' . get_permalink($post) . '" rel="' . $rel . '">';
$inlink = str_replace('%title', $title, $link);
$inlink = str_replace('%date', $date, $inlink);
$inlink = $string . $inlink . '</a>';
$output = str_replace('%link', $inlink, $format);
$adjacent = $previous ? 'previous' : 'next';
echo apply_filters("{$adjacent}_post_link", $output, $format, $link, $post);
}
function custom_previous_post_link($format = '« %link', $link = '%title', $in_same_cat = false, $excluded_categories = '')
{
custom_adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true);
}
function custom_next_post_link($format = '%link »', $link = '%title', $in_same_cat = false, $excluded_categories = '')
{
custom_adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false);
}
快速的问题。我的previous_post_link和next_post_link应该位于single.php文件中吗?现在不是。它实际上在archive.php文件中。 – 2015-01-22 02:20:19
通常single.php用于单个帖子。存档可以用作存档模板。这真的取决于你的主题和设计师如何制作结构。如果您在archive.php文件中进行了更改并且它可以正常工作,那么没有什么可做的了。 – Todd 2015-01-23 03:00:59
由于某些原因,当我更改archive.php文件时,它不起作用。它实际上删除了按钮和下面的一切(页脚等)。 – 2015-01-24 03:22:49