WordPress Function Daquan

1. bloginfo ()

As the name suggests, this function is mainly used to display blog information; and according to different parameters can be used to display information in different parts of blog commonly used are the following:

bloginfo ( ‘name’) displays blog title, such as “fat horse”; the default (no write parameter) of the output;

bloginfo ( ‘description’) display blog description section, such as “knowledge-sharing networks · enjoy a happy life”;

bloginfo ( ‘url’) output blog URL address, such as http://www.qintag.com;

bloginfo ( ‘rss2_url’) show the RSS2.0 feed blog address, such as http://www.qintag.com/feed;

bloginfo ( ‘template_url’) is used to get WordPress blog template address;

bloginfo ( ‘charset’) show blog coding methods, such as “UTF-8”;

A common use bloginfo () function has the following composition:
<a href=”<?php bloginfo(‘url’); ?> “title =” <? php bloginfo ( ‘description’);?> “> <php bloginfo ( ‘name’);??> </ a >

As this form is usually used to add blog at the bottom of the information, such as the Copyright @ Moderate wind, often used in the theme template.

Note that bloginfo () function can only display the output parameters, if you want to use these values in PHP statement obtained, you need to use get_bloginfo () function, the function and bloginfo () using the same parameters, to obtain the same result.

2. wp_title ()

This function is used to display the title of the page, such as a page in the article, the article title is displayed; in the category page, the category name is displayed; and so on.

wp_title () function with three parameters, namely wp_title ( ‘separator’, echo, seplocation), wherein the separator is split between the symbolic title and the rest of the default is >>; echo is a bool variable, take the true heading, will take the false title as a PHP parameter returns; seplocation delimiter position, whichever is defined delimiter right back in the title, take any other value, it represents the delimiter in front of the title.

For example, shaped like a folder header.php theme in a piece of code:
<? Php wp_title ( ‘|’, true, ‘right’);?>
<Php bloginfo ( ‘description’)??;> -; <Php bloginfo ( ‘name’)??>
</ Title>

3. wp_get_archives ()

This function is used to get the blog article archive by setting the function parameters, you can get a variety of ways, such as monthly, yearly and so on.

wp_get_archives () after the function can also be with a variety of parameters, but all parameters need to use & connection, and in single quotes ( ‘) to a character string passed to the function, the form wp_get_archives (‘ type = monthly & format = html & show_post_count = 1 & limit = 10 ‘).

As the meaning of the parameters are described below:
type = monthly archive article represented by month, you can use the yearly, daily, weekly, etc. instead of monthly expressed by year, day, and week display articles archive;

format = html representation usual in HTML <li> Format Article list;

show_post_count = 1 denotes a display belongs to the category (year, month, etc.) the number of articles in the article archive later, the parameter is a bool value;

The maximum number of articles limit = 10 denotes a display archived 10, more than the number, the excess is not displayed;

Although the parameters slightly, it is slightly more complicated, but in fact just pay attention to type, show_post_count and limit the three parameters can be.

4. wp_list_categories ()

And wp_get_archives () function is similar, wp_list_categories () function is used to obtain classified information on blog articles, and you can set the appropriate function parameter to display it. Similar to the function parameters and wp_get_archives () function, you need to use to connect & , in single quotes ( ‘) to pass a character string shaped like wp_get_archives (‘ orderby = name & order = ASC & show_count = 1 & use_desc_for_title = 1 & feed = Feed & exclude = 2,5 & number = 10 ‘).

As examples, the significance of the function of each parameter is as follows:

orderby = name represents the name of the category in alphabetical order of display classified information, can be replaced with name ID and the like;

represented in alphabetical order = ASC category name displayed in ascending classified information, the ASC to DESC indicates descending;

show_count = 1 the number of articles in the category name after each display belong to the classification;

use_desc_for_title = 1 is described using the classification information for each category name hyperlink to add a title attribute;

feed = Feed: next to each add a category called “Subscribe to the” hyperlink, providing RSS feeds of the classification;

exclude = 2,5: ID for the removal of class 2 and 5 in the category displayed; can also be used include = 2,5 indicates that only show ID to the class 2 and 5;

number = 10: Displays only the first of the 10 categories.

5. get_the_category ()

get_the_category () function is used to return an array of some of the attributes of the current article belongs to the category composed, the array includes the following:

cat_ID: the current category ID (you can also write ‘term_id’);

cat_name: the name of the current category (also written as ‘name’);

category_description: The current classification descriptions (also written as ‘description’);

category_count: belonging to the current classification of the number of articles (also written ‘count’).

Use of specific methods, we passed a few sentences to explain the following:

Shaped like get_the_category () -> cat_ID statement returns the current article category ID number;

Shaped like get_the_category () -> description of statements, the return current article describes the classification of; and so on.

6. the_category ()

This function returns the current article belongs to the category name, and is a hyperlink in the form of articles category.

The default no-argument form the_category () to display the category name directly in the form of hyperlinks, read: Gifts Available;

You can keep up in the function parameters such as separators to format the output, such as the_category ( ‘-‘), if the current articles belonging to two or more classification, you can display the form: Gifts Available – empirical knowledge; such as belong to only one category, is displayed in such form: Recommend fine.

7. category_description ()

The function to classify the ID as an input to give a description of the classification and often echo, get_the_category () with the use of the current classification describes the output:

echo category_description (get_the_category () -> cat_ID);

The above statement, get_the_category () has preserved an array of the current classification of information; cat_ID array ID for the classification; the ID input to category_description () function, you can get a description of the classification; then use echo to output .

But after the test, use the following statement can achieve the same functionality and the above statement:

echo category_description ();

This may be because the function in case of default no parameter input will output the current classification described it.

This paper describes some WordPress conditions to function, to determine whether certain conditions were met, for example, is currently at home; whether the current is an author, and so on.

8. is_home ()

is_home () to determine whether the blog page is currently displayed blog page, returns a Bool value if it is in the home, then return TRUE;.

Otherwise, it returns FALSE.

This function is used to control the blog sidebar display, often use the following code snippet:

<? Php
if (is_home ()) {
// This is the content that should be displayed in the blog page
} Else {
Home // This non-blog content should be displayed

9. is_archive ()

is_archive () to determine whether the contents of the currently displayed page is the blog archives, such as archive by date or by category archives, and so on; and its is_home () functions, return a Bool value.

10. is_page ()

is_page () function to determine whether the contents of the currently displayed page blog is independent of (page), such as “on the bamboo wind” and other page; it also returns a Bool value.

We can function in the template is determined whether the current page is a stand-alone, to decide whether to display the currently displayed article Published like.

11. is_paged ()

This function is used to determine whether the current article content because of excessive paging display; <! – Nextpage->

Note that, if you manually add a tag to write articles, to force a page break, then this function and will not be return TRUE.

12. is_page_template ()

is_page_template () function with a parameter required, usually in the following manner:

is_page_template ( ‘guestbook.php’);

Thereby judging individual pages (page) whether the currently displayed template guestbook.php parameters shown; if not with arguments, the function returns the current page independently whether to use the template.

13. is_single ()

is_single () to determine whether the contents of the currently displayed page is a separate article which can be followed by three kinds of parameters, one is the article ID;. One is the title of the article (title); one is the article name (slug, a short, form description of the title of the article); or you can use a combination of three kinds of parameters, thereby to determine whether the contents of the current page is specific to an article.

A simple example is as follows, we can are several ways to determine whether the contents of the currently displayed is Text:

is_single ( ‘808’);

is_single ( ‘good use WordPress must know the function (b)’);

is_single ( ‘functions-must-known-using-wordpress-second’);

is_single ( ‘808’, ‘good use WordPress must know the function (b)’,


Here, the bamboo wind above the need for a way to do the final Description: This function is followed by three parameters, there is a priority, if the first argument qualifying returns TRUE; otherwise, it returns FALSE; seemingly behind argument does not make sense.

14. is_category ()

This function is used to determine whether the contents of the currently displayed page is a category page, such as site-related; without which the parameter of the function returns a Bool value.

15. is_tag ()

is_tag () to determine whether the currently displayed page is a tab page, such as WordPress; thereafter do not need to talk to the parameters of the function also returns a Bool value.

16. is_date ()

This function is used to determine whether the content currently displayed in chronological archive page, such as in April 2009, or April 8, 2009, and so on.

17. is_day (), is_month (), is_year ()

These functions are used to determine whether the contents of the currently displayed by day, month or year archive page. They is_date () is similar, except that the more specific archiving time only.

18. is_author ()

This function is used to determine whether the contents of the currently displayed page to the author archives, such as wind Zhuying blog’s admin page author.

19. is_admin ()

is_admin () function is used to determine whether the current page in the control panel or the administrator panel page.

In this article, to introduce function except get_bloginfo () In addition, almost all will be used in WordPress theme sidebars some functions, such as get_posts () and so on.

20. get_bloginfo ()

The function and our previous article must know good use WordPress functions (a) described bloginfo () function to achieve nearly the same functionality as the main blog used to display information; And according to different parameters of the heel, the output will be different from blog information.

When not followed by parameters, get_bloginfo () to display the blog name, as in “the bamboo wind”;

Followed by other parameters, you can display the corresponding information, such as get_bloginfo ( ‘description’) for displaying the blog description;

Other parameters may also be used, including name, url, wpurl and admin_email etc. But as it relates to bloginfo () function to achieve the same result, therefore, in the case of bloginfo can be achieved, the bamboo wind is not recommended get_bloginfo () function .

WordPress get current method user login information

1) get_currentuserinfo ();

This function will be assigned to the user currently logged on the global variable $ current_user well as some of the individual user information global variables such as $ display_name, $ user_email like. Code is as follows:

 1 <?php global $current_user, $display_name , $user_email;
 2 get_currentuserinfo();
 3 // Global variable $ current_user
 4 echo 'Username: ' . $current_user->user_login . "\n";
 5 echo 'User email: ' . $current_user->user_email . "\n";
 6 echo 'User first name: ' . $current_user->user_firstname . "\n";
 7 echo 'User last name: ' . $current_user->user_lastname . "\n";
 8 echo 'User display name: ' . $current_user->display_name . "\n";
 9 echo 'User ID: ' . $current_user->ID . "\n";
10 // Global variables alone
11 echo $display_name . "'s email address is: " . $user_email;
12 ?>

2). wp_get_current_user()

1 <?php
2 $current_user = wp_get_current_user();
3 if ( 0 == $current_user->ID ) {
4 // Not logged in.
5 } else {
6 // Logged in.
7 }
8 ?>

WordPress adds the Gravatar avatar caching feature

This method is I love WP from a plug-in to take out, so do not need to install plug-ins, you only need to add the code in the theme file functions.php can be achieved, as follows:

First, create a new folder in the root directory of the site, named avatar, and set the permissions into 777, this can be changed, but need to modify the corresponding code in the back of the folder name.

Then, put the following code in functions.php:

/* Gavatar 头像缓存 */
function get_cavatar($source) {
$time = 1209600; //The time of cache(seconds)
$abs = ABSPATH.’avatar/’.$tmp[1].’.jpg’;
$url = get_bloginfo(‘wpurl’).’/avatar/’.$tmp[1].’.jpg’;
$default = get_bloginfo(‘wpurl’).’/avatar/’.’default.jpg’;
if (!is_file($abs)||(time()-filemtime($abs))>$time){
if (filesize($abs)<500) { copy($default,$abs); }
return ‘<img alt=”” src=”’.$url.’” width=”’.$tmp[2].’” height=”’.$tmp[2].’” />’;

Then save it. So there are places where the avatar will automatically replace the local cache of the picture.

I would like to thank WP-gravatar-mini-cache plug-in and its author evil Luo brake. Evlos.

WordPress user function wp_signon () and is_user_logged_in () Xiangjie

WordPress theme development, and sometimes have to control whether landing, for example, some pages can only be logged on the user can view, some special custom domain content (such as download link) is only logged in the user can view and so on. Then how to achieve these functions must be inseparable from the following two functions: wp_signon () and is_user_logged_in (), the following carefully.

1. wp_signon()

Function: Verify the user name and password, and return the login result.

Usage: <? Php wp_signon ($ credentials, $ secure_cookie)?>

Parameters: $ credentials for the user information array, $ secure_cookie for the use of security cookie switch.

Return information: If the error is defined WP_Error information, if normal WP_User information.

Note: only supports WordPress2.5 and above.


$creds = array();//数组
$creds['user_login'] = 'example';
$creds['user_password'] = 'plaintextpw';
$creds['remember'] = true;
$user = wp_signon( $creds, false );//登陆,并保存返回的信息
if ( is_wp_error($user) )
   echo $user->get_error_message();//输出返回的信息
2. is_user_logged_in()

Function: Determines whether the user is logged on

Parameters: None

Returns: the bool value (TRUE or FALSE)


if ( is_user_logged_in() ) {
    echo ’Welcome, registered user!’;
} else {
    echo ’Welcome, visitor!’;

Function finished, and hope that friends can do in their own subject when the flexibility to use them.


WordPress Upgrade to 3.0 Home Page Call single_cat_title () Does Not Display the Problem

WordPress upgrade to 3.0, found that the first page call single_cat_title () category name is not displayed, compared to 2.9 and 3.0 version of the single_cat_title () function, found that the new version of the function of the updated content, the two functions comparison.


function single_cat_title($prefix = ”, $display = true ) {
 global $wp_query;

 if ( is_tag() )
  return single_tag_title($prefix, $display);

 if ( !is_category() )

 $cat = $wp_query->get_queried_object();
 $my_cat_name = apply_filters(‘single_cat_title’, $cat->name);
 if ( !empty($my_cat_name) ) {
  if ( $display )
   echo $prefix . $my_cat_name;
   return $my_cat_name;


function single_cat_title($prefix = ”, $display = true ) {
 $cat = intval( get_query_var(‘cat’) );
 if ( !empty($cat) && !(strtoupper($cat) == ‘ALL’) ) {
  $my_cat_name = apply_filters(‘single_cat_title’, get_the_category_by_ID($cat));
  if ( !empty($my_cat_name) ) {
   if ( $display )
    echo $prefix.strip_tags($my_cat_name);
    return strip_tags($my_cat_name);
 } else if ( is_tag() ) {
  return single_tag_title($prefix, $display);