phpcms 知識總結

來源:互聯網
上載者:User

phpcms是一套功能很強大,智能,好用的內容管理系統,最近再做phmcms二次開發,學到了不少東西。

現在總結下,與大家分享下。

在調用多個欄目下的文章列表時,可以用get標籤.

{pc:get sql="select * from v9_product where catid in($arr)" order="id ASC" thumb="2" num="40"  return="info" page="$pages"} 

{/pc}

需要注意的是這裡的$arr為字串形式,而不能為數組,如$arr="21,23,32";是可以的,

而$arr = array(21,23,32);則是不行的,會出現錯誤,導致得不到結果。

如果想隨機排序,直接將order="rand()",就可以了。

普通列表或欄目調用自訂欄位

在{pc:content  action="lists" 後加上副表moreinfo=1 (等於1時顯示,0時不顯示)

在編輯文章時,如果不想自動添加關鍵字,可以在

可以通過phpcms/modules/content/fields/title/form.inc.php,去掉其中的onBlur事件,就好了。

<?php  $catid = $_GET['catid'];?>

來擷取相應的欄目id.這在實際操作中很有用。

在phpcms 中調用通過一級欄目調用三級欄目的代碼。

{pc:content action="category" catid="$catid" order="listorder ASC" num="40" thumb="2"  return="info"}                 
                    {loop $info $r}  
                    <?php
                        $catidt = $r[catid];
                    ?>
                    <ul>    
                      {pc:content action="lists" catid="$catidt" order="listorder ASC" num="40" thumb="2" return="data"}                                                           
                    {loop $data $v}         
                        <li class="cl">
                          <a href="">
                             <a href="{$v['url']}" target="_blank"><img class="imgs_pro" width="179" height="144" src="{$v['thumb']}"/></a>
                          <h3 class="product-name">
                            <a href="{$v['url']}" target="_blank">
                              <span class="orname1">{$v['title']}</span></a>
                          </h3>
                          <span class="lingshoujia">全國統一銷售價:<b>¥</b>{$v['price']}                      </span>
                          <span class="tejia"><i></i>:<b>¥</b>{$v['tgprice']}</span>
                        </li>                        
                    {/loop}
                    {/pc}                    
                    </ul>
                  {/loop}
 {/pc}

在這裡,有點鬱悶的是,為什麼第二個迴圈中catid不能直接用catid="$r['catid']",而需要先通過$catid=$r[catid]取得。先記下來。

在PHPCMS V9中我們正式開始需要PC標籤做為資料的擷取的方式。如:

{pc:content action="lists"
cache="3600" num="20" page="$page"}{/pc}

下表為PC標籤保留參數表,幾乎所有的PC標籤都支援這些保留參數設定

 

變數名

預設值

說明

action

null

本參數的值表示為操作事件,模型類PC標籤必須使用包含本參數,以說明要進行的操作。

cache

0

緩衝儲存時間(單位秒)

num

20

擷取記錄的條數,最後會被模板引擎處理成limit傳送到處理函數中。

page

null

當前分頁。一般填寫為$_GET[page]

urlrule

null

URL規則

return

data

返回資料變數名

這裡有一必要說一下get標籤,可以對資料庫進行靈活操作,如:

{pc:get sql="SELECT
* FROM phpcms_member" cache="3600" page="$page"
dbsource="discuz"return="data"}

<ul>

{loop $data $key $val}

{$val[username]}<br/>

{/loop}

</ul>

{$pages}

{/pc}

GET標籤所支援的參數。

參數

預設值

必須

 

說明

sql

null

 

要執行的SQL語句

cache

0

 

緩衝時間,單位為秒

page

0

 

分頁,通過變數把當前的分布傳給PC標籤進行處理

dbsource

null

 

資料來源,當你通過系統背景資料來源模組配置過資料來源時,可把資料來源名填寫到這裡,系統會去對應的資料來源來讀取資料。如果要讀取本系統的資料請留空

return

data

 

 返回的資料的變數

常用的函數:

str_cut(): {str_cut($v['title'],50)}, 標題長度截取。

thumb(): {thumb($v['thumb'],178,131)},產生縮圖。

phpcms 模板if,else解析原理

例:

      {pc:content action="lists" catid="12" num="1" order="id DESC" return="info"}                {loop $info $v}                    <!--圖片-->                    <div class="img_top">                    {if $v[thumb]==null}                        <img src="{thumb($v['thumb'],278,198)}"/>                        {else} <img src="{IMG_PATH}lianmengimg/wstupianbg.jpg"/>{/if}                      </div>                    <!--圖片-->                                        <h3><a href="{$v['url']}" target="_blank">{str_cut($v['title'],55)}</a></h3>                    <div class="ws_text">                    <p>{$v['description']}</p>                    </div>                {/loop}      {/pc}

用php代碼來實現,其實是這樣的。

<?php if(defined('IN_ADMIN')  && !defined('HTML')) {echo "<div class=\"admin_piao\" pc_action=\"content\" data=\"op=content&tag_md5=0fbcb24c67cefe51efba7d05ace80da0&action=lists&catid=12&num=1&order=id+DESC&return=info\"><a href=\"javascript:void(0)\" class=\"admin_piao_edit\">編輯</a>";}$content_tag = pc_base::load_app_class("content_tag", "content");if (method_exists($content_tag, 'lists')) {$info = $content_tag->lists(array('catid'=>'12','order'=>'id DESC','limit'=>'1',));}?>                <?php $n=1;if(is_array($info)) foreach($info AS $v) { ?>                    <!--圖片-->                    <div class="img_top">                    <?php if($v[thumb]==null) { ?>                        <img src="<?php echo thumb($v['thumb'],278,198);?>"/>                        <?php } else { ?> <img src="<?php echo IMG_PATH;?>lianmengimg/wstupianbg.jpg"/> <?php } ?>                      </div>                    <!--圖片-->                                        <h3><a href="<?php echo $v['url'];?>" target="_blank"><?php echo str_cut($v['title'],55);?></a></h3>                    <div class="ws_text">                    <p><?php echo $v['description'];?></p>                    </div>                <?php $n++;}unset($n); ?>                <?php if(defined('IN_ADMIN') && !defined('HTML')) {echo '</div>';}?>  

還有一個關於if,else的例子:

{pc:content action="lists" catid="42" order="id DESC" num="5" }{loop $data $n $r}<li>·<a href="{$r['url']}" title="{$r['title']}"{title_style($r[style])}>{str_cut($r[title],39,'')}</a> {if time()-$r[updatetime]<24*180*60}<img src='/image/new.gif' />{else}<span class="ind_tim2">{date('m-d',$r[inputtime])}</span>{/if}</li>{/loop}{/pc}

在列表頁如果想實現分布功能需要加上page="$page":

{pc:content  action="lists" catid="$catid" order="prorder ASC" thumb="2" num="6"  page="$page" return="info"} <div id="pages" class="text-c">{$pages}</div>{/pc}
如何在category頁調取所有子欄目列表

    {pc:content action="category" catid="$catid" num="25" siteid="$siteid" order="listorder ASC"}    <ul>    {loop $data $r}    <li><a href="{$r[url]}">{$r[catname]}</a></li>    {/loop}    </ul>    {/pc}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.