PbootCMS教程|PB建站知识|CMS二次开发|网站前端教程

pbootcms自定义扩展字段实现抓取必应每日一图

北辰与禾 PbootCMS教程 302次

pbootcms自定义扩展字段实现抓取必应每日一图。

1、在必备启动函数里加上

// 执行个人自定义标签函数
 $this->diylabel();

2、在下面继续增加以下代码

	 // 扩展单个标签
    private function diylabel()
    {
        //{ pboot:walle } 每日一图的图片URL //这里自己去掉空格哦。
        $this->content = str_replace('{pboot:walle}', $this->getBingImage(), $this->content);
    }

    //抓取必应每日一图
    private function getBingImage(){
        $url = 'https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1';
        $data = json_decode(get_url($url));
        $result = $data->images[0];
        $image = 'https://www.bing.com'.$result->url;
        return $image;
    }

3、在前台模板文件里使用{pboot:walle}即可输出图片地址。

THE END

赞赏北辰与禾
微信扫一扫打赏
“北辰与禾感谢有你!”