In the second part of the series, we went through the first batch of WordPress template tags. In this third part, we're going to go through the second batch of the almost 200 template tags. Throughout the tutorial, we'll see template tags about taxonomies and terms.
category_description()
This template tag returns the description of a category.
This template tag accepts only one parameter:
$category_ID
(optional—integer):<?php $cat_desc = get_category_description( 15 ); ?>
tag_description()
This template tag returns the description of a tag.
This template tag accepts only one parameter:
$tag_ID
(optional—integer):<?php // Display the description of current tag. echo tag_description(); // Get the description of a specific tag. $special_tag_desc = tag_description( 42 ); ?>
term_description()
This template tag simply returns the description of a term.
This template tag accepts two parameters:
$term_ID
(optional—integer):$taxonomy
(optional—string):<?php // Display the description of current term. echo term_description(); // Get the description of a specific term from a specific taxonomy. $special_term_desc = term_description( 14, 'laptop_inches' ); ?>
single_cat_title()
This template tag returns and displays the category's title for using in page titles.
This template tag accepts two parameters:
$prefix
(optional—string):$echo
(optional—boolean):TRUE
) or return (FALSE
) the tag.TRUE
)
<?php // Display the category title with a prefix. single_cat_title( 'Category: ' ); // Get the category title. $cat_title = single_cat_title( '', false ); ?>
single_tag_title()
This template tag returns and displays the tag's title for using in page titles.
This template tag accepts two parameters:
$prefix
(optional—string):$echo
(optional—boolean):TRUE
) or return (FALSE
) the tag.TRUE
)
<?php // Display the tag title with a prefix. single_tag_title( 'Tag Archive: ' ); // Get the tag title. $tag_title = single_tag_title( '', false ); ?>
single_term_title()
This template tag returns and displays the term's title for using in page titles.
This template tag accepts two parameters:
$prefix
(optional—string):$echo
(optional—boolean):TRUE
) or return (FALSE
) the tag.TRUE
)
<?php // Display the term title with a prefix. single_term_title( 'Term Archive: ' ); // Get the term title. $term_title = single_term_title( '', false ); ?>
get_the_category_list()
& the_category()
These template tags fetch and output the categories that are assigned to the post.
Both template tags accept three parameters:
$separator
(optional—string):$parents
(optional—string):$post_ID
(optional—integer):<?php // Get an unordered list of current post's categories. get_the_category_list(); // Display current post's categories separated by commas and with their parents (if there are any). the_category( ', ', 'multiple' ); ?>
get_the_category_rss()
& the_category_rss()
These template tags make the categories that are assigned to the post ready for feeds and return or display it.
Both template tags accept only one parameter:
$feed_type
(optional—string):<?php // Get feed items of categories for the default feed type. get_the_category_rss(); // Display feed items of categories for atom feeds. the_category_rss( 'atom' ); ?>
get_the_tag_list()
& the_tags()
These template tags return or display the tags of your posts.
Both template tags accept three parameters:
$before
(optional—string):get_the_tag_list()
and 'Tags: ' for the_tags()
)
$sep
(optional—string):get_the_tag_list()
and ', ' for the_tags()
)
$after
(optional—string):<?php // Get a plain list of tag links. get_the_tag_list(); // Display the tags with custom parameters. the_tags( '<div class="mytheme-tags">' . __( 'Tags: ', 'translation-domain' ) , ' · ', '</div>' ); ?>
get_the_term_list()
& the_terms()
These template tags get and echo a list of terms assigned for the post.
Both template tags accept five parameters:
$post_ID
(optional—integer):$taxonomy
(required—string):$before
(optional—string):$sep
(optional—string):$after
(optional—string):<?php // Getting current post's terms from the "Available Brands" taxonomy. get_the_term_list( $post->ID, 'available-brands' ); // Display current post's terms from the "Available Brands" taxonomy with some customization. the_terms( $post->ID, 'available-brands', __( 'Available Brands: ', 'translation-domain' ), ' - ' ); ?>
the_taxonomies()
This template tag displays the taxonomies and the terms associated with those taxonomies.
This template tag accepts only one parameter:
$args
(optional—array):'post'
(integer): Post ID.'before'
(string): HTML code to add before the output.'sep'
(string): Separator text.'after'
(string): HTML code to add after the output.'template'
(string): The template to use for displaying the taxonomy terms.%s
is the taxonomy label and %t
is the list of term links)
<?php $args = array( 'before' => '<div class="taxonomies">', 'sep' => ', ', 'after' => '</div>' ); the_taxonomies( $args ); ?>
get_edit_tag_link()
& edit_tag_link()
These template tags return or echo a "edit this tag" link for you to use in your templates.
get_edit_tag_link()
accepts two parameters:
$tag_ID
(required—integer):NULL
)
$taxonomy
(optional—string):And edit_tag_link()
accepts four parameters:
$link
(optional—string):$before
(optional—string):$after
(optional—string):$tag
(required—object):NULL
)
<?php // Retrieving the current tag's "edit tag" link. $edit_tag_link = get_edit_tag_link(); // Retrieving a specific term's "edit term" link. $edit_tag_link = get_edit_tag_link( 4, 'keyboard-brand' ); // Displaying the current tag's "edit tag" link. edit_tag_link( __( 'Edit', 'translation-domain' ), '<strong>', '</strong>' ); // Displaying a specific tag's "edit tag" link. edit_tag_link( __( 'Edit', 'translation-domain' ), '', '', 11 ); ?>
wp_list_categories()
This template tag returns or displays a list of categories or terms from any kind of taxonomy.
This template tag accepts only one parameter:
$args
(optional—array):'show_option_all'
(string): Shows a link to home (or the "Posts" page set in Settings > Reading) if you set it to a non-blank value. The value will be the anchor text of the link.'show_option_none'
(string): Text to show if there aren't any categories.'orderby'
(string): How to order the links by. Accepts 'name', 'ID', 'slug', 'count' and 'term_group'.'order'
(string): Whether to order items in ascending ('ASC') or descending ('DESC') order.'style'
(string): Style to display categories—'list' to generate an unordered list or 'none' to generate a list of links separated with <br />
s.'show_count'
(integer): Show post count next to each category link.'hide_empty'
(integer): Hide empty categories or not.'use_desc_for_title'
(integer): Use descriptions as "title" attributes of the links.'child_of'
(integer): Displays only children of a given ID of a category.'feed'
(string): If set to any non-blank value, category feed links will appear next to category links. The value will be the anchor text of the links.'feed_type'
(string): Type of feed ('rss', 'rss2', 'atom' or 'rdf').'feed_image'
(string): Image path to override anchor text and show an image instead.'exclude'
(string): Comma-separated list of category IDs to exclude.'exclude_tree'
(string): Same as "exclude", but you must use this one if the "hierarchical" argument is set to 1'current_category'
(integer): Adds a "current-cat" class when suitable.'hierarchical'
(integer): Display items with a hierarchical order or not.'title_li'
(string): Wraps the output with a <li>
tag and displays a title before the category list. You would probably want to set this to an empty string and disable wrapping.'echo'
(integer): Whether to echo the output (1) or return it (0).'depth'
(integer): Maximum depth.'taxonomy'
(string): Taxonomy to list.<?php $args = array( // Show an "All Posts" link. 'show_option_all' => __( 'All Posts', 'translation-domain' ), // Order by post count. 'orderby' => 'count', // Show post count. 'show_count' => 1, // Show feed links. 'feed' => 'Feed', // Remove title_li. 'title_li' => '' ); wp_list_categories( $args ); ?>
wp_dropdown_categories()
This template tag returns or echoes a dropdown menu (<select>
) of categories or terms from a taxonomy of your choice.
This template tag accepts only one parameter:
$args
(optional—array):'show_option_all'
(string): Text to display for showing all categories/taxonomies.'show_option_none'
(string): Text to display for showing no categories/taxonomies.'option_none_value'
(mixed): Value to use when no category/taxonomy is selected.'orderby'
(string): What column to use for ordering the categories/taxonomies.'order'
(string): What direction to order categories/taxonomies.'show_count'
(boolean or integer): Whether to show how many posts are in the category/taxonomy.'hide_empty'
(boolean or integer): Whether to hide categories/taxonomies that don't have any posts attached to them.'child_of'
(integer): Display all categories that are descendants of the given ID.'exclude'
(string): Comma-separated list of category/taxonomy IDs to exclude from the list.'echo'
(boolean or integer): Whether to display or retrieve content.'depth'
(integer): The max depth.'tab_index'
(integer): Tab index for the SELECT
element.'name'
(string): The NAME
attribute value for the SELECT
element.'id'
(string): The ID for the SELECT
element.'class'
(string): CSS class for the SELECT
element.'selected'
(integer): The category/taxonomy ID to be selected by default.'taxonomy'
(string): The name of the taxonomy to retrieve.<?php $args = array( 'show_option_none' => __( 'Nothing!', 'translation-domain' ), 'orderby' => 'title', 'show_count' => 1, 'echo' => 0, 'name' => __( 'brands', 'translation-domain' ), 'taxonomy' => __( 'available-brands', 'translation-domain' ) ); $brands_dropdown = wp_categories_dropdown( $args ); ?>
wp_tag_cloud()
This template tag returns or displays a cloud of terms, generated from a taxonomy of your choice (tags by default).
This template tag accepts only one parameter:
$args
(optional—array):'smallest'
(integer): Smallest text size.'largest'
(integer): Largest text size.'unit'
(string): Text size unit.'number'
(string): How many tags to return'format'
(string): How to return the tags list—'flat' for a flat list separated with spaces, 'list' for an HTML unordered list, and 'array' for a PHP array.'separator'
(string): Separator text.'orderby'
(string): How to order the tags by ('name' or 'count').'order'
(string): Whether to order items in ascending ('ASC') or descending ('DESC') order.'include'
(array): An array of IDs to include.'exclude'
(array): An array of IDs to exclude.'taxonomy'
(string): Taxonomy to get the terms from.'link'
(string): 'view' for front-end viewing, 'edit' for back-end editing links. Works with the 'post_type' argument.'post_type'
(string): If the 'link' argument is set to 'edit', you must set 'post_type' to a post type to set which type of posts will the "edit links" list.'echo'
(boolean): Whether to echo the template tag or not.TRUE
)
<?php $args = array( // Smallest & largest font sizes. 'smallest' => 10, 'largest' => 32, // Get only 20 tags. 'number' => 20, // Order by term popularity. 'orderby' => 'count', // Custom taxonomy. 'taxonomy' => 'brands', // Return output instead of echoing. 'echo' => 0 ); $tag_cloud = wp_tag_cloud( $args ); ?>
wp_generate_tag_cloud()
This template tag returns a tag cloud but this time, you get to choose your own tags.
This template tag accepts two parameters:
$tags
(required—array):NULL
)
$args
(optional—array):'smallest'
(integer): Smallest text size.'largest'
(integer): Largest text size.'unit'
(string): Text size unit.'number'
(string): How many tags to return'format'
(string): How to return the tags list—'flat' for a flat list separated with spaces, 'list' for an HTML unordered list, and 'array' for a PHP array.'separator'
(string): Separator text.'orderby'
(string): How to order the tags by ('name' or 'count').'order'
(string): Whether to order items in ascending ('ASC') or descending ('DESC') order.'topic_count_text'
(string): This is a nooped plural from _n_noop() to generate the text for the tooltip of the tag link.NULL
)
'topic_count_text_callback'
(string): This is the callback function, which gives the count of the posts with that tag returns a text for the tooltip of the tag link.NULL
)
'topic_count_scale_callback'
(string): This is the callback function that works with the 'smallest'
and 'largest'
arguments to calculate the font sizes of generated tags.'filter'
(integer): If this is set to 0, the function won't pass the filter with the same name.<?php // Get an array of the tags from current post. $tags = get_the_tags( '', ', ', '' ); // Set arguments. $args = array( 'smallest' => 10, 'largest' => 36, 'orderby' => 'count' ); wp_generate_tag_cloud( $tags, $args ); ?>
Hope you liked this second batch of template tags. There are six more batches to go, so stay tuned for more template tags!
If you have any questions, comments or corrections, you can share your thoughts with us in the Comments section. And if you liked the article, don't forget to share it with your friends!
Single-Page React Applications With the React-Router and React-Transition-Group Modules
12 Best Contact Form PHP Scripts
1 /Getting Started With the Mojs Animation Library: The ShapeSwirl and Stagger Modules
/Getting Started With the Mojs Animation Library: The Shape Module
Getting Started With the Mojs Animation Library: The HTML Module
Project Management Considerations for Your WordPress Project
/Introduction to the CSS Grid Layout With Examples
/Creating an Image Editor Using CamanJS: Layers, Blend Modes, and Events
/New Short Course: Code a Front-End App With GraphQL and React
Creating an Image Editor Using CamanJS: Applying Basic Filters
Creating an Image Editor Using CamanJS: Creating Custom Filters and Blend Modes
/Challenge: Create a To-Do List in React
1Deploy PHP Web Applications Using Laravel Forge
/Getting Started With the Mojs Animation Library: The Burst Module
/10 Things Men Can Do to Support Women in Tech
/A Gentle Introduction to Higher-Order Components in React: Best Practices
/Challenge: Build a React Component
/Eloquent Mutators and Accessors in Laravel
1A Gentle Introduction to Higher-Order Components in React
/Creating a Blogging App Using Angular & MongoDB: Delete Post
/Creating a Blogging App Using Angular & MongoDB: Add Post
/Introduction to Mocking in Python
/Creating a Blogging App Using Angular & MongoDB: Home
/Creating a Blogging App Using Angular & MongoDB: Login
/Creating Your First Angular App: Components, Part 2
/Creating Your First Angular App: Components, Part 1
/Persisted WordPress Admin Notices: Part 2
/Creating Your First Angular App: Basics
/Error and Performance Monitoring for Web & Mobile Apps Using Raygun
/Using Luxon for Date and Time in JavaScript
/How to Create an Audio Oscillator With the Web Audio API
/20 Essential WordPress Utilities to Manage Your Site
/Beginner’s Guide to Angular 4: HTTP
/Rapid Web Deployment for Laravel With GitHub, Linode, and RunCloud.io
/Introduction to Forms in Angular 4: Writing Custom Form Validators
/10 Best WordPress Booking & Reservation Plugins
/How to Download Files in Python
/Site Authentication in Node.js: User Signup
/Creating a Task Manager App Using Ionic: Part 1
/Deferring Tasks in Laravel Using Queues
/Manipulating HTML5 Canvas Using Konva: Part 1, Getting Started
/10 Must-See Easy Digital Downloads Extensions for Your WordPress Site
Inheritance and Extending Objects With JavaScript
/Performant Animations Using KUTE.js: Part 5, Easing Functions and Attributes
Performant Animations Using KUTE.js: Part 2, Animating CSS Properties
Performant Animations Using KUTE.js: Part 1, Getting Started
/Single-Page Applications With ngRoute and ngAnimate in AngularJS
/How to Set Up a Scalable, E-Commerce-Ready WordPress Site Using ClusterCS
/Building With Vue.js 2 and Firebase
4 /Essential JavaScript Libraries and Frameworks You Should Know About
Build a React App With a Laravel RESTful Back End: Part 1, Laravel 5.5 API
Bulk Import a CSV File Into MongoDB Using Mongoose With Node.js
Learn Computer Science With JavaScript: Part 3, Loops
/Learn Computer Science With JavaScript: Part 2, Conditionals
/Create Interactive Charts Using Plotly.js, Part 5: Pie and Gauge Charts
/Create Interactive Charts Using Plotly.js, Part 4: Bubble and Dot Charts
Create Interactive Charts Using Plotly.js, Part 3: Bar Charts
/Create Interactive Charts Using Plotly.js, Part 2: Line Charts
/Create Interactive Charts Using Plotly.js, Part 1: Getting Started
Getting Started With End-to-End Testing in Angular Using Protractor
/Object-Oriented Programming With JavaScript
/Testing Components in Angular Using Jasmine: Part 2, Services
/Testing Components in Angular Using Jasmine: Part 1
/Creating a Blogging App Using React, Part 6: Tags
/React Crash Course for Beginners, Part 2
/Set Up a React Environment, Part 4
1 /New Course: Get Started With Phoenix
/How to Create a Real-Time Feed Using Phoenix and React
/Pagination in CodeIgniter: The Complete Guide
/JavaScript-Based Animations Using Anime.js, Part 4: Callbacks, Easings, and SVG
JavaScript-Based Animations Using Anime.js, Part 3: Values, Timeline, and Playback
JavaScript-Based Animations Using Anime.js, Part 2: Parameters
JavaScript-Based Animations Using Anime.js, Part 1: Targets and Properties
20 Popular WordPress User Interface Elements
/Getting Started With Matter.js: The Composites and Composite Modules
/Getting Started With Matter.js: The Engine and World Modules
10 More Popular HTML5 Projects for You to Use and Study
/Iterating Fast With Django & Heroku
/Creating a Blogging App Using React, Part 4: Update & Delete Posts
How to Register & Use Laravel Service Providers
/Unit Testing in React: Shallow vs. Static Testing
/Creating a Blogging App Using React, Part 3: Add & Display Post
Creating a Blogging App Using React, Part 1: User Sign-In
/Creating a Grocery List Manager Using Angular, Part 2: Managing Items
/Using Celery With Django for Background Task Processing
/Creating a Grocery List Manager Using Angular, Part 1: Add & Display Items
What Is a JavaScript Operator?
/Building Your Startup: Approaching Major Feature Enhancements
Dynamic Page Templates in WordPress, Part 2
/Dynamic Page Templates in WordPress, Part 1
/How to Draw Bar Charts Using JavaScript and HTML5 Canvas
/What Is WP-CLI? A Beginner’s Guide
/How to Zip and Unzip Files in CodeIgniter
/Programming With Yii2: Building Community With Voting, Comments, and Sharing
12 Best Tab & Accordion WordPress Widgets & Plugins
/How to Create Animations in AngularJS With ngAnimate
/AngularJS Form Validation With ngMessages
/15 Best PHP Calendar, Booking & Events Scripts
/Using the Twitter API to Tweet Repetitive Content
/Getting Started With Chart.js: Scales
/Building Your Startup: Leveraging Bootstrap, Ajax, and jQuery
How to Create a Laravel Helper
/Getting Started With Chart.js: Pie, Doughnut, and Bubble Charts
Getting Started With Chart.js: Radar and Polar Area Charts
/Getting Started With Chart.js: Line and Bar Charts
/Building Your Startup With PHP: Bootstrap Your Home Page
/How to Build a User Tour With Shepherd in JavaScript
/Building With the Twitter API: Analyzing Your Followers
/Programming With Yii2: Building a RESTful API
/Uploading With Rails and Carrierwave
/Uploading Files With Rails and Dragonfly
/Making a Sliding Side Navigation Menu for Responsive Designs
/Building With the Twitter API: Creating Friends to Follow
/Using the Requests Module in Python
5Acuity Scheduling Developer Platform: OAuth, Webhooks, and Reporting
/Acuity Scheduling: Embedding and Developer Integration
/Custom Controllers in OpenCart 2
/Make Creating Websites Fun Again With Hugo
/Authentication in Rails Using Clearance
/Using Illuminate Database With Eloquent in Your PHP App Without Laravel
New Coffee Break Course: How to Use the Angular 2 HTTP Service
Get Started Building Your Blog With Parse.js: Migration to Your Own Parse Server
/Building Your Startup: Automatic Time-Zone Detection
/Adding Custom Fields to Simple Products With WooCommerce
/Using Namespaces and Autoloading in WordPress Plugins, Part 4
New Code eBooks Available for Subscribers
/Understanding Forms and Events in React
/How to Build an Angular 2 Service
7Programming With Yii2: Using the Debugger
/Creating a Custom WordPress Messaging System, Part 4
/Uploading Files With Rails and Shrine
/New Course: Build a REST API With Laravel
/Creating a Custom WordPress Messaging System, Part 2
/Programming With Yii2: Routing and URL Creation
/Processing Forms With phpPress, goPress, rubyPress, and nodePress
Getting Started With Raygun: Insights and Crash Reporting for App Developers
/New Course: How to Use the Google Drive API
/Using Namespaces and Autoloading in WordPress Plugins, Part 3
Programming With Yii2: Using Ajax
6 /Getting Started With the Asset Pipeline, Part 2
/New Coffee Break Course: First Look at Slim PHP
1Using Namespaces and Autoloading in WordPress Plugins, Part 1
10 Best WordPress Facebook Widgets
13Internationalizing WordPress Projects: Updates With WordPress 4.6
Building RESTful APIs With Flask: An ORM With SQLAlchemy
/
tammie I am sure this piece of writing has…