Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Creating a custom taxonomy index page

From: Create an Online Portfolio with WordPress

Video: Creating a custom taxonomy index page

By default when you click on a custom taxonomy link, WordPress will use the index.php template to display the output. If you want to customize the index view for a taxonomy, you need to create a custom taxonomy template. Like with the custom posts type indexes, this is a simple matter of creating a new file called taxonomy.php, and populating it with the contents you want to use. Before we create the file, let me just show you what I am talking about. If I go to any of my posts and I click on one of the custom taxonomy terms, I will be taken to a general index for that term.

Creating a custom taxonomy index page

By default when you click on a custom taxonomy link, WordPress will use the index.php template to display the output. If you want to customize the index view for a taxonomy, you need to create a custom taxonomy template. Like with the custom posts type indexes, this is a simple matter of creating a new file called taxonomy.php, and populating it with the contents you want to use. Before we create the file, let me just show you what I am talking about. If I go to any of my posts and I click on one of the custom taxonomy terms, I will be taken to a general index for that term.

As you can see, we are now under the meal -type custom taxonomy and I am looking at everything that's filed under the term dinner. The problem is by default the title of this page is Blog Archives. It's hardly a blog archive. And in addition, each of these polls types, though they come from different kinds of custom post types, just display the same. What I want to do is change the Blog Archive's title to something more fitting like filed under: and then the actual term, and also add the description for each of the terms, because sometimes you can add a description to a term.

And I want each of these posts to also display what kind of post type it is, so that people know that this is a video, this is a photo, and this is a recipe. But first thing's first. We need to create the new taxonomy template. I will go to my code editor and here we already have this archive-recipes file that we created before, which is the index file for archive recipes. I am going to use this as the base and just make some subtle changes to it. So I will simply take the file and save it under a different name.

So I will change the name to taxonomy.php and now if I make any changes, those changes will only apply to the taxonomy index. Here, I can make a change to the title of the page itself. You remember, this one says the name of the post type, but now I want to display filed under: and then the name of the term. So I will go to my code snippets and here at the very top you find a new h1 class page-title that we can copy and paste it in place of the old one.

This one if we read it says Filed Under and then it inserts single_cat_title, which is the title for the current category or the term. So in our case, because we had dinner open, it should now say Filed Under Dinner. I will save the taxonomy.php file, go back to my browser and reload this page. And now it says Filed Under Dinner at the very top here. That's exactly what I wanted. The next step is to add the category description.

Now, if you go to WordPress Admin and you open one of your taxonomies, you will see that in addition to a title you can also give each taxonomy term a description. I have given Dinner a description here. It just says "Dinner is the most important meal of the day except of course for breakfast," and I want that to display directly under the term itself. So I will go back to my code snippets and I will copy out this batch of code. It starts with the php delimiter ends with the php delimiter. So I will copy that and place it directly after the h1, before the header ends.

This batch of code looks for the category description and then says if the category description is not empty, meaning if there is a category description, then display the category description. So I can save this, reload the page in my browser, and now you see in addition to saying Filed Under Dinner, it also says "Dinner is the most important meal of the day, except of course for breakfast," and this text will change if you add descriptions to other terms.

Finally, I want to change the loop so that inside the loop we display the post type under each of the post titles. We can do this in a couple of different ways. We can approach it the same way we did previously by now creating a new file called contents-taxonomy and then call it that way. However, in our case, with the taxonomies, all the taxonomy displays are going to be the same. Therefore, it's not necessary to have this external file we are going to call in. So instead, I am going to go to concert-archive, which already has all the content I need. I am going to highlight all of that content and copy it.

Then I am going to go back to taxonomy. php, find where content-archive is called. It's right here. Display the call to that item and instead paste in the code itself. Now I have a complete file and taxonomy.php contains all the template information for this display. That also means I can make changes to it without disturbing the content display for regular index pages. So now, because I want to add type of post underneath the title, I first need to find the title.

It's right here, entry-title. And then I can add the code to display the current post type directly underneath. So I will go back to the code snippets and get the final batch of code, and I will copy it first and then I will explain it afterwards. So I will paste it in and then I will explain what happens here. Of course, first it says post_type: and that it spells out what's going on. Now, I had to make a custom function to bring out the post type name, because it doesn't do that by default.

So this is a simple function that first creates a new object, which is called object, and then in that object I put in the current post type object, and I display the singular_name of that object. This is highly technical, but the end result is exactly what we need, which is why it works. If I save this now and reload my page, you will see under each of these posts we now have post type and then the name of the post type.

So here it says Post type: Video, here it says Post type: Photo, and here it says Post type: Recipe. Like with custom post type templates and custom post type indexes, you can also make custom taxonomy indexes targeting specific taxonomies, or even specific terms. You do that by calling the files taxonomy- and then whatever you are targeting. It works the exact same way and you can get extremely specific about what you're targeting and how to display certain types of content. But for the most part what I just showed you, this consolidation of all the taxonomy terms in one single file, works the best.

Using custom taxonomy index templates you can control exactly how different taxonomies are displayed and customize the output to show exactly what the visitor is looking for. This is yet another tool in your tool belt of WordPress awesomeness.

Show transcript

This video is part of

Image for Create an Online Portfolio with WordPress
Create an Online Portfolio with WordPress

40 video lessons · 28573 viewers

Morten Rand-Hendriksen
Author

 
Expand all | Collapse all
  1. 6m 28s
    1. Welcome
      58s
    2. Using the exercise files
      3m 54s
    3. Using the code snippets file
      1m 36s
  2. 8m 31s
    1. What is an online portfolio?
      2m 43s
    2. Tour of the finished project
      3m 15s
    3. Setting up a WordPress development environment
      2m 33s
  3. 16m 10s
    1. Creating site architecture
      5m 1s
    2. Creating a child theme
      6m 7s
    3. Creating an external file to manage functions separately from the theme
      5m 2s
  4. 25m 26s
    1. What is a custom post type?
      2m 14s
    2. Setting up a custom post type
      6m 39s
    3. Adding advanced variables to the custom post type
      3m 35s
    4. Advanced custom post type functionalities
      4m 29s
    5. Changing the menu position of the custom post type
      3m 19s
    6. Adding a custom post type icon
      5m 10s
  5. 22m 8s
    1. What are custom taxonomies?
      3m 34s
    2. Setting up a basic custom taxonomy
      2m 52s
    3. Hooking a custom taxonomy to a post type
      3m 13s
    4. Adding advanced variables to a custom taxonomy
      3m 9s
    5. Using hierarchical and nonhierarchical custom taxonomies
      5m 54s
    6. Using custom taxonomies in admin
      3m 26s
  6. 25m 40s
    1. Populating content into the custom post types
      10m 54s
    2. Uploading videos to YouTube
      2m 22s
    3. Embedding YouTube videos in a custom post type
      4m 23s
    4. Uploading videos to WordPress
      8m 1s
  7. 39m 47s
    1. Creating custom post type templates
      6m 50s
    2. Adding taxonomy info to the custom post type template
      9m 13s
    3. Creating conditional custom taxonomy links
      4m 46s
    4. Handling multiple post type templates: Individual templates
      6m 25s
    5. Handling multiple post type templates: Consolidating everything in one file
      6m 21s
    6. Handling multiple post type templates: Making custom post types the default
      6m 12s
  8. 15m 23s
    1. Creating an index page for a custom post type
      8m 10s
    2. Creating a custom taxonomy index page
      7m 13s
  9. 12m 3s
    1. Creating a custom footer sidebar template
      6m 58s
    2. Displaying a list of links to the latest custom post type posts
      5m 5s
  10. 14m 58s
    1. Creating static pages for the front and the blog
      4m 54s
    2. Populating the menu with new index pages
      4m 52s
    3. Creating a contact page with a contact form
      5m 12s
  11. 5m 55s
    1. Including the abstraction layer in other stock themes
      5m 55s
  12. 1m 22s
    1. Next steps
      1m 22s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Create an Online Portfolio with WordPress.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.