以下是我正在处理的代码:
<?php previous_posts_link('<img src="imageURL.com/image1.png" style="width: 250px;float: left;" />'); ?>
<?php next_posts_link('<img src="imageURL.com/image2.png" style="width: 250px;float: left;" />'); ?>
哪个效果很好,除了它只显示中间页面上的两个图像,但不显示第一页和最后一页。这是有道理的,因为第一页上没有上一页,而最后一页上没有下一页。我的问题是,没有页面上的其他图像,图像看起来很奇怪。我想做的是让图像显示在第一页上,并链接到最后一页,反之亦然。我尝试使用Latest Post Link plug-in。和这段代码:
<a href="<?php latestpostlink_permalink() ?>" title="Most Recent Post">Latest >|</a>
然后三张照片出现了。我尝试将条件语句只显示在第一页上,但是我无法想到或找到正确的变量名称来告诉我在哪个页面。我对wordpress有点新鲜。感谢任何帮助,所以提前感谢!
杰里米
答案 0 :(得分:1)
打开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);
}