天下博览模块修改教程之一 |
||||
---|---|---|---|---|
新进会员
注册日期:
2006/9/3 11:33 所属群组:
注册会员 等级: 2; EXP: 12
HP: 0 / 28 MP: 3 / 348 |
很多人来EMAIL问我,说你的网站的天下博览模块是怎么修改的,一直没有时间给他们回复。今天又有位兄弟来信问我,他们的热情让我非常感动,头脑发热,突然决定写个教程来告诉大家。
我的网站是“神州生活网”,网址是www.szlife.cn。大家可以看我的天下博览模块的效果,要看就抓紧看。最近我准备利用XOOPS 2.0.18版本,对其进行大规模修改,修改得让其符合中国特色,呵呵。 天下博览是用于RSS聚合的模块,好象是D.J.开发的,非常好的一个模块(真的很佩服D.J.,有时间大家认识下),就是有点不大符合中国特色,为什么呢?大家一看http://www.szlife.cn/modules/planet/,就知道了,关键是它抓取了RSS新闻后,只是简单的显示了一个列表,而我们大家的想法是:需要把它分门别类的显示给大家看!!! 怎么办?自己动手修改它! 既然我们的目标很明确了(把它分门别类的显示给大家看)。那么就开始吧。好久没有搞XOOPS了(快有一年了吧),有点忘了,呵呵。 首先为了保持模块的独立性,同时为了日后方便升级,我就把他单独做为一个模块来开发。写到这里,突然发现要教大家如何开发XOOPS模块,那简直是个三峡工程,工程量巨大啊。所以关于如何开发模块,请大家看这个网站上的相关文章,不清楚的话,可以问我,如果我有时间的话,会尽量回答。记得刚开始用XOOPS时,也是发帖在这个网站问,但没什么人回答(估计一是大家都很忙,为了生存嘛,二是很多技术问题不是一句两句能说清楚的),只好自己看源代码,那个辛苦啊,呜!!! 解决方案很简单,其实只要做出一个显示天下博览的页面(比如“娱乐”),其他的象“军事”等,只要把该页面拷贝修改下参数就可以了。 大家先来看下军事页面http://www.szlife.cn/modules/home/junshi.php,它的源代码如下(junshi.php): <?php include("header.php"); $xoopsOption["xoops_pagetitle"] = "军事"; $xoopsOption['template_main'] = 'home_junshi.html'; $xoopsOption["xoops_module_header"] = "<link rel=\"stylesheet\" type=\"text/css\" href=\"" .XOOPS_URL."/modules/home/templates/home.css"."\" />"; $xoopsOption['show_rblock'] =1; include(XOOPS_ROOT_PATH."/header.php"); $xoopsTpl -> assign("xoops_pagetitle", $xoopsOption["xoops_pagetitle"]); $xoopsTpl -> assign("xoops_module_header", $xoopsOption["xoops_module_header"]); $article_handler =& xoops_getmodulehandler("article", "planet"); $articles_1 = & $article_handler->getByBlogID_mark(4, 10, 42); $articles_2 = & $article_handler->getByBlogID_mark(33, 10, 42); $articles_top_1 = array_slice($articles_1, 0, 2); $articles_bottom_1 = array_slice($articles_1,2); $articles_top_2 = array_slice($articles_2, 0, 2); $articles_bottom_2 = array_slice($articles_2,2); $xoopsTpl -> assign("articles_top_1", $articles_top_1); $xoopsTpl -> assign("articles_bottom_1", $articles_bottom_1); $xoopsTpl -> assign("articles_top_2", $articles_top_2); $xoopsTpl -> assign("articles_bottom_2", $articles_bottom_2); $xoopsTpl -> assign("dirname", XOOPS_URL."/modules/planet"); $xoopsTpl -> assign("home_dirname", XOOPS_URL."/modules/home"); include("footer.php"); ?> 已经半夜了,未完待续;
2008/1/23 0:03
|
|||
|
回复: 天下博览模块修改教程之一 |
||||
---|---|---|---|---|
新进会员
注册日期:
2007/12/22 23:32 所属群组:
注册会员
帖子:
14
等级: 2; EXP: 50
HP: 0 / 37 MP: 4 / 321 |
sf
正需 顶起 望继续
2008/1/23 13:04
|
|||
|
回复: 天下博览模块修改教程之一 |
||||
---|---|---|---|---|
资深会员
注册日期:
2007/3/16 22:40 所属群组:
注册会员
帖子:
271
等级: 15; EXP: 40
HP: 0 / 360 MP: 90 / 3882 |
无私的高人,强烈支持!!!
感谢分享
2008/1/23 13:33
|
|||
|
天下博览模块修改教程之二 |
||||
---|---|---|---|---|
新进会员
注册日期:
2006/9/3 11:33 所属群组:
注册会员 等级: 2; EXP: 12
HP: 0 / 28 MP: 3 / 348 |
为方便大家,就不再另开帖子了,本教程都在本帖中发布。如果大家有何不清楚的地方,请跟帖,我会回答的。
我现在开始讲解junshi.php源代码 <?php //包含头文件 include("header.php"); header.php文件源代码很短: <?php include("../../mainfile.php"); include("include/functions.php"); ?> 就是把头文件给包含过来,mainfile.php文件内容我就不再解释了。 其中include/functions.php文件源代码如下,主要用于定义URL分割符: <?php //mark1937 if(!defined("PLANET_URL_DELIMITER")) { define("PLANET_URL_DELIMITER", "/"); } ?> 接着往下看junshi.php代码, //定义页面标题 $xoopsOption["xoops_pagetitle"] = "军事"; //定义模板页面 $xoopsOption['template_main'] = 'home_junshi.html'; 模板home_junshi.html代码为(大家可上http://www.szlife.cn/modules/home/junshi.php对照来看,为方便讲解,我的说明就直接写在下面代码中,用圆刮号表示): <!-- 层 --> <div class="home_area"> <div class="home_col1"> <div class="home_menuB"> <span class="home_tit1">军事</span> <span class="home_tit_right"><a href="<{$dirname}>/index.php/b4(这里b4代表分类是4,也就是军事在数据库中的ID号)" target="_blank">[更多...]</a></span> </div> <div class="home_contentALeft"> <img src="<{$home_dirname}>/images/junshi.gif"/>(军事栏目左上边的图片) </div> <div class="home_contentARight">(军事栏目右上边的文章链接,列了两个文章) <{foreach item=article from=$articles_top_1(注意这里的$articles_top_1,下面会讲到)}> <span class="home_content_span"> ·<a href="<{$dirname}>/view.article.php<{$smarty.const.PLANET_URL_DELIMITER}><{$article.id}>/b<{$article.blog.id}(具体文章的ID)>" title="<{$article.title}>" target="_blank"><{$article.title}>(具体文章的标题)</a> </span><br/> <{/foreach}> </div> <div class="home_contentB">(军事栏目下边的文章链接,列了8个文章) <{foreach item=article from=$articles_bottom_1}>(注意这里的$articles_bottom_1,下面会讲到) <span class="home_content_span"> ·<a href="<{$dirname}>/view.article.php<{$smarty.const.PLANET_URL_DELIMITER}><{$article.id}>/b<{$article.blog.id}>" title="<{$article.title}>" target="_blank"><{$article.title}></a> </span><br/> <{/foreach}> </div> </div> (以下是其他分类,代码和上面是一样的) <div class="home_col2"> <div class="home_menuB"> <span class="home_tit1">历史</span> <span class="home_tit_right"><a href="<{$dirname}>/index.php/b33" target="_blank">[更多...]</a></span> </div> <div class="home_contentALeft"> <img src="<{$home_dirname}>/images/lishi.gif"/> </div> <div class="home_contentARight"> <{foreach item=article from=$articles_top_2}> <span class="home_content_span"> ·<a href="<{$dirname}>/view.article.php<{$smarty.const.PLANET_URL_DELIMITER}><{$article.id}>/b<{$article.blog.id}>" title="<{$article.title}>" target="_blank"><{$article.title}></a> </span><br/> <{/foreach}> </div> <div class="home_contentB"> <{foreach item=article from=$articles_bottom_2}> <span class="home_content_span"> ·<a href="<{$dirname}>/view.article.php<{$smarty.const.PLANET_URL_DELIMITER}><{$article.id}>/b<{$article.blog.id}>" title="<{$article.title}>" target="_blank"><{$article.title}></a> </span><br/> <{/foreach}> </div> </div> </div> <div class="blankDiv"></div> --------------------------------------------------------- 回过头来,继续看junshi.php代码, //链接CSS样式 $xoopsOption["xoops_module_header"] = "<link rel=\"stylesheet\" type=\"text/css\" href=\"" .XOOPS_URL."/modules/home/templates/home.css"."\" />"; $xoopsOption['show_rblock'] =1; include(XOOPS_ROOT_PATH."/header.php"); //输出页标题 $xoopsTpl -> assign("xoops_pagetitle", $xoopsOption["xoops_pagetitle"]); //输出模块头 $xoopsTpl -> assign("xoops_module_header", $xoopsOption["xoops_module_header"]); //下面到了关键部分了 //首先获取模块处理对象 $article_handler =& xoops_getmodulehandler("article", "planet"); //读取军事的文章列表 $articles_1 = & $article_handler->getByBlogID_mark(4, 10, 42); //读取历史的文章列表 $articles_2 = & $article_handler->getByBlogID_mark(33, 10, 42); //注意下面的$articles_top_1就是上面模板文件home_junshi.html中提到的 $articles_top_1 = array_slice($articles_1, 0, 2); $articles_bottom_1 = array_slice($articles_1,2); $articles_top_2 = array_slice($articles_2, 0, 2); $articles_bottom_2 = array_slice($articles_2,2); 手写酸了,未完待续。
2008/1/23 23:12
|
|||
|
回复: 天下博览模块修改教程之一 |
||||
---|---|---|---|---|
Support Team
注册日期:
2006/11/30 20:48 来自 beijing
所属群组:
网站管理员 注册会员 Dev+Hack 资料整理组 等级: 29; EXP: 19
HP: 140 / 704 MP: 368 / 8200 |
home是什么模块?
2008/1/24 3:19
|
|||
|
回复: 天下博览模块修改教程之一 |
||||
---|---|---|---|---|
高级会员
注册日期:
2007/11/13 14:52 所属群组:
注册会员
帖子:
116
等级: 9; EXP: 79
HP: 0 / 219 MP: 38 / 1946 |
期待继续。
2008/1/24 9:48
|
|||
|
回复: 天下博览模块修改教程之一 |
||||
---|---|---|---|---|
资深会员
注册日期:
2007/3/16 22:40 所属群组:
注册会员
帖子:
271
等级: 15; EXP: 40
HP: 0 / 360 MP: 90 / 3882 |
望mark1937多辛苦一下,能够继续把教程写完。
2008/4/19 14:50
|
|||
|