Why does smarty generate static pages? I want to use smarty to generate a list page, which is really static.
For example:
Category: News
50 data entries in total.
A list page contains 10 data records.
There are 5 tabs in total.
For example, dedecms generates a column page.
How can this problem be achieved? Write a small example.
Reply to discussion (solution)
There is no difference between smarty and php.
To make the five pages of the generated content into pages in a certain format, you must write a method in smarty.
Http://bbs.php100.com/read-htm-tid-308311.html
The link sent by the moderator. the code is not specific and the template is not easy to implement.
The difficulty lies in,
How to Write a list page template?
Background program, how to generate different pages by page and call different articles.
I have already done this. I want to share the code with you and hope someone can use it later.
Public function tplmakelist (& $ tpl) {$ pageSize = 1; $ _ field = array ('A. ID', 'A. title ',' B. typedir', 'B. templist ',' B. keyword', 'B. description '); $ this-> _ tables = array (DB_FREFIX. 'article A', DB_FREFIX. 'article _ category B '); $ data = parent: select ($ _ field, array ('where' => array (". catid = B. id AND B. id = {$ this-> _ R ['typeid']} "); $ total = count ($ data ); // all articles under the category $ pageTotal = ceil ($ total/$ pageSize); // total number of pages $ tpl-> template_dir = SM ARTY_TEMPLATE_DIR; for ($ I = 1; $ I <= $ pageTotal; $ I ++) {// The number of pages generated $ file_name = ROOT_PATH. $ data [0]-> typedir. "/list _ {$ this-> _r0000'typeid'00000000_polici.html"; $ this-> _ tables = array (DB_FREFIX. 'article A', DB_FREFIX. 'article _ category B '); $ firstPage = ($ i-1) * $ pageSize; $ datas = parent: select ($ _ field, array ('where' => array (". catid = B. id AND B. id = {$ this-> _ R ['typeid']} "), 'limit' =>" $ firstPage, $ pageSize ")); $ tpl-> assign ('findlist', $ data [0]); $ tpl-> assign ('pagelist', $ datas); $ content = $ tpl-> fetch ($ data [0]-> templist ); $ this-> MakeHtmlFile ($ file_name, $ content) ;}} private function MakeHtmlFile ($ file_name, $ content) {// create if (! File_exists (dirname ($ file_name) {if (! @ Mkdir (dirname ($ file_name), 0777) {die ($ file_name. "directory creation failed! ") ;}} If (! $ Fp = fopen ($ file_name, "w") {echo "file opening failed! "; Return false;} if (! Fwrite ($ fp, $ content) {echo "file write failed! "; Fclose ($ fp); return false;} fclose ($ fp); chmod ($ file_name, 0666 );}
{foreach from=$pagelist item=list}{$list->title}
{/foreach}
If you want to use it in the future, replace the database fields and connect to the database based on your own engine. of course, the database is still to be expanded.