我最近尝试过上一篇文章和下一篇帖子按钮链接。我这样做是在网站的左侧和右侧的图像。它工作正常。但我不知道该怎么做
例如:
<div class="alignleftfp">
<?php next_post('%', '<img class="imgalign" src="' . WP_CONTENT_URL . '/uploads/1.png" alt="Next" /> ', 'no');
?>
</div>
<div class="alignrightfp">
<?php previous_post('%', '<img class="imgalign" src="' . WP_CONTENT_URL . '/uploads/1.png" alt="Next" /> ', 'no');
?>
</div>
是否可以在帖子的每个底部显示带有标题下的上一个帖子和下一个帖子链接。这是截图。
答案 0 :(得分:2)
<nav id="nav-single">
<?php
$prev_post = get_previous_post();
$id = $prev_post->ID ;
$permalink = get_permalink( $id );
?>
<?php
$next_post = get_next_post();
$nid = $next_post->ID ;
$permalink = get_permalink($nid);
?>
<span class="nav-previous"><?php previous_post_link( '%link', __( '<span class="meta-nav">←</span> Previous', 'twentyeleven' ) ); ?>
<h2><a href="<?php echo $permalink; ?>"><?php echo $prev_post->post_title; ?></a></h2>
</span>
<span class="nav-next"><?php next_post_link( '%link', __( 'Next <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?>
<h2><a href="<?php echo $permalink; ?>"><?php echo $next_post->post_title; ?></a></h2>
</span>
</nav>
答案 1 :(得分:1)
我希望您在single.php中使用此代码,从中显示整个帖子。要显示链接(下一个/上一个),您需要检查功能。
get_template_part()
in the same file (Single.php of your theme). In my case function in single.php has been passes parameters like
<?php get_template_part( 'content-single', get_post_format() ); ?>
So, you will open the "content-single.php" according to the parameters specified in the function and paste the same code
<div class="alignleftfp">
<?php next_post('%', '<img class="imgalign" src="' . get_bloginfo('template_directory') . '/images/1.png" alt="Next" /> ', 'no');
?>
</div>
<?php previous_post('%', '<img class="imgalign" src="' . get_bloginfo('template_directory') . '/images/2.png" alt="Next" /> ', 'no');
?>
</div>
below <h1 class="entry-title"><?php the_title(); ?></h1>
我希望这能解决你的问题。