WordPress Two development: Outside the station in the form of HTML call WordPress article

Source: Internet
Author: User

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

Small V in helping customers develop WordPress site often encounter a variety of requirements, this time to help a customer development project, customer requirements to help him develop the site of the article can be called in other sites, and to the form of HTML to call can not use JS, said to do sprocket or something. No way the customer is God, continue to toss chant. Below the implementation method, first in the WordPress root directory to create a new html_post.php file, remember is the need to call out the WordPress site of the article. The code for the html_post.php file is as follows:

Define (' Wp_use_themes ', false);

Require ('./wp-load.php ');

Query_posts (' showposts=10&orderby=new ');

/** Charset=utf-8 "Prevent garbled * * *

< meta http-equiv= "Content-type" content= "HTML; Charset=utf-8 "/>

< PHP while (Have_posts ()): The_post ();? >

< li > < a title= "<? php the_title ();? > "href=" < php the_permalink ();? > "target=" _blank > < php the_title ();? > < a > < li >

  

This makes it possible to call the latest 10 articles in the Web, showposts=10 the number you want to call the article. Let me give you a detailed explanation of how to modify the code to reach the call you want to invoke the effect of the article.

1. What if I want to invoke the latest article in a category?

In fact this is very easy to implement only need to modify the query_posts this parameter, for example, I specify to call the category ID is 1 then the code becomes:

Define (' Wp_use_themes ', false);

Require ('./wp-load.php ');

/** If you want to call multiple categories at the same time separate half-width characters like cat=1,2,3,4 * *

Query_posts (' showposts=10&orderby=new&cat=1 ');

? >

/** Charset=utf-8 "Prevent garbled * * *

< meta http-equiv= "Content-type" content= "HTML; Charset=utf-8 "/>

< PHP while (Have_posts ()): The_post ();? >

< li > < a title= "<? php the_title ();? > "href=" "target=" _blank "> < php the_title ();? > < a > < li >

< PHP endwhile >

2, if I want to call the whole station Wenzhan but only to block a category under the article?

< PHP

Define (' Wp_use_themes ', false);

Require ('./wp-load.php ');

/** if you want to shield multiple categories at once, separate them with half-width characters such as Cat=-1,-2,-3,-4 * *

Query_posts (' showposts=10&orderby=new&cat=-1 ');

? >

/** Charset=utf-8 "Prevent garbled * * *

< meta http-equiv= "Content-type" content= "HTML; Charset=utf-8 "/>

< PHP while (Have_posts ()): The_post ();?>

< li > < a title= "href=" "target=" _blank "> <? php the_title ();? > < a > < li >

< PHP endwhile >

3. What if I want to call a random article?

< PHP

Define (' Wp_use_themes ', false);

Require ('./wp-load.php ');

/** if you want to shield multiple categories at once, separate them with half-width characters such as Cat=-1,-2,-3,-4 * *

Query_posts (' Showposts=10&orderby=rang ');

?>

/** Charset=utf-8 "Prevent garbled * * *

< meta http-equiv= "Content-type" content= "HTML; Charset=utf-8 "/>

< PHP while (Have_posts ()): The_post ();? >

< li > < a title= "href=" "target=" _blank "> <? PHP the_ title ()? > < a > < li >

< PHP endwhile?>

4. What if I want to output a summary?

< PHP

Define (' Wp_use_themes ', false);

Require ('./wp-load.php ');

/** if you want to shield multiple categories at once, separate them with half-width characters such as Cat=-1,-2,-3,-4 * *

Query_posts (' Showposts=10&orderby=rang ');

? >

/** Charset=utf-8 "Prevent garbled * * *

< meta http-equiv= "Content-type" content= "HTML; Charset=utf-8 "/>

< PHP while (Have_posts ()): The_post ();? >

< li > < a title= "<? php the_title ();? > "href=" "target=" _blank "> < php the_title ();? > < a >

< php echo mb_strimwidth (strip_tags apply_filters (' the_content ', $post->post_content)), 0, "...", ' utf-8 ') ; ? > < L i >

< PHP endwhile?>

Almost forgot ~ below small V to say how to call outside the station ~

< PHP

The code is placed where you want to invoke the content and list of the article

$url =http://your site address/html_post.php;

Echo file_get_contents ($url);

? >

OK, that's it. Tune out of the article are pure HTML ~ not what JS Oh, very friendly to SEO. In addition to small V hint: The method described above must be in the call site to support the case of PHP is feasible, if the call site support ASP need to read html_post.php PHP code with ASP rewrite, but if it is static space can only use JS to call slightly.

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.