zoukankan      html  css  js  c++  java
  • Zencart 调用WordPress文章方法 ,WOZ 插件

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

  • 相关阅读:
    Hrbust-1492 盒子(二分图最大匹配)
    数据结构——二叉树的建立和遍历(递归建树&层序遍历建树)
    HDU 1710 二叉树遍历
    HDU 2891
    HDU 2895 贪心 还是 大水题
    POJ 2896 另解暴力
    POJ 2896 AC自动机 or 暴力
    HDU 1714 math
    POJ 1328 贪心
    POJ 2109 巧妙解法
  • 原文地址:https://www.cnblogs.com/lookyou/p/2118940.html
Copyright © 2011-2022 走看看