Parsing Post_class and Get_post_class functions in WordPress, wordpresspostclass_php tutorials

Source: Internet
Author: User
Tags wordpress blog

Parse the Post_class and Get_post_class functions in WordPress, Wordpresspostclass


Post_class ()
Post_class is a built-in WordPress function that displays the class name of the article, which usually generates unique CLSS values for each article, and if you need to make your own theme, and you need a little personality, you'd better stop by. With this function and with the flexible CSS code, we can create a personalized WordPress blog.

Post_class function Description
This function typically generates unique CLSS values for each article, which can be easily used in the node where the article resides.

function uses
Like other WordPress tag functions such as header_image and wp_title, functions without get are usually displayed directly without returning any values.

 
  <?php post_class();="" ?="">
   > <?php the_content;? > 
 
  

Yes, you may have noticed that we don't even have to write clss= "Post_class ()" When using the Post_class function.

Instance Results
No suspense, the results are as follows

 
  
   
   Article content 
 
  

The use of the main function is finished,
The following is the usual source code for the function:
To learn more about this function, and the Get_post_class function, please follow the post.

/** * Display The classes for the post Div. * * @since 2.7.0 * * @param string|array $class One or more classes to add to The class list. * @param int $post _id an optional post ID. */function Post_class ($class = ", $post _id = null) {//Separates classes with a single space, collates classes for POS T DIV Echo ' class= '. Join ("', Get_post_class ($class, $post _id)). '"';}

Get_post_class detailed
Get_post_class is the basic implementation of the Post_class function, in WordPress, like some other functions with get, the function will have a return value, and the return value will be an array containing the basic information of the current article, Get_post_class Functions are mainly used to generate a class value for each article that has nothing to do with it.

If you are a less demanding person, then post_class this function is actually enough for you to toss. If you are a person with a mental cleanliness and do not want your WordPress site to have too many useless code, then you can continue to look down.

Get_post_class function Explanation
This function is primarily used to generate an array of information about the current article, which contains information that we tend to use as class values in the story layer.
As I mentioned above, the Post_class function uses the class value generated by this function.
and the function supports inserting your own class values, one into the returned array.
The above is my own understanding, of course, you can also look at the official manual.

The more puzzling manuals are as follows:
WordPress Themes has a template tag for the post HMTL tag which would help theme authors to style more effectively with CS S. The Template Tag is called Get_post_class. This function returns different post container classes which can is added, typically, in the index.php, single.php, and OT Her template files featuring post content, typically in the HTML

Tag.
function usage

<?php Get_post_class ($class, $post _id);?>

If you are in a loop and you do not need to insert a custom class value, the function does not accept any arguments.

function parameters
$class: The custom class value allows the string to also be used as a dead array.

$post _id: Article ID

Working with instances

$MyClass = Get_post_class ();  Var_dump ($MyClass);

Output Result:

Array (9) {[0]=> string (8) "post-249" [1]=> string (4) "POST" [2]=> string (9) "Type-post" [3]=> string (+) "STA Tus-publish "[4]=> string" Format-standard "[5]=> string (6)" Hentry "[6]=> string ()" Category-catcatcat " [7]=> string (8) "Tag-tag1" [8]=> string (8) "Tag-tag2"}

Step-by-step examples

$MyClass = Get_post_class (' Index-post ', 249);//or $MyClass = Get_post_class (Array (' Index-post '), 249); Var_dump ($MyClass);

Output Result:

Array (Ten) {[0]=> string (8) "post-249" [1]=> string (4) "POST" [2]=> string (9) "Type-post" [3]=> string (+) "St Atus-publish "[4]=> string" Format-standard "[5]=> string (6)" Hentry "[6]=> string" Category-catcatcat "[7]=> string (8)" Tag-tag1 "[8]=> string (8)" Tag-tag2 "[9]=> string (Ten)" Index-post "}

Summarize
According to the source code of the function, we can see that the class value of this function is listed in the following order:

    • Article ID
    • Article type (page, article)
    • The article Type (page, article) is the same as the previous one, but the result has more ' type-' words
    • Publish Status
    • Article format
    • If you need a password
    • Classification described in the article (the classification is listed individually)
    • The label of the article (the label will be listed individually)

Articles you may be interested in:

    • Use of PHP functions to get recent articles in WordPress development
    • Introduction to the use of PHP functions for custom menus in WordPress development
    • 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
    • Simple steps to add Google search to WordPress
    • Get_post and get_posts function usage in WordPress development
    • Get_post_custom () function usage analysis in WordPress development
    • Installing Hana FLV player in WordPress with video player plugin
    • A detailed description of the use of classification function wp_list_categories in WordPress
    • The implementation of short code in the development of WordPress and the skill of using related functions

http://www.bkjia.com/PHPjc/1088784.html www.bkjia.com true http://www.bkjia.com/PHPjc/1088784.html techarticle parsing Post_class and Get_post_class functions in WordPress, Wordpresspostclass post_class () Post_class is a WordPress built-in for displaying articles The function of class name, the function ...

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