Home > Backend Development > PHP Tutorial > PHP combined with smarty generates static pages and paging code in PHP articles

PHP combined with smarty generates static pages and paging code in PHP articles

WBOY
Release: 2016-07-25 08:52:58
Original
943 people have browsed it
This article introduces the method of using smarty template engine to generate static pages in PHP, as well as the implementation code of article paging in PHP. Friends who need it can refer to it.

Example, smarty in php generates static pages and pagination codes in articles. Topic: PHP paging code principle

<?php
include "../config.php";
checkLogin ();
if (isset ($_GET['act']) && $_GET['act'] == 'add') {
// var_dump ($_POST);
$title = isset ($_POST['title']) ? trim ($_POST['title']) : '';
$tag = isset ($_POST['tag']) ? trim ($_POST['tag']) : '';
$content = isset ($_POST['content']) ? $_POST['content'] : '';
$create_time = time ();
echo $sql = "INSERT INTO `article` (`title`,`tag`,`content`,`create_time`) VALUES ('{$title}','{$tag}','{$content}','{$create_time}')";
$_POST['create_time'] = $create_time ;
$res=mysql_query ($sql);
$article_id = mysql_insert_id();
$file_name = '../html/'.$article_id.'.html';
if ($res) {

   $temp = explode ('<div style=\"page-break-after: always;\"><span style=\"display: none;\"> </span></div>',$content);
   $num = 0;
   foreach ($temp as $key => $val ) {
    $num++;
    $pagenav = '';
    if ($key == 0) {
     $file_name = '../html/'.$article_id.'.html';
    } else {
     $file_name = '../html/'.$article_id.'_'.($key+1).'.html';
    }
    for ($i=1;$i<=count($temp);$i++)
    {
     if (($key+1) == $i)
     {
      $pagenav .= " <b>{$i}</b> ";
     }
     else
     {
      if ($i == 1)
      {
       $pagenav = $pagenav." {$i} ";

      }
      else
       {
       $pagenav .= " {$i} ";

      }
     }
    }
    $_POST['content'] = $val ;
    $tpl->assign ('a',$_POST);
    $tpl->assign ('pagenav',$pagenav);
    $html = $tpl->fetch('show_article.html');
    $fp=fopen ($file_name,'w');
    if ($fp) {
     fwrite ($fp,$html);
     fclose ($fp);

    }
   }
   alert ("生成{$num}篇成功",'add_article.php');
} else {
   alert ('增加失败!');
}
} else {
//$FCK->Value='fanglor is a boy !';
$editer = $FCK->CreateHtml();
$tpl->assign ('editer',$editer);
$tpl->display ('add_article.html');
}
?>
Copy after login

Related articles for generating static pages:

  • Example of using smarty to generate static files in PHP
  • Key code about smarty template engine generating static pages
  • How to generate static pages in php (three functions)
  • Two ways to generate static files with php
  • How to generate static pages using smarty

Article paginationRelated articles:

  • php long article pagination code sharing
  • PHP long article paging implementation code
  • php article paging implementation code
  • php text article pagination code example
  • php code to implement paging display of long articles


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template