WordPress Development in the use of related functions for title display analysis, wordpress title _php Tutorial

Source: Internet
Author: User
Tags echo display nginx server

WordPress in the development of the title display for the use of relevant functions of the analysis, WordPress title


Single_cat_title () function
Single_cat_title () function, which we seldom use in daily life, but this function will give us a lot of problems, such as the current page directory, tags, the function is not attached to the main WordPress loop, and can not be put into the main loop to use.

Describe
Gets the classification, label of the current page.

<?php Single_cat_title ($prefix, $display);?>
    • $prefix: Used to set what is displayed before the title.
    • $display: Used to set whether to display directly or return to a variable.

Instance
In this extract the WordPress 2011 default theme, the category.php file around the 18th line of the position of the code

<?phpprintf (' Category Archives:%s ', ' Twentyeleven '), '. Single_cat_title (', false '). '' );? >

Get_the_title and The_title
Get_the_title and The_title Two functions are used to display the title of the article on the article page function, the reason is to merge two functions into an article is because the two letters is an implementation, but the_title the default direct display, Get_the_title The default return string, if you have doubts about it, please look down.

function explanation
The Get_the_title and The_title functions are primarily used to display the title of the current article in a loop, note that the The_title function must be used in a loop.
The difference is that Get_the_title can only return the article title as a string, and The_title can set custom characters before and after the title, as well as whether to display or return a string.

The_title function Use, parameter explanation

<?php The_title ($before, $after, $echo);?>
    • $before characters before the title
    • $after characters after the title
    • $echo display, or return a string, by default True

The_title Example

<?php the_title (' = = ', ' <= ');?>

For the example in this article, we will get the following title:

' =>get_the_title and the_title<= '

Get_the_title function Use, parameter explanation

<?php $myTitle = Get_the_title ($ID);?>

The above code we will get the title of the article variable $mytitle;
$ID is used to set the article ID, but we can omit this parameter in the loop.

Get_the_title Example

<?php $myTitle = Get_the_title ($ID);  echo $mytitle. ' "Title demo" ';? >

We will get

Get_the_title and The_title "title demo"

Summarize
Has said so much, do not know to you to be helpful?
Overall the_title is a higher level package for get_the_title. As said in the Wp_title, the more advanced package, although easy to use, but can toss a little bit less.
The following is the source code for the two functions

the_title function Declaration
The function is positioned around the 43–55 line of the wp-include/post-template.php file

<?php/** * Display or retrieve the current post title with optional content. * * @since 0.71 * * @param string $before Optional. Content to prepend to the title. * @param string $after Optional. Content to append to the title. * @param bool $echo Optional, default to True. Whether to display or return. * @return null|string null on no title. String if $echo parameter is false. */function the_title ($before = ", $after =", $echo = True) {$title = Get_the_title ();  if (strlen ($title) = = 0) return;  $title = $before. $title. $after;  if ($echo) echo $title; else return $title;}? >

get_the_title function Declaration
The function is positioned around the 103–118 line of the wp-include/post-template.php file

<?php/** * Retrieve post title. * If The post is protected and the visitor are not a admin, then "protected" * 'll be displayed before the post title. If The post is private and then * "Private" would be located before the post title. * * @since 0.71 * * @param int $id Optional. The Post ID.  * @return string */function get_the_title ($id = 0) {$post = &get_post ($id); $title = Isset ($post->post_title)? $post->post_title: "; $id = Isset ($post->id)?  $post->id: (int) $id; if (!is_admin ()) {if (!empty ($post->post_password)) {$protected _title_format = apply_filters (' Protected_title_fo  Rmat ', __ (' Protected:%s ')); $title = sprintf ($protected _title_format, $title); } else if (Isset ($post->post_status) && ' private ' = = $post->post_status) {$private _title_format = Apply_  Filters (' Private_title_format ', __ (' Private:%s ')); $title = sprintf ($private _title_format, $title); }} return Apply_filters (' The_title ', $title, $id);}? >

Articles you may be interested in:

    • Analysis of PHP function usage in debugging thumbnail in WordPress
    • configuration resolves the WordPress path in the Nginx server does not automatically add a slash problem
    • The PHP function used in WordPress to get the search form is parsed
    • Use the Wp_count_posts function in WordPress to count the number of articles
    • PHP functions for invoking comment templates and looping out comments in WordPress
    • A detailed description of the use of classification function wp_list_categories in WordPress
    • WordPress restricts non-admin users to comment only once after the article
    • Detailed PHP functions for creating and adding filters in WordPress
    • A detailed description of the use of Wp_title () functions in WordPress development

http://www.bkjia.com/PHPjc/1089578.html www.bkjia.com true http://www.bkjia.com/PHPjc/1089578.html techarticle WordPress In the development of the use of the title display related functions using parsing, wordpress title Single_cat_title () function single_cat_title () function, in daily life we seldom use, but this function ...

  • 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.