<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:wfw="http://wellformedweb.org/CommentAPI/">
<channel>
<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>
<atom:link href="https://www.ishiguang.cn/feed/tag/ZBLOG%E7%9B%B8%E5%85%B3%E6%96%87%E7%AB%A0%E8%B0%83%E7%94%A8/" rel="self" type="application/rss+xml" />
<language>zh-CN</language>
<description></description>
<lastBuildDate>Sat, 26 Feb 2022 17:15:00 +0800</lastBuildDate>
<pubDate>Sat, 26 Feb 2022 17:15:00 +0800</pubDate>
<item>
<title>ZBLOG PHP自动调用文章首张图片和随机调用代码</title>
<link>https://www.ishiguang.cn/15193.html</link>
<guid>https://www.ishiguang.cn/15193.html</guid>
<pubDate>Sat, 26 Feb 2022 17:15:00 +0800</pubDate>
<dc:creator>ssr</dc:creator>
<description><![CDATA[有时为了文章页面美观，我们会调用文章的首张图片或者随机主题图片进行展示，而新版的zblog官方提供了直接调用文章拖图片的函数代码，通过把这个函数代码天街到相应的模板文件，调用相应变量，输入图片u...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<p>有时为了文章页面美观，我们会调用文章的首张图片或者随机主题图片进行展示，而新版的zblog官方提供了直接调用文章拖图片的函数代码，通过把这个函数代码天街到相应的模板文件，调用相应变量，输入图片url即可实现。其中zblog官方z-WiKi提供的代码如下：</p><pre><code>   &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; </code></pre><p>实现调用首张图片的代码：</p><pre><code>       &lt;pre&gt;&lt;code&gt;&lt;img src=&quot;{$temp}&quot; /&gt;
       &lt;/code&gt;&lt;/pre&gt;</code></pre><p>当文章没有图片的时候，随机调用主题style/images/random/下的1.jpg、2.jpg、3.jpg、4.jpg图片。 <br>如果不想调用随机图片，可以把代码修成成如下：</p><pre><code>   &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; </code></pre><p>用于分类文章列表下：</p><pre><code>   &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; </code></pre><p>以上代码函数实现的是调用文章首张图片，如果文章没有图片就调用默认图片no-image.jpg</p>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://www.ishiguang.cn/15193.html#comments</comments>
<wfw:commentRss>https://www.ishiguang.cn/feed/tag/ZBLOG%E7%9B%B8%E5%85%B3%E6%96%87%E7%AB%A0%E8%B0%83%E7%94%A8/</wfw:commentRss>
</item>
</channel>
</rss>