2024年10月12日 建站教程
一般情况下日志中会有很多链接,那么wordpress如何获取日志中的第一个链接?下面web建站小编给大家详细介绍一下具体方法!
function get_content_first_link( $content = false, $echo = false ){
if ( $content === false )
$content = get_the_content();
preg_match_all('/<a.*?href=['"](.*?)['"].*?>/i', $content, $links);
if($links){
return $links[1][0];
}else {
return false;
}
}
<h2><a href="<?php echo get_content_link(get_the_content()); ?>"><?php the_title(); ?></a></h2>
本文链接:http://so.lmcjl.com/news/15223/