Several calling methods used in WordPress

Source: Internet
Author: User

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

The recent tension using WordPress program toss two sets of templates, for the WordPress program also played for several months, for its some of the methods of call also understand some. Today this article is to tell you a few commonly used methods of WordPress calls.

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, ' ... ');?></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, ' ... ');?> </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, ' ... ');?></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?>

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, ' ... ');?> </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.

The above five kinds of WordPress call method, is also the tension itself in the WordPress program to do when the station is often used, hope to help everyone! This article by the tension http://zhangliseo.com original writing, reproduced please specify the Web site, thank you!

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.