Home > CMS Tutorial > WordPress > body text

How to customize article details page template in WordPress

Release: 2019-07-19 16:39:21
Original
5794 people have browsed it

How to customize article details page template in WordPress

If we want the article page style of a certain category to be different from other categories, we can use a custom template method to achieve this. For example, if we are going to use a different template style for category articles named WordPress than other categories,

first create a new template file named single-wordpress.php in the root directory of the theme used. Add the following code snippet to your current theme’s functions.php file:

add_action('template_include', 'load_single_template');
 function load_single_template($template) {
     $new_template = '';
    // single post template    
    if( is_single() ) {      
    global $post;
     // 'wordpress' is category slugs      
     if( has_term('wordpress', 'category', $post) ) {        
     // use template file single-wordpress.php        
     $new_template = locate_template(array('single-wordpress.php' ));
           }
          }    
           return ('' != $new_template) ? $new_template : $template;  
           }
Copy after login

The above code will specify WordPress category posts, using the single-wordpress.php template file. In the same way, you can repeat the above steps to allow other categories to use custom templates.

For more wordpress related technical articles, please visit the wordpress tutorial column to learn!

The above is the detailed content of How to customize article details page template in WordPress. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template