分页: 1 / 1

新手做模版求助。

发表于 : 2019年 6月 25日 23:21
gacjie
第一次做模版,然后会点HTTP,从网上随便找了个模版练手,遇到了几个问题来论坛请教。
QQ截图20190625231447.png
QQ截图20190625231447.png (103.02 KiB) 查看 2445 次

第一个问题,我想在案例页面调用案例下面的二级分类列表。
第二个问题,如何调用文章内的图片。
第三个问题,我想在模版设置里添加设置备案号,邮箱信息啥的功能。
哪位大佬能不能写个例子解答一下,我好照着葫芦画瓢。
提前感谢!
还有一件事情,我找了一下官方网站上面没有找到QQ群之类的交流群,哪位能分享一下。。。。
感谢!感谢!感谢!

Re: 新手做模版求助。

发表于 : 2019年 6月 26日 13:45
ClayMore
QQ群40412938 8110782

Re: 新手做模版求助。

发表于 : 2019年 6月 26日 14:20
xunm
把以下代码加入模板中的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;

}

Re: 新手做模版求助。

发表于 : 2019年 6月 26日 14:29
gacjie
感谢大佬的回复,我已经搞好了,谢谢!另外那些群我好像已经都加了一遍了,没人审核。