Phpcms v9 template making common code collection (GO)

Source: Internet
Author: User
Tags explode browser cache clear browser cache

Phpcms v9 template making common code collection (personal collection)

1. Intercept Call title length

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

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}
<li> <a target= "_blank" href= ' {$r [url]} ' title= ' {$r [title]} "style=" Color:black; " >{str_cut ($r [title],22, ')}</a></li>
{/loop}
{/PC}

4. Display column name (only name, without link)

{$catname}

Show Column name and link (can be clicked)

<a href= "{$CATEGORYS [$r [Catid]][url]}" >{$CATEGORYS [$r [' catid ']][' catname ']}</a>

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}
<a href= "/member/index.php?uid={$r [userid]}" title= "{$r [uname]}" target= "_blank" >{str_cut ($r [uname],28, ')} </a>
{/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}
<a href= "{$r [url]}" >{$r [catname]}</a> |
{/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"}
<?php $TYPE = GetCache (' type_content ', ' Commons ');? >
{Loop $data $n $r}
<li>{if $TYPE [$r [Typeid]][name]}<span style= "color: #CC6600" >[{$TYPE [$r [Typeid]][name]}] </span> {/if}<a href= "{$r [' url ']}" {Title_style ($r [style])}title= "{$r [' title ']}" target= "_blank" >{str_cut ($r [title] ,}</a></li>, ')
{/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}
<li><a href= "{$r [url]}" title= "{$r [title]}" Target=_blank>{str_cut ($r [title],36, ')}</a></li >
{/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}
<a href= ' {$r [url]} ' >{str_cut ($r [description],115)} ... </a>
{/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}
<a href= "{$r [url]}" >{$r [title]}</a>
{php $keywords = explode (', ', $r [keywords]);}
<b> Articles tagged:</b>
{Loop $keywords $keyword}
<a href= "{app_path}index.php?m=content&c=tag&catid={$catid}&tag={urlencode ($keyword)}" class= " Blue "> {$keyword}</a>
{/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}
<a style= "color: #040605" title= "{$r [title]}" href= "{$r [url]}" Target=_blank>{str_cut ($r [title],26, ')}</a >{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}
<a href= "{$r [url]}" >[{$r [' field name ']}]> {$r [title]}</a>
{/loop}
<div class= "Pagebar" >{$pages}</div>
{/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"}
<ul>
{Loop $data $key $val}
<li><a href= "{$val [' url ']}" >{$val [' title ']}</a>
<br> Price: {str_cut ($v [' Custom segment '],100)}//100 is the word count
</li>
{/loop}
</ul>
{/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}
<li><a href= "{$val [' url ']}" target= "_blank" ></a>
<a href= "{$val [' url ']}" target= "_blank" >{str_cut ($val [' title '],20)}</a></li>
{/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

<td><?php
if (Isset ($_get[' Dosubmit ')) {? ><div class= "RT" ><a
href= "javascript:void (0)" onclick= "$ (' #search '). Toggle ()" ><?php
echo L (' folded_up_in_search_of ')? ></a></div><?php}
Echo form::select_category (", $catid, ' name=" catid "id=" catid "', '",
", ' 0 ', 1)?> </td>


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.

<ul>
<!--{get sql= "select A.contentid,a.catid,a.title,a.thumb,a.description,a.url,a.status,a.updatetime, B.contentid,b.hits,b.comments from ' phpcms_content ' as A INNER joins ' Phpcms_content_count ' as B on A.contentid=b.contenti D and A.status=99 and LENGTH (A.THUMB) >0 ORDER BY b.comments desc LIMIT 3,7 "}-->
<li><span class= "Xxnse_fen2" >{$r [comments]} people participate in comments </span> <a href= "{$r [url]}" title= "{$r [title ]} ">{str_cut ($r [title],}</a></li>)
<!--{/get}-->
</ul>

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" R eturn= "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"}

<ul>

{Loop $data $key $val}

{$val [username]}< br/>

{/loop}

</ul >

{$pages}

{/PC}

One is the data source, and the one that produces the pages page effect

Source: http://www.cnblogs.com/zoubizhici/archive/2016/06.html

Phpcms v9 template making common code collection (GO)

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.