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

Incoming search terms:

  • wordpress文章调用
  • ZEN CART WORDPRESS
  • zencart wordpress
  • wordpress 文章调用
  • wordpress cart
  • zen cart调用wordpress
  • zen cart调用 wordpress文章插件
  • zen cart 调用 wordpress
  • zen cart 文章
  • zen cart 加 wordpress

Related posts:

  1. Zencart 调用WordPress最新文章
 

9 Comments

  1. Replacement Dell PA-12 Laptop AC Power Adapter
    Dell PA-10 AC Adapter
    Original Toshiba ADP-65DB Laptop AC Adapter
    Toshiba PA-1650-02 laptop ac adapter
    Toshiba PA-1650-01 65W Laptop AC Adapter
    Toshiba ADP-65DB 65W Laptop AC Adapter
    Toshiba SADP-65KB 65W Laptop AC Adapter
    HP 394224-001 90W Laptop AC Adapter
    65W HP 402018-001 AC power adapter
    70W Dell PA-6 AC Power Adapter

  2. 文章不错,介绍很仔细

  3. 我很喜欢这个网,很多SEO的内容资料,谢谢共享,
    SEO

  4. 很多SEO的内容资料, 我很喜欢这个网,,谢谢
    SEO

  5. Yes, probably so it is

  6. 有点没看太懂,不过特有兴趣,唉,我的悟性啊,博主见笑了。

  7. 正须要这个,谢谢了~

  8. 雪中送炭啊!

发表评论

注意: 评论者允许使用'@user空格'的方式将自己的评论通知另外评论者。例如, ABC是本文的评论者之一,则使用'@ABC '(不包括单引号)将会自动将您的评论发送给ABC。使用'@all ',将会将评论发送给之前所有其它评论者。请务必注意user必须和评论者名相匹配(大小写一致)。