Zen-cart calls WordPress Article method, Woz plug-in

Source: Internet
Author: User
Tags install wordpress

Zen-cart has a Woz plug-in that calls WordPress's Article and uses it as a news system.
In fact, function calls provided by WordPress can achieve the same purpose. The following describes three methods: the first method is to call the latest article, and the second method is to call blog articles randomly; the third is to call the latest message.
first, install Wordpress in a sub-directory of Zen-cart, set a fixed connection and so on
1. Call the latest article
Add the following two lines of code to the appropriate place , it is usually placed on the product page (/templates/the template file name you are using/templates/tpl_product_info_display.php
This line calls the WordPress built-in function, and the Directory address changes with the WordPress installation directory. if your Zen-cart is not the root directory, you need to create two. ['.. /WordPress directory/wp-blog-header.php ']
10 here refers to the number of latest articles called

Ii. randomly call blog articles
<? PHP require ('./WordPress directory/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;?>

3. Call the latest message

the Code directly calls the database and displays the latest message. Here, limit 10 limits the number of messages displayed. The red part is the output style of each message.
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;?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.