是否可以在所有页面上的 wordpress 上一篇文章中下一篇文章


Is it possible in wordpress previous post next post on all pages?

这是我正在处理的代码:

<?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;" />'); ?>

这很好用,除了它只在中间页面上显示两个图像,而不是在第一页和最后一页上。这是有道理的,因为第一页上没有上一页,最后一页上也没有下一页。我的问题是页面上没有其他图像的图像看起来很奇怪。我想做的是让图像出现在第一页上并链接到最后一篇文章,反之亦然。我尝试使用最新的帖子链接插件。和这个代码:

<a href="<?php latestpostlink_permalink() ?>" title="Most Recent Post">Latest &gt;|</a>

但随后出现了三个图像。我尝试放置条件语句以仅使此图像显示在第一页上,但是我想不出或找到正确的变量名称来告诉我在哪个页面上。我对wordpress有点陌生。任何帮助都非常感谢,所以提前感谢!

杰里米

打开单曲.php并将previous_post_link重命名为 custom_previous_post_link,将next_post_link重命名为 custom_next_post_link。 然后将以下内容粘贴到函数.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 = '&laquo; %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 &raquo;', $link = '%title', $in_same_cat = false, $excluded_categories = '')
    {
    custom_adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false);
    }