WordPress page Function Code call Daquan

Source: Internet
Author: User
Tags escape quotes php foreach wordpress blog wordpress version

WordPress template basic file

Style.css style sheet File
Index. php homepage File
Single. php log single page file
Page. PHP page file
Archvie. php classification and date archiving page files
Searchform. php search form files
Search. php search for yemian files
Comments. php message region file (including message list and message box)
404. php 404 error page
Header. php webpage header file
Sidebar. php webpage sidebar File
Footer. php webpage bottom File

WordPress Header

<? PHP bloginfo ('name');?> Website title
<? PHP wp_title ();?> Log or page title
<? PHP bloginfo ('stylesheet _ url');?> The relative address of style.css in the wordpresstheme Sample Table File
<? PHP bloginfo ('pingback _ url');?> Pingback address of Wordpress blog
<? PHP bloginfo ('template _ url');?> Relative address of the WordPress topic File
<? PHP bloginfo ('version');?> Wordpress version of the blog
<? PHP bloginfo ('Atom _ url');?> The atom address of the Wordpress blog
<? PHP bloginfo ('rss2 _ url');?> Wordpress blog RSS2 address
<? PHP bloginfo ('url');?> Absolute Wordpress blog address
<? PHP bloginfo ('name');?> Wordpress blog name
<? PHP bloginfo ('html _ type');?> Html version of the website
<? PHP bloginfo ('charset');?> Website character encoding format

PHP code of WordPress subject Template

<? PHP the_content ();?> Log Content
<? PHP if (have_posts ():?> Check whether logs exist.
<? PHP while (have_posts (): the_post ();?> If yes, all logs are displayed.
<? PHP endwhile;?> End phphanshu "while"
<? PHP endif;?> End phphanshu "if"
<? PHP get_header ();?> Header. php file content
<? PHP get_sidebar ();?> Content of the sidebar. php file
<? PHP get_footer ();?> Contents of the footer. php file
<? PHP the_time ('m-D-y')?> Display date in the format of "02-19-08"
<? PHP comments_popup_link () ;?> Display the message link of a log
<? PHP the_title ();?> Displays the title of a log or page
<? PHP the_permalink ()?> Display the permanent link/URL address of a log or page
<? PHP the_category (',')?> Display the category of a log or page
<? PHP the_author ();?> Show the author of a log or page
<? PHP the_id ();?> Display the ID of a log or page
<? PHP edit_post_link ();?> Display the editing link of a log or page
<? PHP get_links_list ();?> Show links in blogroll
<? PHP comments_template ();?> Comments. php file content
<? PHP wp_list_pages ();?> Display a blog page list
<? PHP wp_list_cats ();?> Display a blog category list
<? PHP next_post_link ('% link')?> URL of the next log
<? PHP previus_post_link ('% link')?> URL of the previous log
<? PHP get_calendar ();?> Call calendar
<? PHP wp_get_archives ()?> Display the date archiving list of a blog
<? PHP posts_nav_link ();?> Display newer log links (Previous Page) and older log links (next page)
<? PHP bloginfo ('description');?> Display the blog description

Other WordPress template code

/% Postname %/display the custom permanent link of the blog
<? PHP the_search_query ();?> Search form value
<? PHP _ E ('message');?> Print Output Information
<? PHP wp_register ();?> Show registration Link
<? PHP wp_loginout ();?> Show logon/logout links
<! -Next page-> insert pages in logs or pages
<! -More-> log Truncation
<? PHP wp_meta ();?> Displays administrator-related control information
<? PHP timer_stop (1);?> Display the page loading time
<? PHP echo get_num_queries ();?> Display load page Query

1. Call the latest article

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

<?php get_archives(‘postbypost‘, 10); ?> (显示10篇最新更新文章)

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 () HanShu 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.

2. 调用随机文章 <?php $rand_posts = get_posts(‘numberposts=10&orderby=rand‘); foreach( $rand_posts as $post ) : ?> <!--下面是你想自定义的Loop--> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?>

3. WordPress calls the latest message

The following is the latest message code I used in a WordPress topic. I can't remember which topic it is. The Code calls the database directly to display the latest message. Here, limit 10 limits the number of messages displayed. The green part is the output style of each message.

<?php global $wpdb; $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url, SUBSTRING(comment_content,1,30) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = ‘1‘ AND comment_type = ‘‘ AND post_password = ‘‘ ORDER BY comment_date_gmt DESC LIMIT 10"; $comments = $wpdb->get_results($sql); $output = $pre_HTML;  foreach ($comments as $comment) { $output .= "n<li>".strip_tags($comment->comment_author) .":" . " <a href="" . get_permalink($comment->ID) . "#comment-" . $comment->comment_ID . "" title="on " . $comment->post_title . "">" . strip_tags($comment->com_excerpt) ."</a></li>"; }   $output .= $post_HTML; echo $output;?>

4. WordPress call related articles

Show related articles on the Article Page

<?php $tags = wp_get_post_tags($post->ID); if ($tags) { $first_tag = $tags[0]->term_id; $args=array( ‘tag__in‘ => array($first_tag), ‘post__not_in‘ => array($post->ID), ‘showposts‘=>10, ‘caller_get_posts‘=>1 ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title();?> <?php comments_number(‘ ‘,‘(1)‘,‘(%)‘); ?></a></li> <?php endwhile; } } wp_reset_query(); ?>

5. WordPress calls an article of the specified category

<?php $posts = get_posts( "category=4&numberposts=10" ); ?> <?php if( $posts ) : ?> <ul><?php foreach( $posts as $post ) : setup_postdata( $post ); ?> <li> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a> </li> <?php endforeach; ?> </ul> <?php endif; ?>

6. WordPress Comment output from comments Link

<?php global $wpdb; $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url, SUBSTRING(comment_content,1,14) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = ‘1‘ AND comment_type = ‘‘ AND post_password = ‘‘ ORDER BY comment_date_gmt DESC LIMIT 10"; $comments = $wpdb->get_results($sql); $output = $pre_HTML; foreach ($comments as $comment) { $output .= "\n<li>".strip_tags($comment->comment_author) .":" . " <a href=\"" . get_permalink($comment->ID) . "#comment-" . $comment->comment_ID . "\" title=\"on " . $comment->post_title . "\">" . strip_tags($comment->com_excerpt) ."</a></li>"; } $output .= $post_HTML; echo $output;?>

7. WordPress calls comment output containing gravatar Avatar

<?php global $wpdb; $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved,comment_author_email, comment_type,comment_author_url, SUBSTRING(comment_content,1,10) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = ‘1‘ AND comment_type = ‘‘ AND comment_author != ‘郑 永‘ AND post_password = ‘‘ ORDER BY comment_date_gmt DESC LIMIT 10"; $comments = $wpdb->get_results($sql); $output = $pre_HTML; foreach ($comments as $comment) { $output .= "\n<li>".get_avatar(get_comment_author_email(‘comment_author_email‘), 18). " <a href=\"" . get_permalink($comment->ID) . "#comment-" . $comment->comment_ID . "\" title=\"" . $comment->post_title . " 上的评论\">". strip_tags($comment->comment_author) .": ". strip_tags($comment->com_excerpt) ."</a></li>"; } $output .= $post_HTML; $output = convert_smilies($output); echo $output; ?>

The code above changes the value of comment_author to your ID, 18 indicates the Avatar size, and 10 indicates the number of comments.

8. WordPress website call statistics

1、日志总数: <?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts->publish;?> 2、草稿数目: <?php $count_posts = wp_count_posts(); echo $draft_posts = $count_posts->draft; ?> 3、评论总数: <?php echo $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments");?> 4、成立时间: <?php echo floor((time()-strtotime("2008-8-18"))/86400); ?> 5、标签总数: <?php echo $count_tags = wp_count_terms(‘post_tag‘); ?> 6、页面总数: <?php $count_pages = wp_count_posts(‘page‘); echo $page_posts = $count_pages->publish; ?> 7、分类总数: <?php echo $count_categories = wp_count_terms(‘category‘); ?> 8、链接总数: <?php $link = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = ‘Y‘"); echo $link; ?> 9、用户总数: <?php $users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users"); echo $users; ?> 10、最后更新: <?php $last = $wpdb->get_results("SELECT MAX(post_modified) AS MAX_m FROM $wpdb->posts WHERE (post_type = ‘post‘ OR post_type = ‘page‘) AND (post_status = ‘publish‘ OR post_status = ‘private‘)");$last = date(‘Y-n-j‘, strtotime($last[0]->MAX_m));echo $last; ?> 9.wordpress判断语句

Is_single ()

Determine whether the page is for a specific article

Is_single ('2 ′)

Determine whether the page is for a specific article (ID = 2)

Is_single ('beef stew ')

Page for determining whether it is a specific article (Title judgment)

Is_single ('beef-stew ')

Determine whether it is a page for a specific article (slug)

Comments_open ()

Enable message?

Pings_open ()

Whether to enable Ping

Is_page ()

Whether it is a page

Is_page ('42 ′)

Id determination, that is, whether it is a page with ID 42

Is_page ('about me ')

Determine title

Is_page ('about-Me ')

Slug judgment

Is_category ()

Category?

Is_category ('6 ′)

Id determination, that is, whether it is a classification with ID 6

Is_category ('clusters ')

Classification title judgment

Is_category ('clusters ')

Classification slug judgment

In_category ('5 ′)

Judge whether the current article belongs to Category 5

Is_author ()

Display the pages of all authors

Is_author ('000000 ′)

Display the author number 1337 page

Is_author ('elite hacker ')

Display the current author's page by nickname

Is_author ('elite-hacker ')

The following uses different judgments to display archives by year, month, day, and time.

Is_date ()

Is_year ()

Is_month ()

Is_day ()

Is_time ()

Determine whether the current page is an archive page

Is_archive ()

Determine whether to search

Is_search ()

Determine whether the page is 404

Is_404 ()

For example:

<?php if(is_single()):?> //这里写你想显示的内容,包括函数 <?php endif;?>

Or:

<?php if(is_home() && !is_paged() ):?> //这里写你想显示的内容,包括函数 <?php endif;?>

10. WordPress non-plug-ins synchronize Twitter

<?php require_once (ABSPATH . WPINC . ‘/class-feed.php’); $feed = new SimplePie(); $feed->set_feed_url(‘http://feeds.feedburner.com/agting′); $feed->set_file_class(‘WP_SimplePie_File’); $feed->set_cache_duration(600); $feed->init(); $feed->handle_content_type(); $items = $feed->get_items(0,1); foreach($items as $item) { echo ‘<a target=”_blank” rel=”external nofollow” title=”Follow Me on Twitter” href=”http://twitter.com/agting″>@郑永</a>: ‘.$item->get_description(); } ?>

In the code, change agting to your Twitter user name, and change Zheng Yong to your name.

Another method of calling requires your space to be a foreign Host:

<?php // Your twitter username. $username = "wange1228"; // Prefix - some text you want displayed before your latest tweet. // (HTML is OK, but be sure to escape quotes with backslashes: for example href=\"link.html\") // Suffix - some text you want display after your latest tweet. (Same rules as the prefix.) $suffix = ""; $feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1"; function parse_feed($feed) { $stepOne = explode("<content type=\"html\">", $feed); $stepTwo = explode("</content>", $stepOne[1]); $tweet = $stepTwo[0]; $tweet = str_replace("&lt;", "<", $tweet); $tweet = str_replace("&gt;", ">", $tweet); return $tweet; } $twitterFeed = file_get_contents($feed); echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix); ?>

Zeroz summarizes the features of this method:

1. Non-plug-ins!

2. You do not need to verify the user name and password, that is, you can specify to call the tweet of any person!

3. You can customize the text displayed after the tweet information, that is, $ suffix = "". Here!

4. Only the latest tweet can be called to meet my needs.

5. Only foreign space is available! (I have verified it)

 

Original article: http://blog.sina.com.cn/s/blog_7a298a6c010103n5.html

WordPress page Function Code call Daquan

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.