帝国cms常用调用代码SEO方向
网站优化每次找代码很麻烦,所以我这里给备用一下,包括一些自定义的函数,其实大多数都是PHP代码
第一类:高效率随机调用代码
<?php $randnum=32; //随机数量 $randids=''; $randdh=''; for($i=1;$i<=$randnum;$i++) { $randids.=$randdh.rand(1,100); //1为最小ID,100000为最大ID $randdh=','; } ?> [e:loop={1,32,0,0,"id in ($randids)"}] <li> <a href="<?=$bqsr['titleurl']?>" title="<?=$bqr['title']?>"><?=$bqr['title']?></a> </li> [/e:loop]
随机高效率进化版:
这个版本的代码,主要是为了方便调取指定栏目的随机文章,为了方便模板的编辑,所以没有封装成函数
<?php $file_cache = ECMS_PATH."news.json"; //缓存整个news表的数据 if(!file_exists($file_cache)){ //查询分类 $hm_class=$empire->query("select classid from {$dbtbpre}enewsclass"); while($hm_r=$empire->fetch($hm_class)) { //查询分类下面的所有id $hm_news=$empire->query("SELECT id FROM `{$dbtbpre}ecms_news` WHERE `classid` = {$hm_r[classid]}"); while($hm_nr=$empire->fetch($hm_news)) { $news_data[$hm_r['classid']][] = $hm_nr[id]; } } file_put_contents($file_cache,json_encode($news_data)); } //获取缓存数据表 $file_arrs = json_decode(file_get_contents($file_cache),true); //根据数据表获取id,每个栏目随机分配文章id foreach($file_arrs as $k=>$v){ $num = count($v)-1; //增加变量 for ($rani=1; $rani<=30; $rani++){ $rand_id.= $v[mt_rand(0,$num)].","; } $rand_id = rtrim($rand_id,","); $rand_data[] = $rand_id; $rand_id = ""; $rani=1; } ?>
调用方式:
<?php $classid = $rand_data[$class_r[$GLOBALS[navclassid]][classid]-1]; ?> [ecmsinfo]0,20,32,0,3,14,0,"id in ($classid)"[/ecmsinfo]
高效率随机调用tag
<code class="hljs language-php-template"><span class="language-php"><span class="hljs-meta"><?php</span> <span class="hljs-variable">$num</span>=<span class="hljs-variable">$empire</span>-><span class="hljs-title function_ invoke__">num</span>(<span class="hljs-string">"select tagid from <span class="hljs-subst">{$dbtbpre}</span>enewstags"</span>); <span class="hljs-variable">$randnum</span>=<span class="hljs-number">100</span>; <span class="hljs-variable">$randids</span>=<span class="hljs-string">''</span>; <span class="hljs-variable">$randdh</span>=<span class="hljs-string">''</span>; <span class="hljs-keyword">for</span>(<span class="hljs-variable">$i</span>=<span class="hljs-number">1</span>;<span class="hljs-variable">$i</span><=<span class="hljs-variable">$randnum</span>;<span class="hljs-variable">$i</span>++) { <span class="hljs-variable">$randids</span>.=<span class="hljs-variable">$randdh</span>.<span class="hljs-title function_ invoke__">rand</span>(<span class="hljs-number">1</span>,<span class="hljs-variable">$num</span>); <span class="hljs-variable">$randdh</span>=<span class="hljs-string">','</span>; } <span class="hljs-meta">?></span></span><span class="language-xml"> [e:loop={"select tagname,tagid from phome_enewstags where tagid in ($randids) limit $randnum",32,24,0}] <span class="hljs-tag"><<span class="hljs-name">a</span> <span class="hljs-attr">target</span>=<span class="hljs-string">"_blank"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/tag/</span></span></span><span class="language-php"><span class="hljs-meta"><?=</span><span class="hljs-variable">$bqr</span>[<span class="hljs-string">'tagid'</span>]<span class="hljs-meta">?></span></span><span class="language-xml"><span class="hljs-tag"><span class="hljs-string">/"</span> <span class="hljs-attr">title</span>=<span class="hljs-string">"</span></span></span><span class="language-php"><span class="hljs-meta"><?=</span><span class="hljs-variable">$bqr</span>[<span class="hljs-string">'tagname'</span>]<span class="hljs-meta">?></span></span><span class="language-xml"><span class="hljs-tag"><span class="hljs-string">"</span>></span></span><span class="language-php"><span class="hljs-meta"><?=</span><span class="hljs-variable">$bqr</span>[<span class="hljs-string">'tagname'</span>]<span class="hljs-meta">?></span></span><span class="language-xml"><span class="hljs-tag"></<span class="hljs-name">a</span>></span> | [/e:loop]</span></code>
随机调用tag,其实这种可以改一改,随机调用所有表的信息,具体可以自行修改