WordPress上一篇、下一篇文章链接添加title属性的方法


也想出现在这里?联系我们
上一篇、下一篇文章代码:该代码解析出来的代码大概如下:

上一篇、下一篇文章代码:
 
<?php previous_post_link('%link','<<') ?>
<?php next_post_link('%link','>>') ?>
  该代码解析出来的代码大概如下:
<a href="……" rel="external nofollow"  rel="external nofollow" > …… </a>
<a href="……" rel="external nofollow"  rel="external nofollow" > …… </a>
  通过 get_previous_post、get_next_post 这两个函数我们可以获取到上一篇和下一篇文章的相关信息(大家可以到官网看看这两个函数的介绍)。   具体解决方法如下: 将
 
<?php previous_post_link('%link','<<') ?>
<?php next_post_link('%link','>>') ?>
替换为
 
<?php
$prev_post = get_previous_post();
if (!empty( $prev_post )): ?>
  <a title="<?php echo $prev_post->post_title; ?>" href="<?php echo get_permalink( $prev_post->ID ); ?>" rel="external nofollow" ><?php echo $prev_post->post_title; ?></a>
<?php endif; ?>
<?php
$next_post = get_next_post();
if (!empty( $next_post )): ?>
  <a title="<?php echo $next_post->post_title; ?>" href="<?php echo get_permalink( $next_post->ID ); ?>" rel="external nofollow" ><?php echo $next_post->post_title; ?></a>
<?php endif; ?>

特别声明:以上内容(如有图片或视频亦包括在内)为本平台用户上传并发布,本平台仅提供信息存储服务。

开通vip