Summary of some methods of wordpress call in the latest article

Source: Internet
Author: User
Tags php foreach wordpress blog

Method 1

You can use a simple template tag wp_get_archvies to call the latest WordPress article. The code is as follows:

The code is as follows: Copy code
<? Php get_archives ('postbypost', 10);?> (Display 10 latest articles)
Or
<? Php wp_get_archives ('Type = postbypost & limit = 20 & format = m m');?>

The following code shows the latest 20 articles in your blog. format = custom is used to customize the display style of the article list. For specific parameters and usage instructions, refer to the official instructions-wp_get_archvies. (Fromat = custom or not. By default, the article title is displayed in the UL list .)

Supplement: The query_posts () function of WP can also call the latest article list. Although the code is a little more, it can better control the display of the Loop. For example, you can set whether to display the summary. For more information, see the official instructions.

Method 2
Call the latest article: (just put the following code at the position you want to render)

The code is as follows: Copy code
<? Php
$ Limit = get_option ('posts _ per_page ');
$ Paged = (get_query_var ('paged '))? Get_query_var ('paged'): 1;
Query_posts ('showposts = '. $ limit = 7.' & paged = '. $ paged );
$ Wp_query-> is_archive = true; $ wp_query-> is_home = false;
?>
<? Php while (have_posts (): the_post (); if (! ($ First_post ==$ post-> ID):?>
<Ul>
<Li> <a href = "<? Php the_permalink ()?>" Rel = "bookmark" title = "Permanent Link to <? Php the_title_attribute ();?> ">
<? Php the_title ();?> </A> </li>
</Ul>
<? Php endif; endwhile;?>

Method 3 call the latest article:

The code is as follows: Copy code
<Ul>
<? Php $ post_query = new WP_Query ('showposts = 10 & prime ;);
While ($ post_query-> have_posts (): $ post_query-> the_post ();
$ Do_not_duplicate = $ post-> ID;?>
<Li> <a href = "<? Php the_permalink ();?> "> <? Php the_title ();?> </A> </li>
<? Php endwhile;?>
</Ul>

Fourth Method call latest article:

The code is as follows: Copy code
<Ul>
<? Php $ result = $ wpdb-> get_results ("select id, post_title FROM $ wpdb-> posts where post_status = 'Publish 'and post_type = 'post' order by id desc limit 0, 10 & Prime ;);
Foreach ($ result as $ post ){
Setup_postdata ($ post );
$ Postid = $ post-> ID;
$ Title = $ post-> post_title;
?>
<Li> <a href = "<? Php echo get_permalink ($ postid) ;?>" Title = "<? Php echo $ title?> "> <? Php echo $ title?> </A> </li>
<? Php }?>
</Ul>

You can display the list of the latest articles in a certain part of the wordpress blog at will, you can define the number of display items at will, if you know a little program, you can simply modify and call random articles and other effects.

The code is as follows: Copy code

1. <div class = "newest">
2. 3. <? Php $ pop = $ wpdb-> get_results ("SELECT id, post_title FROM {$ wpdb-> prefix} posts WHERE post_type = 'post' AND post_status = 'Publish 'AND post_password = ''AND comment_count = 0 order by post_date desc LIMIT 5 "); ?>
4. <ul>
5. <? Php foreach ($ pop as $ post):?>
6. <li> <span class = "news"> </span> <a href = "<? Php the_permalink ()?> "Rel =" bookmark "title =" read more <? Php the_title ();?> "> <? Php echo cut_str ($ post-> post_title, 64);?> </A> </li>
7. <? Php endforeach;?>
8. </ul>
9. </div>

If you want to call a random article, you can

The code is as follows: Copy code

Order by post_date desc

Change

Order by rand ()

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.