The first: the latest article calls
This is what we use the WordPress program often use, the following is the calling code:
? php $rand _posts = get_posts (' numberposts=8&orderby=post_date '); foreach ($rand _posts as $post):? >
<li><a href= " PHP the_permalink ();? > "title=" PHP the_title ();? > "><"? PHP echo Mb_strimwidth (Get_the_title (), 0, 50, ' ... ');? ></a></li>
? PHP Endforeach;? >
Notice that the red number 8 above is the number of articles that represent the call, which you can adjust yourself. And then 0,50 this is the title of the calling article is displayed as 50 bytes, that is, the article title displays up to 25 words.
The second type: Random article call
This is also our use of WordPress program often used, because this can make your page time is different content, for optimization is a certain advantage, the specific code is as follows:
? php $rand _posts = get_posts (' Numberposts=8&orderby=rand '); foreach ($rand _posts as $post):? >
<li><a href= " PHP the_permalink ();? > "title=" PHP the_title ();? > ">" PHP echo Mb_strimwidth (Get_the_title (), 0, 50, ' ... ');? > </a></li>
? PHP Endforeach;? >
As mentioned above, the red number 8 is the number of articles that represent the call, which you can adjust yourself. And then 0,50 this is the title of the calling article is displayed as 50 bytes, that is, the article title displays up to 25 words.
The Third Kind: the popular article calls
This is believed that we all know, this call may display our website most browses the article, also is the user most concerned article. The following is the calling code:
? PHP $postslist = get_posts (' Numberposts=8&order=desc&orderby=comment_count '); foreach ($postslist as $post):? >
<li><a href= " PHP the_permalink ();? > "title=" PHP the_title ();? > "><"? PHP echo Mb_strimwidth (Get_the_title (), 0, 50, ' ... ');? ></a></li>
? PHP Endforeach;? >
Like the top two, the red number 8 is the number of articles that represent the call, which you can adjust yourself. And then 0,50 this is the title of the calling article is displayed as 50 bytes, that is, the article title displays up to 25 words.
The fourth kind: the Sticky article calls
This everyone is not unfamiliar, this is a lot of sites are useful to, WordPress Top article code is divided into two parts, I will give you a talk here.
? Php
$sticky = get_option (' sticky_posts ');
Rsort ($sticky);
$sticky = Array_slice ($sticky, 0, 5);
Query_posts (Array (' post__in ' => $sticky, ' caller_get_posts ' => 1));
if (Have_posts ()):
while (Have_posts ()): The_post ();
? >
<li><a href= " PHP the_permalink ();? > "title=" PHP the_title ();? > "rel=" Bookmark "><"? PHP the_title ();? ></a></li>
? PHP endwhile; endif;? >
The above code in $sticky, 0, 5 of the 5 represents the number of top article calls, "title=" "rel=" "Bookmark" > represents the call of the article link and title. Note: When you add a sticky article, be sure not to forget the last.
Type fifth: calling the specified category
We 8630.html "> sometimes in the WordPress program when you want to call a certain page of the specified classification, the following code allows you to use WordPress, specify the invocation of a category under the article, the code is as follows:
? PHP query_posts (' cat=15&posts_per_page=8&caller_get_posts=1′); >
? PHP while (have_posts ()): The_post ();? >
<li><a href= " PHP the_permalink ();? > "title=" PHP the_title ();? > ">" PHP echo Mb_strimwidth (Get_the_title (), 0, 50, ' ... ');? > </a></li>
? PHP endwhile;? >
15 of the cat=15 in the above code represents the category ID, and we just need to change the number to its own category ID, and the number 8 represents the number of calls to the article. You can adjust the number of articles you want to show yourself.
This article is from http://www.56dr.com/info/html/jzjy/698.html