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; }
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!