本文作者:心月

phpcmsv9移動端頁面靜態化實現方法——模板修改

心月IT博客 2019-05-09
摘要:移動端url規則 欄目頁url規則:m {$catdir} index html|m {$catdir} p{$page} html示例:m news p2 html 內容頁url規則:m {$catdir} {$id} html|m {$catdir} {$id}_{$page} html示例:m news 1_2 html 移動端url規則的目的是讓所有的移動端頁面都生成在 m 文件夾下。

1、添加靜態頁規則

pc端url規則
欄目頁url規則:{$catdir}/index.html|{$catdir}/p{$page}.html示例:news/p2.html
內容頁url規則:{$catdir}/{$id}.html|{$catdir}/{$id}_{$page}.html示例:news/1_2.html
移動端url規則
欄目頁url規則:m/{$catdir}/index.html|m/{$catdir}/p{$page}.html示例:m/news/p2.html
內容頁url規則:m/{$catdir}/{$id}.html|m/{$catdir}/{$id}_{$page}.html示例:m/news/1_2.html

移動端url規則的目的是讓所有的移動端頁面都生成在 m 文件夾下。


2、模板修改

在添加欄目和欄目修改的編輯頁面中添加移動端欄目頁url規則和移動端內容頁url規則

①欄目模板修改

    a.添加欄目模板

模板文件位置:phpcms/models/admin/templates/category_add.tpl.php 

大約在 163 行左右

需要添加的內容為<!--m start--> <!--m end--> 之間的代碼內容。

   <tr>
      <th><?php echo L('show_urlrules');?>:</th>
      <td><div id="show_php_ruleid" style="display:<?php if($setting['content_ishtml']) echo 'none';?>">
	  <?php
		echo form::urlrule('content','show',0,$setting['category_ruleid'],'name="show_php_ruleid"');
	?>
	</div>
	<div id="show_html_ruleid" style="display:<?php if(!$setting['content_ishtml']) echo 'none';?>">
	  <?php	
		echo form::urlrule('content','show',1,$setting['category_ruleid'],'name="show_html_ruleid"');
	?>
	</div>
	</td>
    </tr>
<!--m start-->
    <tr>
      <th width="200"><?php echo L('m_html_category');?>:</th>
      <td>
	  <input type='radio' name='setting[m_ishtml]' value='1' <?php if($setting['m_ishtml']) echo 'checked';?> onClick="$('#m_category_php_ruleid').css('display','none');$('#m_category_html_ruleid').css('display','');"> <?php echo L('yes');?>&nbsp;&nbsp;&nbsp;&nbsp;
	  <input type='radio' name='setting[m_ishtml]' value='0' <?php if(!$setting['m_ishtml']) echo 'checked';?>  onClick="$('#m_category_php_ruleid').css('display','');$('#m_category_html_ruleid').css('display','none');"> <?php echo L('no');?>
	  </td>
    </tr>
	<tr>
      <th><?php echo L('m_html_show');?>:</th>
      <td>
	  <input type='radio' name='setting[m_content_ishtml]' value='1' <?php if($setting['m_content_ishtml']) echo 'checked';?> onClick="$('#m_show_php_ruleid').css('display','none');$('#m_show_html_ruleid').css('display','')"> <?php echo L('yes');?>&nbsp;&nbsp;&nbsp;&nbsp;
	  <input type='radio' name='setting[m_content_ishtml]' value='0' <?php if(!$setting['m_content_ishtml']) echo 'checked';?>  onClick="$('#m_show_php_ruleid').css('display','');$('#m_show_html_ruleid').css('display','none')"> <?php echo L('no');?>
	  </td>
    </tr>
	<tr>
      <th><?php echo L('m_category_urlrules');?>:</th>
      <td><div id="m_category_php_ruleid" style="display:<?php if($setting['m_ishtml']) echo 'none';?>">
	<?php
		echo form::urlrule('content','category',0,$setting['m_category_ruleid'],'name="m_category_php_ruleid"');
	?>
	</div>
	<div id="m_category_html_ruleid" style="display:<?php if(!$setting['m_ishtml']) echo 'none';?>">
	<?php
		echo form::urlrule('content','category',1,$setting['m_category_ruleid'],'name="m_category_html_ruleid"');
	?>
	</div>
	</td>
    </tr>
	
	<tr>
      <th><?php echo L('m_show_urlrules');?>:</th>
      <td><div id="m_show_php_ruleid" style="display:<?php if($setting['m_content_ishtml']) echo 'none';?>">
	  <?php
		echo form::urlrule('content','show',0,$setting['m_category_ruleid'],'name="m_show_php_ruleid"');
	?>
	</div>
	<div id="m_show_html_ruleid" style="display:<?php if(!$setting['m_content_ishtml']) echo 'none';?>">
	  <?php	
		echo form::urlrule('content','show',1,$setting['m_category_ruleid'],'name="m_show_html_ruleid"');
	?>
	</div>
	</td>
    </tr>
    <!--m end-->

    b.修改欄目模板

模板文件位置:phpcms/models/admin/templates/category_edit.tpl.php

大概在153行左右

需要添加的內容同樣為<!--m start--> <!--m end--> 之間的代碼內容。

    <tr>
      <th><?php echo L('show_urlrules');?>:</th>
      <td><div id="show_php_ruleid" style="display:<?php if($setting['content_ishtml']) echo 'none';?>">
	  <?php
		echo form::urlrule('content','show',0,$setting['show_ruleid'],'name="show_php_ruleid"');
	?>
	</div>
	<div id="show_html_ruleid" style="display:<?php if(!$setting['content_ishtml']) echo 'none';?>">
	  <?php	
		echo form::urlrule('content','show',1,$setting['show_ruleid'],'name="show_html_ruleid"');
	?>
	</div>
	</td>
    </tr>
<!--m start-->
    <tr>
      <th width="200"><?php echo L('m_html_category');?>:</th>
      <td>
	  <input type='radio' name='setting[m_ishtml]' value='1' <?php if($setting['m_ishtml']) echo 'checked';?> onClick="$('#m_category_php_ruleid').css('display','none');$('#m_category_html_ruleid').css('display','');"> <?php echo L('yes');?>&nbsp;&nbsp;&nbsp;&nbsp;
	  <input type='radio' name='setting[m_ishtml]' value='0' <?php if(!$setting['m_ishtml']) echo 'checked';?>  onClick="$('#m_category_php_ruleid').css('display','');$('#m_category_html_ruleid').css('display','none');"> <?php echo L('no');?>
	  </td>
    </tr>
	<tr>
      <th><?php echo L('m_html_show');?>:</th>
      <td>
	  <input type='radio' name='setting[m_content_ishtml]' value='1' <?php if($setting['m_content_ishtml']) echo 'checked';?> onClick="$('#m_show_php_ruleid').css('display','none');$('#m_show_html_ruleid').css('display','')"> <?php echo L('yes');?>&nbsp;&nbsp;&nbsp;&nbsp;
	  <input type='radio' name='setting[m_content_ishtml]' value='0' <?php if(!$setting['m_content_ishtml']) echo 'checked';?>  onClick="$('#m_show_php_ruleid').css('display','');$('#m_show_html_ruleid').css('display','none')"> <?php echo L('no');?>
	  </td>
    </tr>
	<tr>
      <th><?php echo L('m_category_urlrules');?>:</th>
      <td><div id="m_category_php_ruleid" style="display:<?php if($setting['m_ishtml']) echo 'none';?>">
	<?php
		echo form::urlrule('content','category',0,$setting['m_category_ruleid'],'name="m_category_php_ruleid"');
	?>
	</div>
	<div id="m_category_html_ruleid" style="display:<?php if(!$setting['m_ishtml']) echo 'none';?>">
	<?php
		echo form::urlrule('content','category',1,$setting['m_category_ruleid'],'name="m_category_html_ruleid"');
	?>
	</div>
	</td>
    </tr>
	
	<tr>
      <th><?php echo L('m_show_urlrules');?>:</th>
      <td><div id="m_show_php_ruleid" style="display:<?php if($setting['m_content_ishtml']) echo 'none';?>">
	  <?php
		echo form::urlrule('content','show',0,$setting['m_show_ruleid'],'name="m_show_php_ruleid"');
	?>
	</div>
	<div id="m_show_html_ruleid" style="display:<?php if(!$setting['m_content_ishtml']) echo 'none';?>">
	  <?php	
		echo form::urlrule('content','show',1,$setting['m_show_ruleid'],'name="m_show_html_ruleid"');
	?>
	</div>
	</td>
    </tr>
    <!--m end-->

②單頁面模板

    a.單頁面添加模板

模板文件位置:phpcms/models/admin/templates/category_page_add.tpl.php

大概在106行左右

需要添加的內容同樣為<!--m start--> <!--m end--> 之間的代碼內容。

    <tr>
      <th><?php echo L('urlrule_url');?>:</th>
      <td><div id="category_php_ruleid" style="display:<?php if($setting['ishtml']) echo 'none';?>">
	<?php
		echo form::urlrule('content','category',0,$setting['category_ruleid'],'name="category_php_ruleid"');
	?>
	</div>
	<div id="category_html_ruleid" style="display:<?php if(!$setting['ishtml']) echo 'none';?>">
	<?php
		echo form::urlrule('content','category',1,$setting['category_ruleid'],'name="category_html_ruleid"');
	?>
	</div>
	</td>
    </tr>
    <!--m start-->
    <tr>
        <th width="200"><?php echo L('m_html_category');?>:</th>
        <td>
            <input type='radio' name='setting[m_ishtml]' value='1' <?php if($setting['m_ishtml']) echo 'checked';?> onClick="$('#m_category_php_ruleid').css('display','none');$('#m_category_html_ruleid').css('display','')"> <?php echo L('yes');?>&nbsp;&nbsp;&nbsp;&nbsp;
            <input type='radio' name='setting[m_ishtml]' value='0' <?php if(!$setting['m_ishtml']) echo 'checked';?>  onClick="$('#m_category_php_ruleid').css('display','');$('#m_category_html_ruleid').css('display','none')"> <?php echo L('no');?>
        </td>
    </tr>

    <tr>
        <th><?php echo L('m_urlrule_url');?>:</th>
        <td><div id="m_category_php_ruleid" style="display:<?php if($setting['ishtml']) echo 'none';?>">
                <?php
                echo form::urlrule('content','category',0,$setting['m_category_ruleid'],'name="m_category_php_ruleid"');
                ?>
            </div>
            <div id="category_html_ruleid" style="display:<?php if(!$setting['ishtml']) echo 'none';?>">
                <?php
                echo form::urlrule('content','category',1,$setting['m_category_ruleid'],'name="m_category_html_ruleid"');
                ?>
            </div>
        </td>
    </tr>
    <!--m end-->

    b.單頁面修改模板

模板文件位置:phpcms/models/admin/templates/category_page_edit.tpl.php

大概在92行左右

需要添加的內容同樣為<!--m start--> <!--m end--> 之間的代碼內容。

    <tr>
      <th><?php echo L('urlrule_url');?>:</th>
      <td><div id="category_php_ruleid" style="display:<?php if($setting['ishtml']) echo 'none';?>">
	<?php
		echo form::urlrule('content','category',0,$setting['category_ruleid'],'name="category_php_ruleid"');
	?>
	</div>
	<div id="category_html_ruleid" style="display:<?php if(!$setting['ishtml']) echo 'none';?>">
	<?php
		echo form::urlrule('content','category',1,$setting['category_ruleid'],'name="category_html_ruleid"');
	?>
	</div>
	</td>
    </tr>
    <!--m start-->
    <tr>
        <th width="200"><?php echo L('m_html_category');?>:</th>
        <td>
            <input type='radio' name='setting[m_ishtml]' value='1' <?php if($setting['m_ishtml']) echo 'checked';?> onClick="$('#m_category_php_ruleid').css('display','none');$('#m_category_html_ruleid').css('display','')"> <?php echo L('yes');?>&nbsp;&nbsp;&nbsp;&nbsp;
            <input type='radio' name='setting[m_ishtml]' value='0' <?php if(!$setting['m_ishtml']) echo 'checked';?>  onClick="$('#m_category_php_ruleid').css('display','');$('#m_category_html_ruleid').css('display','none')"> <?php echo L('no');?>
        </td>
    </tr>

    <tr>
        <th><?php echo L('urlrule_url');?>:</th>
        <td><div id="m_category_php_ruleid" style="display:<?php if($setting['m_ishtml']) echo 'none';?>">
                <?php
                echo form::urlrule('content','category',0,$setting['m_category_ruleid'],'name="m_category_php_ruleid"');
                ?>
            </div>
            <div id="m_category_html_ruleid" style="display:<?php if(!$setting['m_ishtml']) echo 'none';?>">
                <?php
                echo form::urlrule('content','category',1,$setting['m_category_ruleid'],'name="m_category_html_ruleid"');
                ?>
            </div>
        </td>
    </tr>
    <!--m end-->


處理好的效果圖:(別忘了添加語言包,不然會出現英文)

欄目頁添加效果圖

欄目頁添加效果圖


單頁面添加效果圖

單頁面添加效果圖


    這一步只是完成模板的操作,接下來要處理model中的相關方法,然后才能實現給欄目同時設置移動端url規則。移動端頁面靜態化的具體實現方法請參考《phpcmsv9移動端頁面靜態化實現方法——功能實現

文章版權及轉載聲明:

作者:心月 本文地址:http://www.eojird.tw/cms/266.html發布于 2019-07-01
文章轉載或復制請以超鏈接形式并注明出處心月IT博客

分享到:
贊(

發表評論

快捷輸入:

    評論列表 (有 0 條評論,人圍觀)參與討論