第一次做模版,然后会点HTTP,从网上随便找了个模版练手,遇到了几个问题来论坛请教。
第一个问题,我想在案例页面调用案例下面的二级分类列表。
第二个问题,如何调用文章内的图片。
第三个问题,我想在模版设置里添加设置备案号,邮箱信息啥的功能。
哪位大佬能不能写个例子解答一下,我好照着葫芦画瓢。
提前感谢!
还有一件事情,我找了一下官方网站上面没有找到QQ群之类的交流群,哪位能分享一下。。。。
感谢!感谢!感谢!
新手做模版求助。
版主: seita
Re: 新手做模版求助。
QQ群40412938 8110782
- xunm
- 帖子: 68
- 注册时间: 2018年 7月 5日 12:24
- 来自: http://luolt.cn
- 联系:
Re: 新手做模版求助。
把以下代码加入模板中的function.php文件中
代码中的图片地址自行调整
//缩略图调用
代码中的图片地址自行调整
//缩略图调用
代码: 全选
function showThumb($obj,$size=null,$link=false){
preg_match_all( "/<[img|IMG].*?src=[\'|\"](.*?)[\'|\"].*?[\/]?>/", $obj->content, $matches );
$thumb = '';
$options = Typecho_Widget::widget('Widget_Options');
$attach = $obj->attachments(1)->attachment;
if (isset($attach->isImage) && $attach->isImage == 1){
$thumb = $attach->url;
if(!empty($options->src_add) && !empty($options->cdn_add)){
$thumb = str_ireplace($options->src_add,$options->cdn_add,$thumb);
}
}elseif(isset($matches[1][0])){
$thumb = $matches[1][0];
if(!empty($options->src_add) && !empty($options->cdn_add)){
$thumb = str_ireplace($options->src_add,$options->cdn_add,$thumb);
}
}
if(empty($thumb) && empty($options->default_thumb)){
$thumb= $options->themeUrl .'/air/img/thumb/' . rand(1, 20) . '.jpg';
//去掉下面4行双斜杠 启用BING美图随机缩略图
//$str = file_get_contents('http://cn.bing.com/HPImageArchive.aspx?format=js&idx='.rand(1, 30).'&n=1');
//$array = json_decode($str);
//$imgurl = $array->{"images"}[0]->{"urlbase"};
//$thumb = '//i'.rand(0, 2).'.wp.com/cn.bing.com'.$imgurl.'_1920x1080.jpg?resize=220,150';
return $thumb;
}else{
$thumb = empty($thumb) ? $options->default_thumb : $thumb;
}
if($link){
return $thumb;
}
}
//Yoniu:取文章首图
function GetThumFromContent($content){
// 当文章无图片时的默认缩略图
$options = Typecho_Widget::widget('Widget_Options');
$random= $options->themeUrl .'/air/img/thumb/' . rand(1, 20) . '.jpg';
//正则匹配 主题目录下的/sj/的图片(以数字按顺序命名)
preg_match_all("|<img[^>]+src=\"([^>\"]+)\"?[^>]*>|is", $content->content, $img);
if($imgsrc = !empty($img[1])){
$imgsrc = $img[1][0];
}else{
preg_match_all("|<img[^>]+src=\"([^>\"]+)\"?[^>]*>|is", $content->content ,$img);
$tupian = $content->widget('Widget_Options')->tupian;
if ($tupian == 'dan'){
if($imgsrc = !empty($img[1])){
$imgsrc = $img[1][0];
}
}else if($tupian == 'shi'){
if($imgsrc = !empty($img[1])){
$imgsrc = $img[1][0];
}else{
$imgsrc = $random;
}
}else{
$imgsrc = $random;
}
}
return $imgsrc;
}