Wordpress secondary development: wordpress articles are called in HTML form outside the site

Source: Internet
Author: User

Small V often encounters various requirements when helping a customer develop a wordpress site. This time, when helping a customer develop a project, the customer asks that the articles on the site he developed can be called on other websites, in addition, JavaScript cannot be called in the form of HTML. There is no way the customer is God. Continue to make the effort. The implementation method is as follows. First, create an html_post.php file in the wordpress root directory. Remember to call the wordpress site of the article externally. 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 gibberish */

<Meta http-equiv = "Content-Type" content = "text/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>

  

In this way, you can call the latest 10 articles on the website. The number showposts = 10 can be changed to the number of articles you want to call. Next, I will explain how to modify the code to call the article you want to call.

1. If I want to call the latest article under a certain category, how can I implement it?

In fact, this is easy to implement. You only need to modify the query_posts parameter. For example, if the ID of the class to be called is 1, the Code becomes:

Define ('wp _ USE_THEMES ', false );

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

/** If you want to call multiple classes at the same time, separate them with halfwidth characters, for example, cat = */

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

? >

/** Charset = UTF-8 "Prevent gibberish */

<Meta http-equiv = "Content-Type" content = "text/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. What if I want to call the dynamic route for CDN to answer questions but only block articles under a certain category?

<? Php

Define ('wp _ USE_THEMES ', false );

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

/** If you want to block multiple categories at the same time, separate them with halfwidth characters, for example, cat =-1,-2,-3,-4 */

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

? >

/** Charset = UTF-8 "Prevent gibberish */

<Meta http-equiv = "Content-Type" content = "text/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 block multiple categories at the same time, separate them with halfwidth characters, for example, cat =-1,-2,-3,-4 */

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

?>

/** Charset = UTF-8 "Prevent gibberish */

<Meta http-equiv = "Content-Type" content = "text/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 the abstract?

<? Php

Define ('wp _ USE_THEMES ', false );

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

/** If you want to block multiple categories at the same time, separate them with halfwidth characters, for example, cat =-1,-2,-3,-4 */

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

? >

/** Charset = UTF-8 "Prevent gibberish */

<Meta http-equiv = "Content-Type" content = "text/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,200, "...", 'utf-8 ');? > </L I>

<? Php endwhile;?>

I almost forgot ~ Next, let's talk about how to call it out of the station ~

<? Php

// Place the Code where you need to call the article content and list

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

Echo file_get_contents ($ url );

? >

OK. All the compiled articles are HTML-only ~ It's not a js. It's very SEO friendly. In addition, Tips V: the methods described above must be feasible only when the site is called to support php, if the calling site supports asp, rewrite the PHP code that reads html_post.php with ASP. However, if it is a static space, it can only be called using js.

Related Article

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.