Phpcms v9 Template Tag tips, tags common methods _php tutorials

Source: Internet
Author: User
Tags clear browser cache
Phpcms v9 template making common code collection

1. Intercept Call title length

{Str_cut ($r [title],36, ')}, followed by quotation marks to remove ....


2. Format time

Call format Time 2011-05-06 11:22:33

{Date (' y-m-d h:i:s ', $r [Inputtime])}

3. Multi-column Call & Multi-Recommendation bit call

Call Requirements: The article range is 59 60 613 columns, and pushed to 27 and 282 recommended bits;
Starting with the third article, 7 consecutive articles are called.

{pc:get sql= "select * from V9_news where ID in (SELECT ID from V9_position_data where posid in (27,28) and CATID in (59,60,6 1) Order by Listorder DESC "cache=" 3600 "start=" 3 "num=" 7 "return=" Data "}
{Loop $data $n $r}

  • · {Str_cut ($r [title],22, ')}

  • {/loop}
    {/PC}
    4. Display column name (only name, without link)

    {$catname}
    Show Column name and link (can be clicked)

    {$CATEGORYS [$r [' catid ']][' catname '}
    5. Get parent section ID/Get Parent column name

    {$CATEGORY [$catid][parentid]}
    Parent column Name: {$CATEGORYS [$CAT [Parentid]][catname]}
    6. External data source invocation

    Dedecmsdb add at Background data source
    {pc:get sql= "select * from Cq_member where mtype= ' Enterprise '" cache= "3600" dbsource= "Dedecmsdb" num= "7" return= "Data"}
    {Loop $data $r}
    {Str_cut ($r [uname],28, ')}
    {/loop}
    {/PC}
    7. Call the Sub-column (in the column homepage template needs to use)

    {pc:content action= "category" Catid= "$catid" num= "siteid=" $siteid "order=" Listorder ASC "}
    {Loop $data $r}
    {$r [catname]} |
    {/loop}
    {/PC}
    8. Display the column name of the specified ID (example here catid=22)

    {$CATEGORYS [22][' CatName ']}
    9. Show the article category before the article

    {pc:content action= "lists" catid= "" order= "Listorder DESC" num= "14"}

    {Loop $data $n $r}

  • {if $TYPE [$r [Typeid]][name]} [{$TYPE [$r [Typeid]][name]}] {/if} {Str_cut ($r [title],33, ')}

  • {/loop}
    {/PC}
    10. Specify the variable loop growth (slides are often used)

    {pc:content action= "lists" catid= "5" order= "Listorder DESC" thumb= "1" num=
    {php $num = 0}
    {Loop $data $r}
    linkarr[{$num}] = "{$r [url]}";
    picarr[{$num}] = "{$r [thumb]}";
    textarr[{$num}] = "{str_cut ($r [title],36, ')}";
    {PHP $num + +}
    {/loop}
    {/PC}
    11. Article calls using limit

    {pc:content action= "position" posid= "$" num= "1" order= "Listorder DESC limit 1,1--"}
    Everything else is used as before.
    {pc:content action= "position" posid= "order=" Listorder DESC "limit= ' 1,8--'}
    {Loop $data $r}

  • {Str_cut ($r [title],36, ')}

  • {/loop}
    {/PC}
    12. The article is called from the specified location

    The starting position is 5, and 3 is called. Equivalent to the Limit function.
    {pc:content action= "position" posid= "order=" Listorder DESC "num=" 3 "start=" 5 "}
    {Loop $data $r}
    {Str_cut ($r [description],115)} ...
    {/loop}
    {/PC}
    13. Article List page call keyword, or first page call keyword


    Note: Explode (', ', $r [keywords]), is the article keyword through the comma separated, that is, each article to be a comma interval keyword, otherwise the call will be all as a key word. If it is a space interval keyword, the explode (', ', $r [keywords]) will be changed to explode (", $r [keywords]);

    {pc:content action= "lists" catid= "$catid" num= "order=" "id DESC" page= "$page"}
    {Loop $data $r}
    {$r [title]}
    {php $keywords = explode (', ', $r [keywords]);}
    Article Tags:
    {Loop $keywords $keyword}
    {$keyword}
    {/loop}
    {/loop}
    {/PC}
    14. Whenever a few lines of the list appear once some symbols (such as the first page of the article recommendation, a row of two, in the middle of the two want to add a vertical bar | This code is used.)

    A large number of words will be prone to error, because the modulo operation Oh, but generally also 4 titles below
    {pc:content action= "position" posid= "8" order= "Listorder DESC" num= "2"}
    {Loop $data $r}
    {Str_cut ($r [title],26, ')} {if $n%2==1} | {/if}
    {/loop}
    {/PC}
    15.V9 List page perfectly supports custom segment invocation

    {pc:content action= "lists" catid= "$catid" num= "order=" "id DESC" page= "$page" moreinfo= "1"}
    {Loop $data $r}
    [{$r [' field name ']}]> {$r [title]}
    {/loop}
    {$pages}
    {/PC}
    16. The current column calls the parent and the following column information method

    The rest of the code is still in the ground. This is the element
    {php $arrchildid = $CATEGORYS [$CAT [Parentid]][arrchildid]}
    {pc:get sql= "select * from V9_news where catid in ($arrchildid) cache=" 3600 "page=" $page "num=" \ "return=" Data "}
    17.v9 How to return the current page after the form has been submitted, not the default home file address


    Find the 73rd line of the phpcms\modules\formguide\index.php file

    ShowMessage (L (' Thanks '), App_path);

    The following code can be modified to automatically return to the previous page

    ShowMessage (L (' Thanks '), http_referer);
    18.V9 first page or pagination custom field call


    and 15, almost.
    The first normal list or column calls the custom field
    After {pc:content action= "lists", add the Sub-table moreinfo=1 (equals 1 o'clock display, 0 o'clock does not display)
    Example:

    {pc:content action= "lists" Moreinfo=1 catid= "2" order= "id DESC" num= "4"}


        {Loop $data $key $val}
      • {$val [' title ']}

        Price: {str_cut ($v [' Custom segment '],100)}//100 is the word count

      • {/loop}

    {/PC}
    The second recommended bit calls the custom field
    After you add a custom field to the model, you must click Yes in the recommended bit label
    And then use the same method to adjust the data is OK, remember, if you add the article, you must go to update the article will be displayed, the custom segment in the recommended only show you choose, the selection before adding the article does not display, update the article shows
    Example:

    {pc:content action= "position" posid= "recommended bit ID" num= "thumb=" 1 "moreinfo=" 1 "order=" Listorder DESC "}
    {Loop $data $key $val}


  • {str_cut ($val [' title '],20)}

  • {/loop}
    {/PC}

    20. Editor upload image automatically use title as ALT parameter

    One: Modify Statics/js/ckeditor/plugins/image/dialogs/image.js
    Found it

    AccessKey: ' T ', ' Default ': '
    Replaced by

    AccessKey: ' T ', ' Default ': $ (' #title '). Val ()
    Two: Clear browser cache


    21. Increase the number of random clicks on the article

    Found 100 rows of $views = $r [' views '] +1
    Modified to:
    $rand _nums=rand (79,186);
    $views = $r [' views '] + $rand _nums;
    Indicates a click, increasing the range of 79 to 186 times
    -------------------------------------------------------------
    Tips: Some version error folk solutions
    1. Thumbnail images and Atlas cannot be uploaded
    \phpcms\libs\classes\attachment.class.php
    Please put 24 lines of (also may be 23 lines)
    $this->upload_func = ' copy ';
    Change into
    $this->upload_func = ' move_uploaded_file ';
    2. Fragment Module Search article does not see the column
    phpcms\modules\block\templates\search_content.tpl.php
    13 Lines change to

    if (Isset ($_get[' Dosubmit '))) {? >href= "javascript:void (0)" onclick= "$ (' #search '). Toggle ()" > echo L (' Folded_up_in_search_of ')?> echo form::select_category (", $catid, ' name=" catid "id=" catid "', ',
    ", ' 0 ', 1)?>
    22, Phpcms V9 get tag call

    1, call the system single data, example (call ID 1 information, title length of not more than 25 kanji, display update date):
    {Get Sql= "select * from Phpcms_content where contentid=1"/}
    Title: {str_cut ($r [title])} url:{$r [URL]} Update Date: {date (' y-m-d ', $r [UpdateTime])}
    2, call the system a number of data, example (call column ID 1 through the audit of 10 information, the title length of not more than 25 characters, display update date):
    {Get Sql= "select * from Phpcms_content where catid=1 and status=99 order by updatetime Desc" rows= "10"}
    Title: {str_cut ($r [title])} url:{$r [URL]} Update Date: {date (' y-m-d ', $r [UpdateTime])}
    {/get}
    3, with paging, example (call column ID 1 through the audit of 10 information, title length of not more than 25 characters, display update date, with pagination):
    {Get Sql= "select * from Phpcms_content where catid=1 and status=99 order by updatetime Desc" rows= "" Page= "$page"}
    Title: {str_cut ($r [title])} url:{$r [URL]} Update Date: {date (' y-m-d ', $r [UpdateTime])}
    {/get}
    Paging: {$pages}
    4, the custom return variable, example (call column ID 1 through the audit of 10 information, the title length of not more than 25 Chinese characters, display the update date, the return variable is $v):
    {Get Sql= "select * from Phpcms_content where catid=1 and status=99 order by updatetime Desc" rows= "" return= "V"}
    Title: {str_cut ($v [title])} url:{$v [URL]} Update Date: {date (' y-m-d ', $v [UpdateTime])}
    {/get}
    5, call other databases under the same account, example (call the database for BBS, category ID 1 of the 10 latest theme, the theme length of not more than 25 kanji, display the updated date):
    {Get Dbname= "BBS" sql= "select * from Cdb_threads where fid=1 order by dateline Desc" rows= "10"}
    Subject: {Str_cut ($r [subject],)} url:http://bbs.phpcms.cn/viewthread.php?tid={$r [tid]} Update Date: {date (' y-m-d ', $r [ Dateline])}
    {/get}
    6, call external data, example (call data source for BBS, category ID 1 of the 10 latest theme, the topic length of not more than 25 kanji, display update date):
    {Get dbsource= "BBS" sql= "select * from Cdb_threads where fid=1 order by dateline Desc" rows= "10"}
    Subject: {Str_cut ($r [subject],)} url:http://bbs.phpcms.cn/viewthread.php?tid={$r [tid]} Update Date: {date (' y-m-d ', $r [ Dateline])}
    {/get}

    Do not know if there are no friends in the use of these methods can not meet the needs of the time?

    For example: Take out the 3rd to 10th record of the most comments, some people say I am superfluous, generally took the most comments no reason not to take the first and second, because the phpcms thumbnail to 4:3 such size is better, the strip shape (such as 3:4) picture thumbnail effect is not good, To manually update the first and second records with the most comments, you do not want to automatically update the top two entries.



      • {$r [comments]} people participate in comments · {str_cut ($r [title], 28)}


    The key point is the order by b.comments Desc LIMIT 3,7 (which means reading 7 data down from the 3rd record) This is often used in MySQL, I hold the idea of try, the result is possible.

    The effect is as follows:

    Hope to do phpcms development of friends to learn and share together

    Phpcms V9 retains the use of 2008 get tags

    It includes 2 ways of internal data and external data

    Let's first analyze how the internal data is used.

    1. Call of internal data

    {pc:get sql= "select * from ' XX ' WHERE FID = $ltid and digest =2 and Ifupload =1 ORDER by Tid DESC" num= "2" cache= "3600" re turn= "Data"}
    {Loop $data $r}

    。。。。。

    {/LOOP}{/PC}

    You can see that the GET statement supports the use of NUM but does not support limit 5,5. Such usage

    I'm really sorry.

    Num is the number of bars called

    2. Invocation of external data

    {Pc:get sql = "SELECT * from phpcms_member" cache = "3600" page = "$page" Dbsource = "discuz" return = "Data"}

        {loop $data $key $val}

        {$val [username]}< br/>

        {/loop}

        '!--ul- ->

        {$pages}

        {/PC}

        One is a data source, one is the resulting pages page effect

        http://www.bkjia.com/phpjc/477557.html www.bkjia.com true http://www.bkjia.com/phpjc/477557.html techarticle phpcms v9 template making common code collection 1. Intercept call title length {str_cut ($r [title],36,)}, The quotation marks in the back are to remove .... 2. Format time call format Time 2011-05-06 1 ...

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.