Ecshop如何调用WordPress?

这里给大家介绍一下Ecshop与Wordpress共用一个数据库时,在首页调用Wordpress内容的方法。
第一步:在Ecshop根目录找到index.php文件,在113行插入如下代码:

$smarty->assign(‘new_wordpress’,    index_get_new_wordpress());   // wordpress

如图:ecwd1

第二步:在文件中写一个从数据库调出来Wrodpress 文章表内容的函数,如图:

image

代码如下:
function index_get_new_wordpress()
{
    $sql = “SELECT  ID, post_title, guid FROM bixingorgwp_posts where post_status=’publish’ ORDER BY ID DESC LIMIT 0, 11″;        
    $res = $GLOBALS[‘db’]->getAll($sql);

    $arr = array();
    foreach ($res AS $idx => $row)
    {
        $arr[$idx][‘id’]          = $row[‘ID’];
        $arr[$idx][‘title’]  = $row[‘post_title’];
        $arr[$idx][‘url’]           = $row[‘guid’];
    }

    return $arr;
}

第三步:在Ecshop模板中调用文章内容,代码如下:

<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″>
<DIV class=CommonPanel  id=”ECS_CARTINFO”><!– –>
<DIV  class=CommonPanelHeader><H3 class=CommonPanelTitle>博文交流</H3></DIV>
<DIV class=CommonPanelBody>
<UL class=CommonPanelList id=CategoriesList>
<ul>
<!–{foreach from=$new_wordpress item=wordpress}–>
<li>
<a href=”{$wordpress.url}” title=”{$wordpress.title|escape:html}” target=”_blank
” class=”STYLE1″>{$wordpress.title|truncate:13}</a>   
</li><!–{/foreach}–>
</ul>
</UL>
</DIV>
</DIV>

如图:
ecwd2

最后一步,在首页index.dwt 文件中插入模板文件,如图:

ecwd3

代码为:<!– #BeginLibraryItem “/library/ads_left_bottom.lbi” –><!– #EndLibraryItem –>

好了完成,访问首页看看效果。

ecwd4

在网站:http://www.bixing.org/ 左侧:博文交流板块,大家可以看看效果。

此条目发表在 Ecshop 分类目录,贴了 标签。将固定链接加入收藏夹。

Ecshop如何调用WordPress?》有 6 条评论

  1. SwedaySteeple 说:

    都可以

  2. hxg810329 说:

    你好,请教一下,如果在这样的网站架构中(ECSHOP+WORDPRESS),访问这两个不同程序页面,是需要注册两个会员帐号,还是注册一个帐号就可以通用了?

  3. hxg810329 说:

    请问如何让同一个会员名登陆两个不同程序的页面呢/

发表评论