网络营销电子商务研究中心

网络营销电子商务研究中心 (https://www.0058.net/index.php)
-   ZenCart (https://www.0058.net/forumdisplay.php?f=69)
-   -   Zen-cart 调用Wordpress文章方法 (https://www.0058.net/showthread.php?t=5843)

Mahanoy City 2016-08-17 04:37 PM

Zen-cart 调用Wordpress文章方法
 
Zen-cart 有个WOZ的插件,作用就是调用Wordpress 的文章,将这个作为新闻系统来用。
其实,通过Wordpress自带的函数调用,完全可以达到同样的作用,下面介绍两种方法,一种是调用最新的文章;另一种是随机调用Blog文章。
首先,把WordPress安装到zen-cart一个子目录里,设置好固定连接等

一、调用最新文章
在合适的地方加入下面两行代码,一般会放在产品页面(/includes/templates/你使用的模板文件名/templates/tpl_product_info_display.php
<?php require('./wordpress所在目录/wp-blog-header.php'); ?> 这行调用WordPress自带函数,目录地址要随着WordPress安装目录变化而变化.如果你的Zen-cart不是根目录,那么前面就要打两个.['../wordpress所在目录/wp-blog-header.php']
<?php get_archives('postbypost', 10); ?> 这里的10指调用的最新文章数量

二、随机调用Blog文章
随机调用4篇Blog文章
<?php require('./wordpress所在目录/wp-blog-header.php'); ?>
<?php
$rand_posts = get_posts('numberposts=4&orderby=rand');
foreach( $rand_posts as $post ) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>


All times are GMT +8. The time now is 01:42 PM.

Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.