zblog
当前位置:首页 > 商学院 > zblog > 正文内容

zblog

添加文章缩略图

豫唐网络2022-10-12 12:222703

自定义缩略图,列表缩略图片,未设置则调用文章首图,首图也没有,调用自定义默认图片,本教程对图片进行的裁剪处理,已方便减少图片请求所产生的带宽问题,操作步骤如下。

1、添加《原生代码上传图片》代码

https://www.ytecn.com/post/396.html

2、在文章编辑页面接口位置添加代码

functionActivePlugin_ytecn_ai_xzjt(){
Add_Filter_Plugin('Filter_Plugin_Edit_Response5','ytecn_ai_xzjt_edit_response');
}
functionytecn_ai_xzjt_edit_response(){
global$zbp,$article;
echo'<scripttype="text/javascript"src="'.$zbp->host.'zb_users/plugin/ytecn_ai_xzjt/script/upload.js"></script>';
echo'<styletype="text/css">
.ytecn_input_img{width:40%!important;}
.ytecn_upimgbutton{width:120px;}
.ytecn_upimg{width:100px;vertical-align:middle;}</style>';
echo'<divid="tesetu">缩略图1:
<inputname="meta_pic"id="edtTitle"type="text"class="ytecn_input_img"value="'.$article->Metas->tesetu1.'"/>
<inputtype="button"class="ytecn_upimgbutton"value="选择图片">
<imgclass="ytecn_upimg"src="'.$article->Metas->pic.'">
</div>';
echo'<divid="tesetu">缩略图2:
<inputname="meta_pic2"id="edtTitle"type="text"class="ytecn_input_img"value="'.$article->Metas->tesetu2.'"/>
<inputtype="button"class="ytecn_upimgbutton"value="选择图片">
<imgclass="ytecn_upimg"src="'.$article->Metas->pic2.'">
</div>';
}

3、通过Filter_Plugin_Post_Get接口,添加图片自定义输出字段,并处理逻辑关系。

functionActivePlugin_ytecn_ai_xzjt(){
Add_Filter_Plugin('Filter_Plugin_Post_Call','ytecn_nana_Post_Call');
}
functionytecn_nana_Post_Call($post,$method,$args)
{
global$zbp;
if($method=='img'){
$GLOBALS['hooks']['Filter_Plugin_Post_Call']['ytecn_nana_Post_Call']=PLUGIN_EXITSIGNAL_RETURN;
if(!empty($post->Metas->pic)){
$img[]=$post->Metas->pic;
}elseif($post->ImageCount){
$img[]=$post->AllImages[0];
}else{
$random=mt_rand(1,10);
$img[]=$zbp->host.'zb_users/theme/ytecn_nana/image/random/'.$random.'.png';
}
if(empty($args)){
return$img[0];
}else{
$width=$args[0];
$height=$args[1];
$imgs=Thumb::Thumbs($img,$width,$height);
return$imgs[0];
}
}
}

5、前台调用,在需要的地方,输入

{$article->img(200,100)}

img括号里面的是裁剪的宽和高。

如不需要裁剪,则输入

{$article->img()}


完整源码下载:

请开通vip查阅

扫描二维码推送至手机访问。

版权声明:本文由汤阴县豫唐网络科技有限公司发布,如需转载请注明出处。

本文链接:https://www.ytecn.com/post/363.html

分享给朋友:

相关文章

zblogphp页面管理页面增加子菜单接口说明

zblogphp页面管理页面增加子菜单接口说明

接口名称:Filter_Plugin_Admin_PageMng_SubMenu接口描述:文章管理页面增加子菜单调用方法:Add_Filter_Plugin('Filter_Plugin_Ad...

zblogphp文章页面编辑3号输出接口说明

zblogphp文章页面编辑3号输出接口说明

接口名称:Filter_Plugin_Edit_Response3接口描述:文章编辑页面3号输出接口,具体位置位于右侧底部。应用场景:可在文章(页面)编辑页增加自定义参数,如自定义表单字段等。调用方法...

zblogphp程序报错后如何获得帮助

zblogphp程序报错后如何获得帮助

zblogphp程序报错后获取帮助分为免费和付费两种。免费帮助方法1开启调试模式(点击打开新链接),将截图发到群内。方法2提交工单或私信把网站信息发群主,等凑够一定数量后,群主开直播查错。付费帮助找群...

zba文件怎么使用?zba文件是什么?

zba文件怎么使用?zba文件是什么?

.zba是zblogphp的专用应用格式。应用格式又分主题和插件两种。.zba主题安装,打开zblog后台,选择《主题管理》,点击《本地上传并安装主题zba文件》,上传后点击提交,然后开启主题,安装完...

zblog商业授权

zblog商业授权

zblog的商用链接,已与2022年01月28从官网移除,git开源协议MIT。如你依然不放心,可以找豫唐购买授权服务。豫唐是zblog的指定授权商之一。Z-Blog 授权价格及服务支持版本授权许可:...

zblogphp开源免费、小巧强大的博客程序与CMS建站系统

zblogphp开源免费、小巧强大的博客程序与CMS建站系统

Z-BlogPHP 基于 PHP 平台,支持 MySQL(含 MariaDB)、SQLite 和 PostgreSQL 数据库。期待它能成为您建站、写博的上佳选择。我们一直在努力把 Z-BlogPHP...