Home > zencart > Zen-cart 调用WordPress文章方法

Zen-cart 调用WordPress文章方法

08:20|分类: zencart
close

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文章

<?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; ?>

三、调用最新留言

该代码直接调用数据库显示一份最新留言。其中LIMIT 10限制留言显示数量。红色部份则是每条留言的输出样式。

<?php
global $wpdb;
$sql = “SELECT DISTINCT ID, post_title, post_password, comment_ID,
comment_post_ID, comment_author, comment_date_gmt, comment_approved,
comment_type,comment_author_url,
SUBSTRING(comment_content,1,30) AS com_excerpt
FROM $wpdb->comments
LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID =
$wpdb->posts.ID)
WHERE comment_approved = ‘1′ AND comment_type = ” AND
post_password = ”
ORDER BY comment_date_gmt DESC
LIMIT 10″;
$comments = $wpdb->get_results($sql);
$output = $pre_html;

foreach ($comments as $comment) {
$output .= “\n<li>”.strip_tags($comment->comment_author)
.”:” . ” <a href=\”” . get_permalink($comment->ID) .
“#comment-” . $comment->comment_ID . “\” title=\”on ” .
$comment->post_title . “\”>” . strip_tags($comment->com_excerpt)
.”</a></li>”;
}

$output .= $post_HTML;
echo $output;?>

本博相关日志

声明: 本站遵循 署名-非商业性使用 3.0 共享协议. 转载请注明转自 外贸乐
close
你的位置:首页 >> zencart |你可以:↑回到顶部↑ |添加书签 |返回上页

本文地址:http://www.waimaole.com/zen-cart-wordpress.html
如果你喜欢本文,欢迎订阅 我的博客。



10 条评论 to “Zen-cart 调用WordPress文章方法”

你可以发表一条评论 或者 引用 本文
  1. arickzhu 说:

    文章中的那几个get_函数要自己写啊,WordPress中好像没有。

  2. alex 说:

    你好,站长, 我想把 随机调用Blog文章 放到左栏, 请问有什么方法可以实现, 我把那代码放到 安装的 blank sidebox 插件里面,然后可以正常显示, 但是客户一下单CHECK OUT 就页面出现问题, 只剩下左栏跑到了页面中间,产品全部消失 , 目前没有解决方法, 请问怎么实现BLOG文章放到左栏.. 谢谢!

  3. anspt 说:

    你好,我按你说的方法

    调用文章,可是调出来的文章的地址是www.****.com/?p=16一点就跑到主页
    可是实际上文章的地址应该是www.***. com/?main_page=wordpress&p=16
    有显示文章题目,可是地址不对什么办?
    谢谢!

  4. lucas 说:

    我也碰到楼下同样的情况 google也有收录.com/?p=11这样的URL 也有收录/?main_page=wordpress&p=16这种页面。但是。com/?p= 这种页面点去就跑到主页去了。怎么办? 站长?

  5. wedding dress 说:

    根据站长的提示,已经成功的随机调用文章了,可能有些地方还要调整下,继续研究中

发表评论

Hi, I know you have something to tell me. Please leave me a reply.

«

你已输入0字符。