Phpcms 的使用

什么是web服务器?它是做什么的?

  1. 通过工具打开 WAMP 的 www directory
  2. 将原有的东西拷贝出去 清空此目录 把要分享的项目拷贝进来 保障有index.html(直接就在目录下)
  3. 通过工具 start all server
  4. www directory 会被分享出去
  5. 别人如何访问?
  6. 通过ipconfig找到自己的ip地址
  7. 别人在浏览器中输入192.168.x.y
  8. 自己如何访问?
  9. 127.0.0.0 或者 localhost 都代表了自己的ip地址 通过他们都可以访问

什么是动态网站?什么是静态网站?

  • 192.168.3.40/

  • 192.168.3.40/index.html

  • 192.168.3.40/index.php

请求同一个资源得到的永远是相同的东西称为静态

请求同一个资源会根据情况的不同得到不同的东西称为动态

phpcms 安装流程

  1. 解压得到两个文件夹
  2. redeme可以删掉(不用)
  3. 拷贝install_package 下 所有的内容
  4. 拷贝 到 www directory 打开服务器 分享出去
  5. 自己访问localhost (/index.html) «««««««
  6. 按照引导一直点击下一步
  7. (全新安装) ( root 空密码留空 1@2.com)
  8. phpcms phpcms // localhost/amdin.php

三个重要的地址

  • localhost/admin.php
  • localhost/index.php
  • localhost/phpmyadmin

两个重要的目录

  1. www/phpcms/tmplates/default/content/
  2. www/statics/ -css/ -images/ -js/

几个重要的变量

  • {CSS_PATH}
  • {JS_PATH}
  • {IMG_PATH}

管理页面中的链接

  1. 创建模型
  2. 创建category_xxx.html list_xxx.html show_xxx.html
  3. 模型的名字 模型的数据表名 创建模型的时候选择模版
  4. 新建栏目 模型选择刚创建的 (记得更新栏目缓存)
  5. 管理内容 点击栏目名字左侧的+号 给这个栏目下添加列表内容
  6. 转入代码
  7. 在header.html中把所有的一级栏目读取出来 带上链接
  8. 在list_xxx.html中把这个栏目下的列表简略内容读取出来
  9. 在show_xxx.html中把列表中的具体内容读取出来

第7步代码

{pc:content action="category" catid="0"}
{php print_r($data)} <<<<<<<<< 这行是调试代码
<ul>
{loop $data $r}
  <li>
    <a href="$r['url']">
      <span>{$r['catname']}</span>
    </a>
  </li>
{/loop}
</ul>
{/pc}

第八步代码

{pc:content action="lists" catid=$catid}
<ul>
{loop $data $r}
<li>
<a href="$r['url']">
  <span>{$r['title']}</span>
</a>
</li>
{/loop}
</ul>
{/pc}

第九步代码

<span>{$content}</span>

常用代码


  {loop subcat(12) $k $v}{/loop}  快速遍历子栏目

  {php }  添加一段php代码

  {str_cut($r[title],56,'...')}  截取字符串

  {str_cut(strip_tags($v[description]), 150)}  截取字符串

  {thumb($v[thumb],90,60)}  控制图片大小

  {date('Y-m-d H:i:s',$r[inputtime])}  设置时间输出格式

  {siteurl($siteid)}  返回到首页的链接

  {catpos($catid)}  生成面包屑html

  {template "content","header"} 引入另一个文件

  <!--if语法 和全局的SEO变量-->
  {if $n==1}class="on" style="margin:0"{/if}  用if输出类名
  {if isset($SEO['title']) && !empty($SEO['title'])}
    {$SEO['title']}
  {/if}
  {$SEO['site_title']}
  {$SEO['keyword']}
  {$SEO['description']}


  <!--文件路径-->
  {CSS_PATH}
  {JS_PATH}
  {IMG_PATH}


  <!--show.html页面中可以直接使用的变量(部分)实质上可以使用数据表中的任何一个字段-->
  {$title}
  {$content}
  {$inputtime}
  {$copyfrom}



  <!-- 利用CATEGORYS的一些方式-->
  {$CAT[]}  取本栏目相关信息
  {$CATEGORYES[][]}  从本栏目开始取其他栏目相关信息
  {$CATEGORYS[$CAT[parentid]][catname]}  父栏目名称
  {$CATEGORYS[$CAT[parentid]][url]} 父栏目链接
  {$CATEGORYS[$CATEGORYS[$CAT[parentid]][parentid]][catname]}  上上级栏目名称
  {$CATEGORYS[$CATEGORYS[$CAT[parentid]][parentid]][url]}  上上级栏目链接

  <!--获取推荐位下的内容列表-->
  {pc:content  action="position" posid="9" order="id DESC ASC" num="10" cache="3600" return="test" page="$page"}
    {loop $test $r}
       {if $num%2==0}{/if}
    {/loop}
  {/pc}
  {$pages} 分页html字符串

  <!--获取某个栏目下的所有子栏目-->
  {pc:content action="category" catid="$parentid" num="12" siteid="$siteid" order="listorder ASC"}
  {loop $data $r}
  <li><a href="{$r[url]}">{$r[catname]}</a></li>
  {/loop}
  {/pc}

  <!-- 获取某个栏目下的所有内容并分页-->
  {pc:content action="lists" catid="$catid" num="25" order="id DESC" page="$page"}
  {loop $data $r}
  	<li><span class="rt">{date('Y-m-d H:i:s',$r[inputtime])}</span>·<a href="{$r[url]}" target="_blank"{title_style($r[style])}>{$r[title]}</a></li>
  	{if $n%5==0}<li class="bk20 hr"></li>{/if}
  {/loop}
  <div id="pages" class="text-c">{$pages}</div>

   <!--遍历数据中的某个数组-->
  {loop $photos $r}
  <li><a href="{$r[url]}"><img src="{thumb($r[url], 75, 45, 0)}" alt="{$r[alt]}" /></a></li>
  {/loop}


  <!--快速遍历输出该栏目下的子栏目-->
  {loop $arrchild_arr $cid}
    <li{if $catid==$cid} class="cur"{/if}><a href="{$CATEGORYS[$cid][url]}">{$CATEGORYS[$cid][catname]}</a></li>
  {/loop}


  <!--show页面的上一篇和下一篇-->
  <p class="f14">
    <strong>上一篇:</strong><a href="{$previous_page[url]}">{$previous_page[title]}</a><br />
    <strong>下一篇:</strong><a href="{$next_page[url]}">{$next_page[title]}</a>
  </p>

  <!--获取点击次数-->
  <span id="hits"></span>
  <script src="{APP_PATH}api.php?op=count&id={$id}&modelid={$modelid}"></script>

  <!--使用sql语句-->
  {pc:get sql="SELECT * FROM phpcms_member" cache="3600" page="$page"  return="data"}
  <ul>
    {loop $data $key $val}
    {$val[username]}
    {/loop}
  </ul>
  {$pages}
  {/pc}



一些常见的问题处理

在任何页面都可以使用 {pc}{/pc}

  • index.html $catid = 0;
  • header.html $catid = ?; {template “content”,x}
  • footer.html $catid = ?; {template “content”,x}
  • cebianlan.html $catid = ?; {template “content”,x}

在这些页面取栏目

  • {pc:content action=”category” catid=0}{/pc}
  • {pc:content action=”category” catid=12}{/pc} (12这个栏目可以后台操作不显示在导航)

在这些页面取栏目下的内容

  • {pc:content action=”lists” catid = 5}{/pc}

  • category_*.html $catid = 使用了这个模型的栏目的id
  • (如果一个栏目有子栏目,点击栏目链接会来到category)
  • list_*.html $catid = 使用了这个模型的栏目的id
  • (如果一个栏目下面再没有子栏目,点击链接会来到list)
  • show_*.html $catid = 使用了这个模型的栏目的id
  • (每个栏目下用action=”lists”读出来的内容的链接,都是指向对应栏目的show_*.html)
  • page_*.html $catid = 使用了这个单页的栏目的id
  • (所有单网页的链接都是指向各自的page_*.html)

查找v9_category那张表中parendid 为 x 的栏目

  • {pc:content action=”category” catid=x}{/pc}

查找v9_模型那里那张数据表 中 catid 为 x 的条目

  • {pc:content action=”lists” catid=x}{/pc}

  • 栏目划分的一般方法

    首页 一般不作为栏目添加(直接写在html页面中)

    新闻动态 (尽量使用新闻模型,让下面的子栏目使用同一模型)

    • 校内新闻 (新闻模型)

    • 国际新闻 (新闻模型)

    • 国内新闻 (新闻模型)

    • 新闻发布规则 (单网页)

    • bbc (外链)

    招聘信息(在首页中是动态的,但是没出现在导航中)

    使用招聘模型把招聘信息作为一个栏目

    (!!!!设置该栏目不在导航显示)

    catid = 89;

    {pc:content action=’lists’ catid=89}{/pc} 去获取这个隐藏栏目下的内容

    关于我们(其下都是单页)

    新建关于我们 (单页) -> page_a.html

    • 公司简介 -> page_a.html

    • 董事长简介 -> page_b.html