wordpress最新文章特殊放大显示自定义

第一步function.php里面添加代码

function wpb_demo_shortcode()
{
	//获取到最新的文章的参数,获取几篇最新的文章
	$args = array('numberposts' => '1');
	//获取到最新文章的数据
	$recent_posts = wp_get_recent_posts($args);
	//只获取了一篇文章,直接取id
	$newBlogId = $recent_posts[0]['ID'];
	//获取文章的特色图像
	$imgArray =  wp_get_attachment_image_src(get_post_thumbnail_id($newBlogId));
	$imgUrl = $imgArray[0];
	//获取文章的标题
	$newBlogTitle = $recent_posts[0]['post_title'];
	//将文章的发布时间转化为时间戳,再进行格式化
	$newBlogDate =  date('M j, Y', strtotime($recent_posts[0]['post_date']));
	//获取文章的摘要部分
	$newPostContent = get_the_excerpt($newBlogId);
	//获取文章的详情页的url
	$thisPostUrl = $recent_posts[0]['guid'];
	// return print_r($recent_posts);
	//拿到所有数据后开始构造页面
	return "<a href='$thisPostUrl'target='_blank'>"
	."<div style='position: relative;background-image: url($imgUrl);background-repeat: no-repeat;
	background-position: center center;background-size: cover;padding-top:200px;padding-bottom:350px;'>".
		"<div style='color:#ffffff;position:absolute;top: 100px;width: 100%;z-index: 3;'>"
		."<div style='font-size:35px;text-align: center;font-weight: 600;'>$newBlogTitle</div>"
		."<div style='font-size:20px;text-align: center;margin-top:20px;'>$newBlogDate</div>"
		."<div style='font-size:20px;text-align: center;margin-top:20px;'>$newPostContent</div>"
		."</div>"
		. "<div style='background-color: rgba(0,0,0,.45);position: absolute;top: 0;height: 100%;width: 100%;'></div>"
	."</div></a>";

}
// register shortcode
add_shortcode('get_latest_articles', 'wpb_demo_shortcode');

第二步使用elementor的短代码来添加上
在这里插入图片描述
最后实现结果,最新的文章放大显示其他文章都是缩小显示
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值