欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

ecshop网站底部的帮助的文章用help.php文件打开,而不是article.php打开的方法

shiping 的头像
如果想要底部的帮助和其他的文章模板分开,用不同模板来实现。

那我们单独建立一个文件help.php来调用帮助模板help.dwt的方法显示帮助文章内容。

1.复制artile.php文件重命名为help.php文件,不过里面的有些代码可以删掉。我只保留了一些如下

<?php

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');

if ((DEBUG_MODE & 2) != 2)

{

    $smarty->caching = true;

}

//-- INPUT

$_REQUEST['id'] = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;

$article_id     = $_REQUEST['id'];

if(isset($_REQUEST['cat_id']) && $_REQUEST['cat_id'] < 0)

{

    $article_id = $db->getOne("SELECT article_id FROM " . $ecs->table('article') . " WHERE cat_id = '".intval($_REQUEST['cat_id'])."' ");

}

//-- PROCESSOR

$cache_id = sprintf('%X', crc32($_REQUEST['id'] . '-' . $_CFG['lang']));

if (!$smarty->is_cached('help.dwt', $cache_id))

{

   

    $article = get_article_info($article_id);

    if (empty($article))

    {

        ecs_header("Location: ./\n");

        exit;

    }

    if (!empty($article['link']) && $article['link'] != 'http://' && $article['link'] != 'https://')

    {

        ecs_header("locationarticle[link]\n");

        exit;

    }

    $smarty->assign('categories',       get_categories_tree());  // 分类树

    $smarty->assign('helps',            get_shop_help()); // 网店帮助

    $smarty->assign('id',               $article_id);

    $smarty->assign('username',         $_SESSION['user_name']);

    $smarty->assign('email',            $_SESSION['email']);

    $smarty->assign('type',            '1');

    $smarty->assign('promotion_info', get_promotion_info());

    $smarty->assign('article',      $article);

    $smarty->assign('keywords',     htmlspecialchars($article['keywords']));

    $smarty->assign('descriptions', htmlspecialchars($article['title']));

    $catlist = array();

    foreach(get_article_parent_cats($article['cat_id']) as $k=>$v)

    {

        $catlist[] = $v['cat_id'];

    }

    assign_template('a', $catlist);

    $position = assign_ur_here($article['cat_id'], $article['title']);

    $smarty->assign('page_title',   $position['title']);    // 页面标题
    $smarty->assign('ur_here',      $position['ur_here']);  // 当前位置

    $smarty->assign('comment_type', 1);
 
 
    $next_article = $db->getRow("SELECT article_id, title FROM " .$ecs->table('article'). " WHERE article_id > $article_id AND cat_id=$article[cat_id] AND is_open=1 LIMIT 1");
    if (!empty($next_article))
    {
        $next_article['url'] = build_uri('help', array('aid'=>$next_article['article_id']), $next_article['title']);
        $smarty->assign('next_article', $next_article);
    }

    $prev_aid = $db->getOne("SELECT max(article_id) FROM " . $ecs->table('article') . " WHERE article_id < $article_id AND cat_id=$article[cat_id] AND is_open=1");
    if (!empty($prev_aid))
    {
        $prev_article = $db->getRow("SELECT article_id, title FROM " .$ecs->table('article'). " WHERE article_id = $prev_aid");
        $prev_article['url'] = build_uri('help', array('aid'=>$prev_article['article_id']), $prev_article['title']);
        $smarty->assign('prev_article', $prev_article);
    }


    assign_dynamic('article');

}

    $smarty->display('help.dwt', $cache_id);

//-- PRIVATE FUNCTION

function get_article_info($article_id)

{

   

    $sql = "SELECT a.*, IFNULL(AVG(r.comment_rank), 0) AS comment_rank ".

            "FROM " .$GLOBALS['ecs']->table('article'). " AS a ".

            "LEFT JOIN " .$GLOBALS['ecs']->table('comment'). " AS r ON r.id_value = a.article_id AND comment_type = 1 ".

            "WHERE a.is_open = 1 AND a.article_id = '$article_id' GROUP BY a.article_id";

    $row = $GLOBALS['db']->getRow($sql);

    if ($row !== false)

    {

        $row['add_time']     = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']); // 修正添加时间显示

       

        if (empty($row['author']) || $row['author'] == '_SHOPHELP')

        {

            $row['author'] = $GLOBALS['_CFG']['shop_name'];

        }

    }

    return $row;

}

?>

2.在themes/你的模板文件夹下(要么就默认default文件夹)新建一个文件help.dwt的文件,

这是本人的帮助的模板

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Keywords" content="{$keywords}" />
<meta name="Description" content="{$description}" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>{$page_title}</title>
<!-- TemplateEndEditable --><!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<link rel="shortcut icon" href="favicon.ico" />
<link rel="icon" href="animated_favicon.gif" type="image/gif" />
<link href="{$ecs_css_path}" rel="stylesheet" type="text/css" />
{* 包含脚本文件 *}
{insert_scripts files='common.js'}
<script type="text/javascript" src="js/action.js"></script>
<style>
.ur_here{ width:760px;}
</style>
</head>
<body>
<div class="wapper">
<!-- #BeginLibraryItem "/library/page_header.lbi" --><!-- #EndLibraryItem -->

<div class="block clearfix" style="margin-top:15px;">
 <div id="articleLeft" class="fl">
 <!-- {if $related_goods} -->
 <div class="mod1 mod2 blank" id="articleRelated" style="padding-bottom:10px;">
 <span class="lt"></span><span class="lb"></span><span class="rt"></span><span class="rb"></span>
 <h1 class="mod2tit">{$lang.releate_goods}</h1>
 <div class="mod2con" >
  <!--{foreach from=$related_goods item=releated_goods_data}-->
     <ul class="attribute" >
      <li>
       <a href="{$releated_goods_data.url}" class="fl"><img src="{$releated_goods_data.goods_thumb}" alt="{$releated_goods_data.goods_name}" align="left" /></a>
   <p class="fl" style="width:110px;"> <a href="{$releated_goods_data.url}" title="{$releated_goods_data.goods_name}">{$releated_goods_data.short_name}</a><br />
    <!-- {if $releated_goods_data.promote_price neq 0} -->
    {$lang.promote_price}<b class="f1">{$releated_goods_data.formated_promote_price}</b><br />
    <!-- {else} -->
    {$lang.shop_price}<b class="f1">{$releated_goods_data.shop_price}</b></p>
    <!-- {/if} -->
      </li>
     </ul>
  <!--{/foreach}-->
  </div>
 </div>
 <script type="text/javascript">divheight("articleRelated");</script>
 <!-- {/if} -->
 <!-- TemplateBeginEditable name="右边区域" -->
 <!-- #BeginLibraryItem "/library/helpleft.lbi" --><!-- #EndLibraryItem -->
  <!-- TemplateEndEditable -->
 </div>


  <div id="articleRight" class="fr" >
    <!-- #BeginLibraryItem "/library/ur_here.lbi" --><!-- #EndLibraryItem -->
  <div class="articleBox">
   <h1 class="articleTit tc">{$article.title|escape:html}</h1>
   <div class="author tc">
    {$article.author|escape:html} / {$article.add_time}
    <div class="articleSize">[<a href="javascript:articleSize('16','30')">大</a>] [<a href="javascript:articleSize('14','24')">中</a>] [<a href="javascript:articleSize('12','21')">小</a>]</div>
   </div>
      <div style="border-top: #efefef solid 1px;"><div>
  <!-- {if $article.content } -->
  <div id="article" class="word">
   {$article.content}
  </div>
  <!-- {/if} -->
  {if $article.open_type eq 2 or $article.open_type eq 1}
   <div class="tr"><a href="{$article.file_url}" target="_blank"><u>{$lang.relative_file}</u></a></div>
  {/if}
   <div class="articlePrev">
   <!-- 上一篇文章 -->
   <span style="margin-right:350px;">
              {$lang.next_article}:
     {if $next_article}
     <a href="{$next_article.url}">{$next_article.title}</a>
     {else}
     Empty!
     {/if}
                
            </span>
    <!-- 下一篇文章 -->
             <span style="">
    {$lang.prev_article}:
    {if $prev_article}
    <a href="{$prev_article.url}">{$prev_article.title}</a>
    {else}
     Empty!
    {/if}
             </span>
   </div>
 </div> 

 </div>

</div>
</div>
</div>

<!-- #BeginLibraryItem "/library/help.lbi" --><!-- #EndLibraryItem -->
<!-- #BeginLibraryItem "/library/page_footer.lbi" --><!-- #EndLibraryItem -->
</div>
</body>
</html>


3.在themes/你的模板文件夹(要么就默认default文件夹)/library/目录下新建一个文件helpleft.lbi的文件

代码如下:

<!-- {if $helps} -->

<div class="mod1 mod2 blank" id="historybox">
 <span class="lt"></span><span class="lb"></span><span class="rt"></span><span class="rb"></span>
 <h1 class="mod2tit">帮助中心</h1>
   
   
       <div class="helpleftbox">
    <!-- {foreach from=$helps item=help_cat} -->
   <div class="goodsbox1">
    <div class="helpTit1">{$help_cat.cat_name}</div>
    <div class="helpList1 tl">
    <!-- {foreach from=$help_cat.article item=item} -->
    ·<a href="{$item.url}" title="{$item.title|escape:html}">{$item.short_title}</a><br />
    <!-- {/foreach} -->
    </div>
   </div>
   <!-- {/foreach} --> 
  </div>
       
        <script type="text/javascript">divheight("helpbox");</script> 
       
</div>

<!-- {/if} -->

 

至于模板里面的样式就不写了,根据自己的网站的样式自行修改,只参考有用的标签即可。

 

4.在includes/lib_common.php文件中,找到函数行build_uri(),

在 case 'article':
            if (empty($aid))
            {
                return false;
            }
            else
            {
                $uri = $rewrite ? 'article-' . $aid : 'article.php?id=' . $aid;
            }

            break;

的后面加上下面的一段:
   case 'help':

if (empty($aid))

{

return false;

}

else

{

$uri = $rewrite ? 'help-' . $aid : 'help.php?id=' . $aid;

}

break;

5.在includes/lib_main.php文件中找到函数get_shop_help()

找到下面的这段

$arr[$row['cat_id']]['article'][$key]['url']         = $row['open_type'] != 1 ?
            build_uri('article', array('aid' => $row['article_id']), $row['title']) : trim($row['file_url']);

把它改为:
   $arr[$row['cat_id']]['article'][$key]['url'] = $row['open_type'] != 1 ?

build_uri('help', array('aid' => $row['article_id']), $row['title']) : trim($row['file_url']);

帮助页面展示:

ecshop网站底部的帮助的文章用help.php文件打开,而不是article.php打开的方法
 

 


 

来自  http://blog.sina.com.cn/s/blog_8dc13ec50101awyr.html
普通分类: