文章目录
- //WordPress文章上一篇下一篇显示缩略图
function wptoo_pageturn_thumb($id){
if (has_post_thumbnail($id)) {
echo get_the_post_thumbnail( $id, ”, ” );
} else {
$first_img = ”;
ob_start();
ob_end_clean();
$output = preg_match_all(‘//i’, get_post( $id )->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$random = mt_rand(1, 10);
$first_img= get_bloginfo ( ‘stylesheet_directory’ ).’/images/random/’.$random.’.jpg’;
}
echo ‘post_title.'” />’;
}
} - 1、首先将上面的代码按需要添加到主题 functions.php 文件中。
2、然后将下面代码添加到single.php文件中,文章上一篇下一篇显示缩略图就能够实现了。ID);?>
<a href="ID ); ?>” rel=”external nofollow” >
上一篇:post_title; ?>
ID);?>
<a href="ID ); ?>” rel=”external nofollow” >
下一篇:post_title; ?>遇到WordPress建站上的问题可以加入我们的WordPress交流群一起交流分享WordPress建站经验噢。
WordPress交流群:8424781
文章来自小白学习资源站https://qyymz.com转载请保留本链接,谢谢!
用惯了文章标题+文章链接的上一篇下一篇样式吗?
前段时间博主在朋友的WordPress博客看到文章缩略图+文章标题+文章链接的上一篇下一篇样式,觉得特别有意思,于是自己也试着实现这样的效果。
网上案例也挺多的,搜出一大堆,整理了下今天分享出来

//WordPress文章上一篇下一篇显示缩略图
function wptoo_pageturn_thumb($id){
if (has_post_thumbnail($id)) {
echo get_the_post_thumbnail( $id, '', '' );
} else {
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/
/i', get_post( $id )->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$random = mt_rand(1, 10);
$first_img= get_bloginfo ( 'stylesheet_directory' ).'/images/random/'.$random.'.jpg';
}
echo '
post_title.'" />';
}
}
//WordPress文章上一篇下一篇显示缩略图
function wptoo_pageturn_thumb($id){
if (has_post_thumbnail($id)) {
echo get_the_post_thumbnail( $id, '', '' );
} else {
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/
/i', get_post( $id )->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$random = mt_rand(1, 10);
$first_img= get_bloginfo ( 'stylesheet_directory' ).'/images/random/'.$random.'.jpg';
}
echo '
post_title.'" />';
}
}
1、首先将上面的代码按需要添加到主题 functions.php 文件中。
2、然后将下面代码添加到single.php文件中,文章上一篇下一篇显示缩略图就能够实现了。
ID);?>
<a href="ID ); ?>" rel="external nofollow" >
上一篇:post_title; ?>
ID);?>
<a href="ID ); ?>" rel="external nofollow" >
下一篇:post_title; ?>
遇到WordPress建站上的问题可以加入我们的WordPress交流群一起交流分享WordPress建站经验噢。
WordPress交流群:8424781
文章来自小白学习资源站https://qyymz.com转载请保留本链接,谢谢!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
