How To Build A Media Site On WordPress (Part 2)

Advertisement

The default “category” and “tag” taxonomies in WordPress offer a lot of flexibility to those with imagination and in my development experience I have seen a wide range of creative implementations. With the introduction of custom taxonomies and their growing ease of use, though, we need no longer be bound to categories and tags. With the ability to create both hierarchical and non-hierarchical taxonomies and with the introduction of several new features in WordPress 3.1, now is the time, if you’re not already, to begin putting custom taxonomies to use.

In part one1 of this two part series, we learned how to setup custom post types and custom taxonomies. We also learned how to build a template to check for and display media attached to custom posts. Now, we’ll learn how to use custom taxonomy templates to organize and relate our media. Let’s get started!

Screenshot

Organizing Our Media – Working With Custom Taxonomy Templates

Now that we have our media displaying, it’s time to work on how it’s organized. If you tried clicking on one of the custom taxonomy terms, odds are the result weren’t very exciting. You probably saw something like this:


A rather unhelpful default view of a term in the “presenter” taxonomy.

What we’re going to do next is create a template that allows us to customize the results and offer a page that will be more useful.

Creating A Custom Taxonomy Template

As with custom posts, the WordPress template engine has a custom taxonomy template hierarchy2 that it follows to determine what template it uses to display data associated with a custom taxonomy term. We’ll start with our “presenters” taxonomy. In our case, the WordPress hierarchy is as follows:

  • taxonomy-presenters.php – WordPress will check the theme folder for a file named taxonomy-presenters.php. If it exists, it will use that template to display the content. For different custom taxonomies, simple replace “presenters” with the name of your custom taxonomy.
  • taxonomy.php - If no custom taxonomy template is found, WordPress checks for a general taxonomy template.
  • archive.php – If no general taxonomy template is used, the WordPress archive template is used.
  • index.php – If no archive template is found, WordPress defaults to the old standby – the index.

Note: The WordPress template hierarchy structure also allows templates for specific terms. For instance, in a case where “Jonathan Wold” was a term in the “presenters” taxonomy, I could create a custom template called “taxonomy-presenters-jonathan-wold.php”.

Non-Hierarchical Custom Taxonomy Templates

We’ll start with the non-hierarchical “presenters” custom taxonomy. As with the custom post type examples previously, I will be using minimal examples for each of the templates.

To get started with this example, create a file called taxonomy-presenters.php and upload it to your theme folder. Add the following code:

<?php get_header(); ?>

<?php // Get the data we need
   $presenter = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
?>

   <div id="container">
      <div id="content" class="presenter">
         <h1 class="entry-title"><?php echo $presenter->name; ?></h1>
         <p><?php echo $presenter->description; ?></p>
      </div>
   </div>

<?php get_footer(); ?>

Previewing a term should now show you a rather empty page with the name of the term and the description (if you entered one when creating or editing the term). In my case, on Twenty Ten, accessing the term “Jonathan Wold” (/presenter/jonathan-wold) looks like this:


A rather basic, yet more useful, view of a custom taxonomy term template.

Before moving on, let’s review the code above to learn what it’s doing and what you can do with it.

$presenter = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );

This piece of code may seem intimidating at first, but it’s rather simple. First, we are defining a variable called $presenter. Our goal is to have that variable store everything that WordPress knows about our term.

To do that, we are using the function get_term_by3. That function requires three things:

  1. Field – You can access a term by name, ID, or slug. In our case, we are using the slug, which is “jonathan-wold”.
  2. Value – We’ve told WordPress that we want to get our term data by using the “slug” field. Now, it needs a slug to retrieve data. Since we want this to be dynamic, we are using another function called get_query_var4. When you access a term in WordPress (e.g. viewing a term by its permalink), a query is run in order to generate the results for that term. Using “get_query_var” allows you to intercept that query and get the data for your own use.
  3. Taxonomy – In addition to the term slug, WordPress also needs the taxonomy name (this is critical in cases where the same name is used across multiple taxonomies). We use “get_query_var” again to retrieve that for us.

If we wanted to access the term data for one specific term in a particular custom taxonomy, we would do it like this:

$presenter = get_term_by( 'slug', 'jonathan-wold', 'presenters');

In our example, we are adding code into our template telling WordPress to give us the data for the term a visitor is currently viewing. WordPress stores that data as an “object”.

To see what data is available to you in an object, add the following within your code:

<?php
   echo '<pre>';
   print_r( $presenter );
   echo '</pre>';
?>

Preview the term again and you should see a block of code that looks something like this:

Screenshot5
An easily readable view of the object attributes and values.

That block of code lets you see what WordPress knows about your particular object and what information you have available to use within your template.

Note: In part one, I referenced a technique for adding custom fields to your custom taxonomies and giving you access to more data within your templates. Just incase you missed the reference, take a look at the advanced tutorial, How To Add Custom Fields To Custom Taxonomies6, on the Sabramedia blog.

Displaying Object Data In Templates

Now, let’s look at how we took the data from that object and actually displayed it in the template. Let’s start with the first example:

<?php echo $presenter->name; ?>

In English, we are telling PHP to “echo”, or display, the “name” value of the $presenter object. We would know that the object created with “get_term_by” contains the value for “name” by either looking up the return values for get_term_by in the Codex7 or by using “print_r” to see for ourselves. We’ll explore this in more detail once we look at the “topics” taxonomy.

To get our description, we do the same thing, changing the “name” value to “description”:

<?php echo $presenter->description; ?>

Displaying Term Results In Custom Taxonomy Templates

Now that we have our term name and description displaying, it’s time to show some actual custom post results.

We are continuing our example with taxonomy-presenters.php. Replace the existing code with the following:

<?php get_header(); ?>

<?php // Get the data we need
   $presenter = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );

   $resources = new WP_Query(
      array(
         'post_type' => 'resource', // Tell WordPress which post type we want
         'posts_per_page' => '3', // Show the first 3
         'tax_query' => array( // Return only resources where presenter is listed
            array(
               'taxonomy' => 'presenters',
               'field' => 'slug',
               'terms' => $presenter->slug,
               )
            )
         )
      );
?>

   <div id="container">
      <div id="content" class="presenter">
         <h1 class="entry-title"><?php echo $presenter->name; ?></h1>
         <p><?php echo $presenter->description; ?></p>

         <div class="resources">
            <h3>Latest Resources</h3>
            <ul id="resource-list">
               <?php while ( $resources->have_posts() ) : $resources->the_post(); ?>
                  <li id="resource-<?php the_ID(); ?>" class="resource">
                     <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                     <span><?php the_excerpt(); ?></span>
                  </li>
               <?php endwhile; ?>
            </ul>
         </div>   

      </div>
   </div>

<?php get_footer(); ?>

Previewing one of your terms should now display the name and description of the term along with a list of custom posts associated with that term. In our case, the results look like this:


With a customizable list of related custom posts, the term results template is looking much more useful.

The update to this code block is the addition of our “$resources” query. Let’s take a look at that more closely:

$resources = new WP_Query(
   array(
      'post_type' => 'resource', // Tell WordPress which post type we want
      'posts_per_page' => '3', // Show the first 3
      'tax_query' => array( // Return resources associated with presenter
         array(
            'taxonomy' => 'presenters',
            'field' => 'slug',
            'terms' => $presenter->slug,
            )
         )
      )
   );

For our variable of $resources, we are creating a new instance of the WordPress class, WP_Query8. Then, we’re setting values on several parameters, post_type9, post_per_page10, and tax_query11.

The first two are straight forward. With “post_type”, you let WordPress know which types of content you’re wanting to return. We used that in our media example to retrieve attachments. To display multiple posts types, replace the “post_type” line with this:

'post_type' => array( 'resource', 'other_post_type', 'another_post_type' ),

For “posts_per_page”, you are letting WordPress know how many posts to return before triggering pagination. If you want to return all posts, use “-1″ for the value, like this:

'posts_per_page' => '-1', // Show all the posts

Now, “tax_query” is a new parameter added in WordPress 3.112. It is a powerful parameter that lets you return results associated with multiple taxonomies and custom fields.

Let’s take a closer look at it:

'tax_query' => array( // Return resources associated with presenter
   array(
      'taxonomy' => 'presenters',
      'field' => 'slug',
      'terms' => $presenter->slug,
      )
   )

First, we choose our custom taxonomy. In our case, we are hardcoding in “presenters”. If we wanted to make it more dynamic and build, for instance, a general taxonomy template (taxonomy.php) to handle multiple taxonomies in a similar way, we would use “get_query_var” again, like so:

'taxonomy' => get_query_var( 'taxonomy' ),

Note: The “tax_query” function works with one taxonomy at a time. To query multiple taxonomies, simply duplicate the code above (be sure to add the appropriate comma at the end) and change the parameters accordingly.

Next, we have the “field” parameter. This lets WordPress know what field we will be returning our terms by. WordPress accepts “slug” or “id”. I am using “slug” because I prefer recognizing posts by words over numbers.

Then, we have “terms”. In our case, we are using the $presenter variable to pass in the “slug” in the same way we added data directly into our custom post template. If we wanted to make it more dynamic, we could use “get_query_var” again:

'term' => get_query_var( 'term' ),

If we want to return results for multiple terms, we add an array, like this:

'term' => array( 'term_1', 'term_2', 'random_other_term' ),

To modify our results further, we can use an optional “operator” parameter that allows us to specify whether our results are “IN”, “NOT IN”, or “OR”. A simple example, appropriate for use in a single taxonomy, is “NOT IN”.

To modify the query to return results that are “NOT IN” the custom taxonomy and terms that you’ve listed, add the following within your tax_query array:

'operator' => 'NOT IN',

Note: To experiment with results queried against multiple custom taxonomies, take a look at “Multiple Taxonomy Handling” under Taxonomy Parameters13 on the Codex reference for WP_Query.

Now that we’ve gone through that, we reference our newly created query with a loop. Here’s the code again:

<div class="resources">
   <h3>Latest Resources</h3>
   <ul id="resource-list">
      <?php while ( $resources->have_posts() ) : $resources->the_post(); ?>
         <li id="resource-<?php the_ID(); ?>" class="resource">
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            <span><?php the_excerpt(); ?></span>
         </li>
      <?php endwhile; ?>
   </ul>
</div>

This is another basic instance of The Loop14, customized to return results from our $resources query and, in this case, the results returned are “the_ID”, “the_permalink”, “the_title”, and “the_excerpt”.

Checking For Empty Results

In our example above, we have some code (like the <UL>) that appears outside of our loop. If there were no results, the “container” HTML would still show up in the template. To prevent that, we can preface it with a conditional statement like this:

<?php if ( $resources->post_count > 0 ) { // Check to make sure there are resources ?>
// Display your results
<?php } ?>

Replace “$resources” with the name of your custom query and return your results within the conditional statement. If the “post_count” is greater than zero (“> 0″), then the code will appear in your template – otherwise, the page remains free of extra HTML.

Hierarchical Custom Taxonomy Templates

Alright, now that we have a non-hierarchical taxonomy under our belt, let’s move on and tackle hierarchy. We covered the basics in setting up “presenters”, so let’s pick up there where we left off.

Create a file called taxonomy-topics.php and add the following code:

<?php get_header(); ?>

<?php // Get the data we need
   $topic = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );    

   $resources = new WP_Query(
      array(
         'post_type' => 'resource', // Tell WordPress which post type we want
         'posts_per_page' => '3', // Show the first 3
         'tax_query' => array( // Return only resources where presenter is listed
            array(
               'taxonomy' => 'topics',
               'field' => 'slug',
               'terms' => $topic->slug,
               )
            )
         )
      );
?>

   <div id="container">
      <div id="content" class="presenter">
         <h1 class="entry-title"><?php echo $topic->name; ?></h1>
         <p><?php echo $topic->description; ?></p> 

         <?php if ( $resources->post_count > 0 ) { // Check to make sure there are resources ?>
            <div class="resources">
               <h3>Latest Resources</h3>
               <ul id="resource-list">
                  <?php while ($resources->have_posts()) : $resources->the_post(); ?>
                     <li id="resource-<?php the_ID(); ?>" class="resource">
                        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                        <span><?php the_excerpt(); ?></span>
                     </li>
                  <?php endwhile; ?>
               </ul>
            </div>
         <?php } ?>

      </div>
   </div>

<?php get_footer(); ?>

Previewing a “topic” should now give you a familiar plain template that looks something like this:


A basic, yet useful view of another custom taxonomy term.

Creating Parent and Children Links

Now, the thing that is different with this taxonomy is that it can have both “parents” and “children”. What we want to do is check for a parent topic and, if it exists, display a link to it. We also want to check for sub-topics and if they exist, display links to them.

Note: For these examples to work, be sure that you’re working with a post example that has multiple levels of a hierarchical custom taxonomy associated with it. In my example, I have created topics 3 levels deep and associated all of them with the post.

So let’s get started. First, within the PHP section at the top of our template, add the following code:

if ( $topic->parent > 0 ) { // Check to make sure the topic has a parent
   $topic_parent = get_term( $topic->parent, 'topics' ); // Get the object for the topic's parent
}  

$topic_children = get_terms( 'topics', 'child_of='.$topic->term_id );
$last_topic = end( array_keys( $topic_children ) ); // Mark the last topic

Alright, what do we have going on here? First, we’re checking to make sure the topic has a parent. If a topic does not have a parent, WordPress gives the “parent” attribute a value of zero (“0″). So, the first thing we do is a conditional to check and make sure that the parent has a value greater than zero. If it does, we define the variable $topic_parent and use the get_term function15 to retrieve the parent topic based on its ID.

Next, we define another variable called $topic_children. This time, we use the get_terms function16, which has a special attribute called “child_of”. We pass in the value of the current topic and tell WordPress, in English, to “take the current topic and bring me back a list of all its sub-topics or children”.

Then, we define a variable called $last_topic. The data that $topic_children gives us is in the form of an array. Our $last_topic variable counts to the “end” of the array and keeps track of it. We’re going to use that later to put a comma after each of our sub-topics and then do nothing for the last sub-topic.

Now, to show the results, add the following code within your template:

<?php if ( $topic->parent > 0  ) { ?>
<strong>Parent:</strong> <a href="<?php echo get_term_link( $topic_parent->slug, 'topics' ); ?>"><?php echo $topic_parent->name; ?></a>
<?php } ?>

<?php if ( $topic_children ) { ?>
   <strong>Subtopics: </strong>
   <?php foreach ( $topic_children as $key => $topic_single ) : ?>
      <span><a href="<?php echo get_term_link( $topic_single->slug, 'topics' ); ?>"><?php echo $topic_single->name; ?></a></span><?php if ( $key !== $last_topic ) echo ', '; ?>
<?php endforeach; ?>
<?php } ?>

Each block of code first checks to make sure that a parent topic or sub-topic(s) exists, respectively. Then, in the case of the “parent”, we use the get_term_link function17 to retrieve the link by the “slug” of the $topic_parent.

For our sub-topics, we create a “foreach” loop to output a list of all sub-topics. At the end, we do a conditional check on the $last_topic in our array using the variable we created earlier. If it is not the last topic, we echo a comma after the close <span> – otherwise, we do nothing.

And there you have it! The result using the Twenty Ten theme will look something like this:


A view of the “topics” taxonomy, with the parent topic and sub-topics listed.

Relating Taxonomies By Posts

Now, this is where we get a bit fancy. Let’s say we’re working on our template for the “topics” taxonomy and we wanted to show a list of “presenters” who covered that particular topic. How would we do that? In the code that follows, we’re going to use the custom posts themselves as our reference point and bring back the related custom taxonomies.

The rationale is simple. If we had 10 posts associated with a particular term in a given custom taxonomy, those 10 posts will likely have other terms from other custom taxonomies associated with them as well. So, we use the posts themselves to retrieve and compile the term data that would otherwise not be related to our particular term. Here are some examples where this might be especially useful:

  • Events - An “event” taxonomy where we want to show a list of “presenters” at that same event.
  • Movies - A “genre” taxonomy where we want to show a list of “directors” who make that same genre of film.
  • Recipes - A “category” taxonomy where we want to show related “ingredients”.

Alright, let’s dive into the code:

// Retrieve all the IDs for resources associated with the current term
$post_ids = array();
foreach ( $resources->posts as $post ) {
   array_push( $post_ids, $post->ID );
}

// Get presenter data based on the posts associated with the current term
$presenters_by_posts = wp_get_object_terms( $post_ids, "presenters" );

$topic_presenters = array();
foreach ( $presenters_by_posts as $presenter ){
   $topic_presenters[$presenter->term_id] = $presenter;
}
$last_presenter = end( array_keys( $topic_presenters ) );

First, we define an empty array called $post_ids. Then, we create a loop through each of the “resources” associated with our current term using the $resource query we created earlier. We take that loop and “push” each of the post IDs for our resources back into the previously empty $post_ids array.

Next, we define a new variable, $presenters_by_posts. We use the wp_get_object_terms function18, which accepts either a single ID or an array of IDs (which we just created) to return a list of terms. In our case, we’re using this function to check all the custom posts associated with this term and bring back a list of all the “presenters”.

Next, we define another empty array called $topic_presenters. We now loop through our $presenters_by_posts and then redefine our $presenter variable to hold the term_id of each $presenter that we returned using our $presenters_by_posts function.

Now, let’s make use of that in the template. Add the following the code:

<?php if ( $topic_presenters ) { ?>
   <strong>Presenters:</strong>
   <?php foreach ( $topic_presenters as $key => $presenter ) : ?>
      <span><a href="<?php echo get_term_link( $presenter->slug, 'presenters' ); ?>"><?php echo $presenter->name; ?></a></span><?php if ( $key !== $last_presenter ) echo ', '; ?>
   <?php endforeach; ?>
<?php } ?>

Now, we simply loop through each of our $topic_presenters using our redefined $presenter. We then access the attribute values of our $presenter object to echo the “slug” for the term link and the term “name”. Finally, we do a check for the $last_presenter and if it is not the last one, we echo a comma.

Here’s how that looks in my example:


The updated view of “Topics”, with a list of presenters related by custom posts.

Conclusion

And that’s a wrap! With part one and part two under your belt you have taken some solid steps above and beyond the basics of WordPress theme development. My goal has been to give you some solid examples that you can follow and to explain what’s been done along the way so you can apply what you’ve learned to your own projects. You’ve learned a lot about custom post types and custom taxonomies and I am looking forward to seeing what you build.

My next area of interest is a tutorial that teaches best practices for customizing the WordPress admin and building new backend interfaces for end-users to manage these increasingly complex media sites. I’m also interested in writing about how to build the front-end filtering interface, demonstrated in the ARISE resource center19. If either of those interest you, please let me know.

Credits

As I mentioned in part one, the WordPress Stack Exchange20 community has been a huge help in sharing techniques and pointing out best practice solutions. If you have a question directly related to this post, ask it here. If you have anything else WordPress related, though, be sure to check out WPSE Also, a big thank you to all my team mates at Sabramedia21 for their patience with me and all their help testing and providing feedback.

↑ Back to topShare on Twitter

Jonathan Wold is the husband of a beautiful redhead named Joslyn and the father of a baby boy named Jaiden. He works at Sabramedia, a web design and development company that specializes in WordPress powered media sites. He is also a core developer and evangelist for Newsroom, a newspaper paywall and CMS built for the newspaper industry.

  1. 1

    Another awesome tutorial I have to try. Thanks Jonathan

    0
  2. 2

    Everything about Smashing Magazine oozes with professionalism, and this time – once again – it is no different. I am amazed, and so happy, to see such quality tutorials. This is like the pot of gold at the end of my WordPress development rainbow, you make it so much simpler to grasp. Thank you!

    0
  3. 3

    Thank you!
    Alas, I am still stuck with the previous post – I can create Resources, and edit them, but they are not displayed, and when I ask wordpress to show them to me, he can’t find them.. is this because my blog is in Hebrew?

    0
    • 4

      Hey Noga, sorry to hear you’re having trouble! The language of the site shouldn’t affect whether or not your post displays. Have you tried updating your Permalinks?

      0
      • 5

        Thanks Jonathan. How do I do that?

        0
        • 6

          For some reason I have to manually edit the post’s location, and it shows me the post, but the player doesn’t work.

          0
          • 7

            Noga, are you still having trouble? For the player itself, view the source code and check the URLs for the JW Player files – make sure they are properly referenced. That’s the first place to start and will probably resolve your trouble.

            0
  4. 8

    Thanks for this great tutorial! I’m fairly new to WordPress but the custom taxonomy template is going to aid our additional sections as we develop our blog further

    0
  5. 9

    Amazing, I had no idea word press could be so cool!

    0
  6. 10

    This is definitely what I am most interested in ;).

    “how to build the front-end filtering interface, demonstrated in the ARISE resource center. If either of those interest you, please let me know.”

    Screen cast would be even more awesome than your current tutorials as well, thanks for your great efforts in sharing!

    0
    • 11

      John, thank you for feedback and interest in the next tutorial! We’ve got a project or two coming up that will give us opportunity to develop our jQuery plugin further and about that time I’ll look again at writing a tutorial and releasing it for general use. Keep an eye out for it in the coming months!

      0
      • 12

        that would be awesome to have this next tutorial for the front-end filtering interface !

        0
  7. 13

    Jonathon,

    Both your posts were very helpful – thanks! This is the first time I’ve really understood custom post types, how to set them up, and what they can do.

    I’d be interested in either of those topics, but would probably like to see customizing the admin interface first as this is a problem I’m starting to come up against, particularly on a magazine project I’m developing now which will have many different authors with a lot of different input.

    Best,

    Tim

    0
    • 14

      Tim, thank you for your feedback! I’m very glad to hear that I was able to help you grasp custom post types better. That was my goal! I am working on an admin interface heavy project right now and, with that wrapped up, that will probably be the next tutorial that I write. Keep your eyes open for that.

      0
  8. 15

    Mark "Chief Alchemist" Simchock

    June 8, 2011 12:21 pm

    Wow. My brain is a bit sketchy at the moment. I’ll have to come back and read this again in detail when the grey sponge is in better shape.

    FWIW, I suggest checking out XYDAC’s Ultimate Taxonomy Manager

    http://taxonomymanager.wordpress.com/

    What’s hot is the custom fields can be setup to store HTML. For example, you could have a term called Sponsor and a custom field called Sponsor_bio. The bio need not be uniform across all Sponsors. Instead you can place a snippet of markup in the custom field and use that to display the bio when a given sponsor is taxonomy’ed to a given post.

    That’s just the tip of the iceberg :)

    0
  9. 17

    Suddenly inspired!

    June 8, 2011 2:15 pm

    This is me when I see a new article posted at Smashing Magazine: http://bukk.it/pig-yay.gif

    0
  10. 19

    Just to say this series of posts is really great. I’ve been looking at getting into wordpress development (at the moment I just to custom php), and I needed something like this to get me started. I eagerly await the admin post!

    Nico

    0
    • 20

      Nico, I’m glad I was able to help get you started! Press ahead my friend, there are a lot of great resources out there. If you hit a wall, try WordPress Stack Exchange. Keep up the good work!

      0
  11. 21

    good article this is what i am looking for

    0
  12. 23

    Deuce Creative

    June 9, 2011 3:07 am

    Thanks for a great couple of articles Jonathan, very useful! Really looking forward to hearing more about how you built the front-end filtering interface for your ARISE resource center as it looks and works great! So +1 for that as the next article topic! :)

    0
    • 24

      You are very welcome and I’m glad to hear they were useful to you. As I mentioned in an earlier comment, we have a project or two coming up that will make heavy use of that filtering plugin we’re developing and with those projects complete, we plan to turn our attention to releasing the plugin and writing a tutorial to go with it. Thank you for your interest in it and keep your eyes open over the next few months.

      0
  13. 25

    Hi Jonathan,

    Def-o. Keep writing more tutorials.

    I had used custom post types with some success already, but these two posts highlight so much I have overlooked. Well written and easy to follow.

    Cheers.

    0
    • 26

      Thank you, Andy! I enjoy the writing, though finding the time is a challenge. It’s worth the effort, though, and I’m happy to hear that you found the tutorials useful.

      0
  14. 27

    Nice once again Jonathan. We need more of these type articles and projects to really show the light of WP as a CMS. Thanks again, and I’ll be checking back here often for reference!

    0
    • 28

      Thank you, Evan. I had hoped to turn this series into a good reference point and I’m glad to hear folks using it as such. Please feel free to comment down the road and leave a reference to work you’ve built where the tutorial has helped!

      0
  15. 29

    WordPress is overestimated.

    0
  16. 30

    well done father of triple J family. I’d like to bookmark this post as a resource.
    (after a short while..)
    well done sonny for bookmarking : )

    0
  17. 32

    I’m very interested in the front-end filtering interface how-to!

    0
  18. 34

    yes, front-end filtering interface tutorial would be interesting,
    thanks for the great tuts Jon :)

    0
  19. 35

    Hi thanks for the tutorial. I have problem following the tutorial. My taxonomy-presenters.php is not being displayed. When I click on the presenters name, WordPress displays the default 2010 theme post. If I delete that post it displays a ‘Not Found’ page. Any ideas what I may have wrong? Thank you in advance.

    0
  20. 36

    Resolved my issue. I used the Themergency custom Taxonomy Generator wich includes the add_action( ‘init’, ‘register_taxonomy_topic’ ); which seems to be missing from your code?

    0
  21. 37

    Very helpful stuff, thank you!

    looking forward to see front-end filtering interface tutorial.

    Thanks,
    Anton

    0
  22. 38

    WordPress is growing up. its becoming a lot like drupal . how fun

    0
  23. 39

    cool, stof , you rock..

    0
  24. 40

    AMAZING TUTORIAL – Thanks so much… I wondered if you might be able to help me out on how to do wp_get_archive() for a particular custom post type only? Having some real problems finding any snippets on how to do this online? Thanks in advance.

    Adam

    0
    • 41

      So i sorted it out but in the hackiest way imaginable – basically building the archive myself for the custom post type… If anyone is interested I am happy to share the code (it ain’t pretty, but it works). Apparently wordpress will soon support the wp_get_archive() command for custom post types – roll on that day!

      0
  25. 42

    This is awesome! Now I am just trying to figure out how to make “Resources” show up in the front-end. Do I need to edit index.php?

    0
  26. 43

    Really useful tutorial. Thanks!

    0
  27. 44

    Great tutorial. One recommendation though: instead of doing a custom WP_Query on the archive pages, you should instead be modifying the default WordPress query with pre_get_posts.

    Using your first example (displaying term results in custom taxonomy template), you have posts_per_page set to 3. So if there are 4 results, you’ll get a Next Page link.

    Clicking that link, WordPress will first ask for results 11-20, which don’t exist, and will give you a 404 before your custom query can run.

    The best approach would be to hook into pre_get_posts, and if the conditions are right modify the default query using your query args. That way you can run a normal loop on the taxonomy page and everything works (right posts are displayed, pagination works…).

    Here’s a tutorial I recently wrote that describes this approach: http://www.billerickson.net/customize-the-wordpress-query/

    Also, one more issue. wp_get_object_terms will return duplicates. So if there’s two posts that use the same presenter, that presenter will show up twice in your list. You’ll either want to:
    $presenter = array_unique( $presenter );

    Or:
    $presenters_by_posts = array_unique( $presenters_by_posts, SORT_REGULAR );

    Here’s a ticket relating to it: http://core.trac.wordpress.org/ticket/11003

    0
  28. 45

    Great post. I found it searching for tips on custom post types and taxonomies for online local newspapers. Still haven’t found that article, but yours helped a bit. Great overview.

    0
  29. 46

    Thanks a lot for a such good article…
    i really find it helpful…

    0
  30. 47

    Just want to say – Absolutely amazing.. Really helped me out… And taught me so much.
    Without you I’d probably be sacked ;)
    Thank you.

    ps… Would be nice to have the comments with the latest first..(ASC) ?????????

    0
  31. 48

    Jean Gerard Bousiquot

    March 3, 2013 6:51 pm

    Hello there ! As always thanks Jonathan for your great tutorials. Even though it was written in 2011, it is still useful and precious to me. Just finish reading the two parts. Now I’m going to put all this knowledge in practice in a current project. Again, Thanks a lot for sharing your knowledge.

    Regards, JGB.

    0
  32. 49

    What happened to part 3? I was looking forward to hearing how you did the filtering!

    0

↑ Back to top