案例效果展示:





































代码实现:

1.在ecshop后台找到文章管理->文章分类->添加文章分类,添加一个顶级分类,叫做“合作单位”,并且让其显示在导航栏。如下图:

































1.在ecshop后台找到文章管理->文章列表->添加新文章。(文章标题:八维研修学院;文章分类:合作单位;文章重要性:普通;是否显示:是,等等一些东西完善了)如下图:












3.在ecshop/languages/zh_cn/admin/article.PHP(56行)添加:

$_LANG['baidu_map'] = '百度地图';

4.在ecshop/admin/templates/article_info.htm第11行添加:

<span class="tab-back" id="baidu-tab">{$lang.baidu_map}</span>

ecshop后台文章管理->文章列表->编辑文章内容,可以看到导航标签多了一个百度地图

5.在ecshop/admin/templates/article_info.htm第18行添加

  1. <table width="90%" id="baidu-table" style="display: none">
  2. <tr>
  3. <td class="narrow-label">{$lang.baidu_map_info}</td>
  4. <td><input type="text" name="point_x" size ="20" maxlength="30" value="{$article.point_x|escape}" />,<input type="text" name="point_y" size ="20" maxlength="30" value="{$article.point_y|escape}" />{$lang.require_field}</td>
  5. </tr>
  6. </table>

6.在ecs.article表中添加两个字段:point_x、point_y,都是varchar类型

7.在ecshop/admin/article.php里面搜索“插入数据”,在$sql = "INSERT INTO ".$ecs->table('article')."(title, cat_id, article_type, is_open, author, "."author_email, keywords, content, add_time, file_url, open_type, link, description后面添加“,point_x,point_y”。

添加后:

  1. $sql = "INSERT INTO ".$ecs->table('article')."(title, cat_id, article_type, is_open, author, "."author_email, keywords, content, add_time, file_url, open_type, link, description,point_x,point_y) "."VALUES ('$_POST[title]', '$_POST[article_cat]', '$_POST[article_type]', '$_POST[is_open]', "."'$_POST[author]', '$_POST[author_email]', '$_POST[keywords]', '$_POST[FCKeditor1]', "."'$add_time', '$file_url', '$open_type', '$_POST[link_url]', '$_POST[description]','$_POST[point_x]','$_POST[point_y]')";
  2. $db->query($sql);

8.在ecshop/admin/article.php第287行添加point_x = '$_POST[point_x]',point_y = '$_POST[point_y]'

添加后

  1. if ($exc->edit("title='$_POST[title]', cat_id='$_POST[article_cat]', article_type='$_POST[article_type]', is_open='$_POST[is_open]', author='$_POST[author]', author_email='$_POST[author_email]', keywords ='$_POST[keywords]', file_url ='$file_url', open_type='$open_type', content='$_POST[FCKeditor1]', link='$_POST[link_url]', description = '$_POST[description]',point_x = '$_POST[point_x]',point_y = '$_POST[point_y]'", $_POST['id']))

9.在百度地图坐标文本框输入:116.306358;40.049285

10.在ecshop/article.php第125行添加:
  1. if($article['cat_id']==15){
  2. $smarty->display('article_company.dwt', $cache_id);
  3. }else{
  4. $smarty->display('article.dwt', $cache_id);
  5. }

这个是前台article.php的所有代码看情况而定(可不写)
  1. <?php
  2. /**
  3. * ECSHOP 文章内容
  4. * ============================================================================
  5. * * 版权所有 2005-2012 上海商派网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.ecshop.com;
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * $Author: liubo $
  12. * $Id: article.php 17217 2011-01-19 06:29:08Z liubo $
  13. */
  14. define('IN_ECS', true);
  15. require(dirname(__FILE__) . '/includes/init.php');
  16. if ((DEBUG_MODE & 2) != 2)
  17. {
  18. $smarty->caching = true;
  19. }
  20. /*------------------------------------------------------ */
  21. //-- INPUT
  22. /*------------------------------------------------------ */
  23. $_REQUEST['id'] = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
  24. $article_id     = $_REQUEST['id'];
  25. if(isset($_REQUEST['cat_id']) && $_REQUEST['cat_id'] < 0)
  26. {
  27. $article_id = $db->getOne("SELECT article_id FROM " . $ecs->table('article') . " WHERE cat_id = '".intval($_REQUEST['cat_id'])."' ");
  28. }
  29. /*------------------------------------------------------ */
  30. //-- PROCESSOR
  31. /*------------------------------------------------------ */
  32. $cache_id = sprintf('%X', crc32($_REQUEST['id'] . '-' . $_CFG['lang']));
  33. if (!$smarty->is_cached('article.dwt', $cache_id))
  34. {
  35. /* 文章详情 */
  36. $article = get_article_info($article_id);
  37. if (empty($article))
  38. {
  39. ecs_header("Location: ./\n");
  40. exit;
  41. }
  42. if (!empty($article['link']) && $article['link'] != 'http://' && $article['link'] != 'https://')
  43. {
  44. ecs_header("location:$article[link]\n");
  45. exit;
  46. }
  47. $smarty->assign('article_categories',   article_categories_tree($article_id)); //文章分类树
  48. $smarty->assign('categories',       get_categories_tree());  // 分类树
  49. $smarty->assign('helps',            get_shop_help()); // 网店帮助
  50. $smarty->assign('top_goods',        get_top10());    // 销售排行
  51. $smarty->assign('best_goods',       get_recommend_goods('best'));       // 推荐商品
  52. $smarty->assign('new_goods',        get_recommend_goods('new'));        // 最新商品
  53. $smarty->assign('hot_goods',        get_recommend_goods('hot'));        // 热点文章
  54. $smarty->assign('promotion_goods',  get_promote_goods());    // 特价商品
  55. $smarty->assign('related_goods',    article_related_goods($_REQUEST['id']));  // 特价商品
  56. $smarty->assign('id',               $article_id);
  57. $smarty->assign('username',         $_SESSION['user_name']);
  58. $smarty->assign('email',            $_SESSION['email']);
  59. $smarty->assign('type',            '1');
  60. $smarty->assign('promotion_info', get_promotion_info());
  61. /* 验证码相关设置 */
  62. if ((intval($_CFG['captcha']) & CAPTCHA_COMMENT) && gd_version() > 0)
  63. {
  64. $smarty->assign('enabled_captcha', 1);
  65. $smarty->assign('rand',            mt_rand());
  66. }
  67. $smarty->assign('article',      $article);
  68. $smarty->assign('keywords',     htmlspecialchars($article['keywords']));
  69. $smarty->assign('description', htmlspecialchars($article['description']));
  70. $catlist = array();
  71. foreach(get_article_parent_cats($article['cat_id']) as $k=>$v)
  72. {
  73. $catlist[] = $v['cat_id'];
  74. }
  75. assign_template('a', $catlist);
  76. $position = assign_ur_here($article['cat_id'], $article['title']);
  77. $smarty->assign('page_title',   $position['title']);    // 页面标题
  78. $smarty->assign('ur_here',      $position['ur_here']);  // 当前位置
  79. $smarty->assign('comment_type', 1);
  80. /* 相关商品 */
  81. $sql = "SELECT a.goods_id, g.goods_name " .
  82. "FROM " . $ecs->table('goods_article') . " AS a, " . $ecs->table('goods') . " AS g " .
  83. "WHERE a.goods_id = g.goods_id " .
  84. "AND a.article_id = '$_REQUEST[id]' ";
  85. $smarty->assign('goods_list', $db->getAll($sql));
  86. /* 上一篇下一篇文章 */
  87. $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");
  88. if (!empty($next_article))
  89. {
  90. $next_article['url'] = build_uri('article', array('aid'=>$next_article['article_id']), $next_article['title']);
  91. $smarty->assign('next_article', $next_article);
  92. }
  93. $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");
  94. if (!empty($prev_aid))
  95. {
  96. $prev_article = $db->getRow("SELECT article_id, title FROM " .$ecs->table('article'). " WHERE article_id = $prev_aid");
  97. $prev_article['url'] = build_uri('article', array('aid'=>$prev_article['article_id']), $prev_article['title']);
  98. $smarty->assign('prev_article', $prev_article);
  99. }
  100. assign_dynamic('article');
  101. }
  102. if(isset($article) && $article['cat_id'] > 2)
  103. {
  104. if($article['cat_id']==15){
  105. $smarty->display('article_company.dwt', $cache_id);
  106. }else{
  107. $smarty->display('article.dwt', $cache_id);
  108. }
  109. }
  110. else
  111. {
  112. $smarty->display('article_pro.dwt', $cache_id);
  113. }
  114. /*------------------------------------------------------ */
  115. //-- PRIVATE FUNCTION
  116. /*------------------------------------------------------ */
  117. /**
  118. * 获得指定的文章的详细信息
  119. *
  120. * @access  private
  121. * @param   integer     $article_id
  122. * @return  array
  123. */
  124. function get_article_info($article_id)
  125. {
  126. /* 获得文章的信息 */
  127. $sql = "SELECT a.*, IFNULL(AVG(r.comment_rank), 0) AS comment_rank ".
  128. "FROM " .$GLOBALS['ecs']->table('article'). " AS a ".
  129. "LEFT JOIN " .$GLOBALS['ecs']->table('comment'). " AS r ON r.id_value = a.article_id AND comment_type = 1 ".
  130. "WHERE a.is_open = 1 AND a.article_id = '$article_id' GROUP BY a.article_id";
  131. $row = $GLOBALS['db']->getRow($sql);
  132. if ($row !== false)
  133. {
  134. $row['comment_rank'] = ceil($row['comment_rank']);                              // 用户评论级别取整
  135. $row['add_time']     = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']); // 修正添加时间显示
  136. /* 作者信息如果为空,则用网站名称替换 */
  137. if (empty($row['author']) || $row['author'] == '_SHOPHELP')
  138. {
  139. $row['author'] = $GLOBALS['_CFG']['shop_name'];
  140. }
  141. }
  142. return $row;
  143. }
  144. /**
  145. * 获得文章关联的商品
  146. *
  147. * @access  public
  148. * @param   integer $id
  149. * @return  array
  150. */
  151. function article_related_goods($id)
  152. {
  153. $sql = 'SELECT g.goods_id, g.goods_name, g.goods_thumb, g.goods_img, g.shop_price AS org_price, ' .
  154. "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
  155. 'g.market_price, g.promote_price, g.promote_start_date, g.promote_end_date ' .
  156. 'FROM ' . $GLOBALS['ecs']->table('goods_article') . ' ga ' .
  157. 'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = ga.goods_id ' .
  158. "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
  159. "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
  160. "WHERE ga.article_id = '$id' AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0";
  161. $res = $GLOBALS['db']->query($sql);
  162. $arr = array();
  163. while ($row = $GLOBALS['db']->fetchRow($res))
  164. {
  165. $arr[$row['goods_id']]['goods_id']      = $row['goods_id'];
  166. $arr[$row['goods_id']]['goods_name']    = $row['goods_name'];
  167. $arr[$row['goods_id']]['short_name']   = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
  168. sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
  169. $arr[$row['goods_id']]['goods_thumb']   = get_image_path($row['goods_id'], $row['goods_thumb'], true);
  170. $arr[$row['goods_id']]['goods_img']     = get_image_path($row['goods_id'], $row['goods_img']);
  171. $arr[$row['goods_id']]['market_price']  = price_format($row['market_price']);
  172. $arr[$row['goods_id']]['shop_price']    = price_format($row['shop_price']);
  173. $arr[$row['goods_id']]['url']           = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
  174. if ($row['promote_price'] > 0)
  175. {
  176. $arr[$row['goods_id']]['promote_price'] = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
  177. $arr[$row['goods_id']]['formated_promote_price'] = price_format($arr[$row['goods_id']]['promote_price']);
  178. }
  179. else
  180. {
  181. $arr[$row['goods_id']]['promote_price'] = 0;
  182. }
  183. }
  184. return $arr;
  185. }
  186. ?>






































11.在\ecshop\themes\default里面复制article_pro.dwt改名为article_company.dwt

12.把下面一段话放在article_company.dwt第14行
  1. <style type="text/css">
  2. #allmap{width:100%;height:500px;}
  3. </style>
  4. <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=nXezGCeI80ZZK2IsGWDWPMgS"></script>

13.把<div id="allmap"></div>放在article_company.dwt第38行

14.在article_company.dwt第39行放一下一段代码:

  1. <script type="text/javascript">
  2. // 百度地图API功能
  3. var sContent =
  4. "<h4 style='margin:0 0 5px 0;padding:0.2em 0'>{$article.title|escape:html}</h4>" +
  5. "<img style='float:right;margin:4px' id='imgDemo' src='{$article.file_url}' width='139' height='104' title='{$article.title|escape:html}'/>" +
  6. "<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'>{$article.description}</p>" +
  7. "</div>";
  8. var map = new BMap.Map("allmap");
  9. var point = new BMap.Point({$article.point_x},{$article.point_y});
  10. var marker = new BMap.Marker(point);
  11. var infoWindow = new BMap.InfoWindow(sContent);  // 创建信息窗口对象
  12. map.centerAndZoom(point, 15);
  13. map.addOverlay(marker);
  14. marker.addEventListener("click", function(){
  15. this.openInfoWindow(infoWindow);
  16. //图片加载完毕重绘infowindow
  17. document.getElementById('imgDemo').onload = function (){
  18. infoWindow.redraw();   //防止在网速较慢,图片未加载时,生成的信息框高度比图片的总高度小,导致图片部分被隐藏
  19. }
  20. });
  21. </script>

page_header.lbi中修改
  1. {insert_scripts files='common.js,utils.js'}

ecshop二次开发之百度地图的更多相关文章

  1. ECSHOP二次开发指南

    ECSHOP二次开发指南 发布时间:2013-05-28 12:47:00   来源:   评论:0 点击: 次 [字号:大 中 小] QQ空间新浪微博腾讯微博人人网豆瓣网百度空间百度搜藏开心网复制更 ...

  2. ecshop二次开发 给商品添加自定义字段

    说起自定义字段,我想很多的朋友像我一样会想起一些开源的CMS(比如Dedecms.Phpcms.帝国)等,他们是可以在后台直接添加自定义字段的. 抱着这种想法我在Ecshop的后台一顿找,不过肿么都木 ...

  3. EcShop二次开发系列教程–总纲

    EcShop作为老牌的B2C独立网店系统,功能非常全名,强大的文件.数据库缓存机制,保证前后台系统执行速度更快.系统平稳运行.但是过多的功能也或多或少的会影响到系统的整个效率,所有在使用EcShop搭 ...

  4. ecshop二次开发之购物车常见问题

    1.ecshop二次开发中保存注册用户购物车数据解决方法:ecshop购物车是数据库中cart表来支持的,在ecshop表中rec_id是编号,user_id是注册用户的id,session_id表示 ...

  5. Ecshop二次开发必备基础

    EcShop二次开发学习方法 近年来,随着互联网的发展,电子商务也跟着一起成长,B2B,C2C,B2C的电子商务模式也不断的成熟.这时催生出了众多电子商务相关的PHP开源产品.B2C方面有Ecshop ...

  6. EcShop二次开发学习方法和Ecshop二次开发必备基础

    ecshop二次开发学习方法 近年来,随着互联网的发展,电子商务也跟着一起成长,B2B,C2C,B2C的电子商务模式也不断的成熟.这时催生出了众多电子商务相关的php开源产品.B2C方面有Ecshop ...

  7. web开发调用百度地图API + AK申请

    web开发调用百度地图API + AK申请 要使用百度地图的API我们首先需要在我们的html页面引入js----`` 如何获取百度地图ak: 1.登陆百度地图开发者平台 2.注册百度开发者账号并登陆 ...

  8. ECShop二次开发指南(一)

    ECSHOP是一套完整的网络商店解决方案,包括前台的商品展示.购物流程和强大易用的后台管理.由于 ecshop简单易用,使用者几乎可以在3几分钟简单的设置一下就可以拥有一个网上商店系统,所以很多的B2 ...

  9. EcShop二次开发学习方法

    EcShop二次开发学习方法 (2012-03-08 11:10:08) 转载▼ 标签: 京东 公用函数库 二次开发 sql语言 数据库设计 杂谈 分类: ecshop 近年来,随着互联网的发展,电子 ...

随机推荐

  1. topology进程结束会不会关闭数据库连接

    测试环境:redhat,oracle 11.2.0.3.0 测试目标:当java进程关闭之后,进程的数据库连接会不会被释放,何时被释放 实验证明:在运行topology前,执行 select coun ...

  2. Vuejs之Component slot 插槽详解

    Vuejs的component的数据进行了沙箱隔离,除js全局变量如Math, Date之类外无法访问用户自定义的变量,所以使用component写组件或嵌套组件时明白变量的访问非常重要 编译作用域 ...

  3. SVN 环境搭建

    安装配置 安装环境 #查看系统版本环境 [root@svn ~]# cat /etc/redhat-release CentOS release 6.7 (Final) [root@svn ~]# u ...

  4. Java面试总结-基础篇2

    1. mvn的dependency-management dependency-management是声明依赖,不实际引入,主要用于在父依赖中统一各依赖的版本,否则,各个子模块在引用同一依赖时,难免会 ...

  5. PAT甲级——A1026 Table Tennis

    A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For a ...

  6. Cocos2dx 3.0 过渡篇(二十八)C++11强类型枚举

    一朋友在微信朋友圈晒了张照片,随手点开大图,带着赞赏的眼光扫了下,恩,几个月不见.又美丽了...咦?等等,她戴的这是什么?酷炫的造型! 金属边框! 微型摄像头! 这不是传说中的谷歌眼镜么?土豪啊,还好 ...

  7. 2018-8-14-Resharper-如何把类里的类移动到其他文件

    title author date CreateTime categories Resharper 如何把类里的类移动到其他文件 lindexi 2018-08-14 17:34:39 +0800 2 ...

  8. springmvc:请求参数绑定集合类型

    一.请求参数绑定实体类 domain: private String username; private String password; private Double money; private ...

  9. POJ 2533 最小上升子序列

    D - POJ 2533 经典DP-最长上升子序列 A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let th ...

  10. Leetcode434.Number of Segments in a String字符串中的单词数

    统计字符串中的单词个数,这里的单词指的是连续的不是空格的字符. 请注意,你可以假定字符串里不包括任何不可打印的字符. 示例: 输入: "Hello, my name is John" ...