<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel rdf:about="https://www.ishiguang.cn/feed/rss/tag/ZBLOG%E7%9B%B8%E5%85%B3%E6%96%87%E7%AB%A0%E8%B0%83%E7%94%A8/">
<title>拾光 - ZBLOG相关文章调用</title>
<link>https://www.ishiguang.cn/tag/ZBLOG%E7%9B%B8%E5%85%B3%E6%96%87%E7%AB%A0%E8%B0%83%E7%94%A8/</link>
<description></description>
<items>
<rdf:Seq>
<rdf:li resource="https://www.ishiguang.cn/15193.html"/>
</rdf:Seq>
</items>
</channel>
<item rdf:about="https://www.ishiguang.cn/15193.html">
<title>ZBLOG PHP自动调用文章首张图片和随机调用代码</title>
<link>https://www.ishiguang.cn/15193.html</link>
<dc:date>2022-02-26T17:15:00+08:00</dc:date>
<description>有时为了文章页面美观，我们会调用文章的首张图片或者随机主题图片进行展示，而新版的zblog官方提供了直接调用文章拖图片的函数代码，通过把这个函数代码天街到相应的模板文件，调用相应变量，输入图片url即可实现。其中zblog官方z-WiKi提供的代码如下：   &lt;pre&gt;&lt;code&gt;{php}

   $temp=mt_rand(1,4);

   $pattern=&quot;/&lt;[img|IMG].*?src=[\&#039;|\&quot;](.*?(?:[\.gif|\.jpg|\.png]))[\&#039;|\&quot;].*?[\/]?&gt;/&quot;;

   $content = $article-&gt;Content;

   preg_match_all($pattern,$content,$matchContent);

   if(isset($matchContent[1][0]))

   $temp=$matchContent[1][0];

   else

   $temp=$zbp-&gt;host.&quot;zb_users/theme/$theme/style/images/random/$temp.jpg?imageMogr2/format/webp&quot;;//需要在相应位置放置4张jpg的文件，名称为1，2，3，4

   {/php}
   &lt;/code&gt;&lt;/pre&gt; 实现调用首张图片的代码：       &lt;pre&gt;&lt;code&gt;&lt;img src=&quot;{$temp}&quot; /&gt;
       &lt;/code&gt;&lt;/pre&gt;当文章没有图片的时候，随机调用主题style/images/random/下的1.jpg、2.jpg、3.jpg、4.jpg图片。 如果不想调用随机图片，可以把代码修成成如下：   &lt;pre&gt;&lt;code&gt;{php}

   $pattern=&quot;/&lt;[img|IMG].*?src=[\&#039;|\&quot;](.*?(?:[\.gif|\.jpg|\.png]))[\&#039;|\&quot;].*?[\/]?&gt;/&quot;;

   $content = $article-&gt;Content;

   preg_match_all($pattern,$content,$matchContent);

   if(isset($matchContent[1][0]))

   $temp=$matchContent[1][0];

   else

   $temp=$zbp-&gt;host.&quot;zb_users/theme/$theme/style/images/random/no-image.jpg?imageMogr2/format/webp&quot;;//在相应位置放置一张命名为no-image的jpg图片

   {/php}
   &lt;/code&gt;&lt;/pre&gt; 用于分类文章列表下：   &lt;pre&gt;&lt;code&gt;{foreach GetList(12,1,null,null,null,null,array(&#039;has_subcate&#039; =&gt; ture)) as $related}

   &lt;li&gt;

   {php}

   $pattern=&quot;/&lt;[img|IMG].*?src=[\&#039;|\&quot;](.*?(?:[\.gif|\.jpg|\.png]))[\&#039;|\&quot;].*?[\/]?&gt;/&quot;;

   $content = $related-&gt;Content;

   preg_match_all($pattern,$content,$matchContent);

   if($matchContent[1][0])

   $temp=$matchContent[1][0];

   else

   $temp=&quot;$host&quot;.&quot;zb_users/theme/$theme/style/images/no-image.jpg?imageMogr2/format/webp&quot;;

   {/php}

   &lt;a href=&quot;{$related.Url}&quot; title=&quot;{$related.Title}&quot;&gt;&lt;img src=&quot;{$temp}&quot; alt=&quot;{$related.Title}&quot; /&gt;&lt;/a&gt;

   &lt;/li&gt;

   {/foreach}
   &lt;/code&gt;&lt;/pre&gt; 以上代码函数实现的是调用文章首张图片，如果文章没有图片就调用默认图片no-image.jpg</description>
</item>
</rdf:RDF>