post

How to Make a Genesis Grid Archive Template for Tags

To display posts from a specific tag or tags, you need to add a ‘tag’ argument to the $grid_args array.

In the StudioPress tutorial about categories, you are given this example for your home.php.

<?php
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'child_grid_loop_helper' );
/** Add support for Genesis Grid Loop **/
function child_grid_loop_helper() {
    if ( function_exists( 'genesis_grid_loop' ) ) {
        genesis_grid_loop( array(
            'features' => 2,
            'feature_image_size' => 0,
            'feature_image_class' => 'alignleft post-image',
            'feature_content_limit' => 0,
            'grid_image_size' => 'grid-thumbnail',
            'grid_image_class' => 'alignleft post-image',
            'grid_content_limit' => 0,
            'more' => __( '[Continue reading...]', 'genesis' ),
            'posts_per_page' => 6,
            'cat' => '6,7' //enter your category IDs here separated by commas in ' '
        ) );
    } else {
        genesis_standard_loop();
    }
}
 
/** Remove the post meta function for front page only **/
remove_action( 'genesis_after_post_content', 'genesis_post_meta' );
 
genesis();

Simply change the ‘cat’ argument to ‘tag’. And you can have the customization you want. OR, you can grab it dynamically by making the following changes:

<?php
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'child_grid_loop_helper' );
/** Add support for Genesis Grid Loop **/
function child_grid_loop_helper() {
    $term = get_query_var( 'term' );
    if ( function_exists( 'genesis_grid_loop' ) ) {
        genesis_grid_loop( array(
            'features' => 2,
            'feature_image_size' => 0,
            'feature_image_class' => 'alignleft post-image',
            'feature_content_limit' => 0,
            'grid_image_size' => 'grid-thumbnail',
            'grid_image_class' => 'alignleft post-image',
            'grid_content_limit' => 0,
            'more' => __( '[Continue reading...]', 'genesis' ),
            'posts_per_page' => 6,
            'tag' => $term
        ) );
    } else {
        genesis_standard_loop();
    }
}
 
/** Remove the post meta function for front page only **/
remove_action( 'genesis_after_post_content', 'genesis_post_meta' );
 
genesis();

You can save this as tag.php to make all of your tag archives as a grid. Or, you can simply apply this to a single tag by naming it tag-{SLUG}.php or tag-{ID}.php (see WordPress Codex for Tag Templates for more information).

post

How to Make a Custom Taxonomy Genesis Grid Archive Template

First, catch up on the Grid Loops by reading these posts:

Now, that you have a basic understanding of the Grid, let’s apply this to a custom taxonomy archives.

First, you need a new document saved as taxonomy-{taxName}.php (for more information, see the WordPress Codex). So if you have a custom taxonomy of “Book Type,” registered as ‘book_type,’ then the file name will be taxonomy-book_type.php.

Second, create the header, just like a page template. This is primarily for your organization and your information. So I just model it after the page template just to be consistent.

<?php
/*
Template Name: Book Type Taxonomy Archive
*/

Third, you want to set all your customizations like remove post meta, post info, page layout, etc.

Fourth, you want to include the Grid Looper Helper function. This is a standard protocol for the Genesis Grid Loop:

<?php

remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'wps_grid_loop_helper' );
/** Add support for Genesis Grid Loop **/
function wps_grid_loop_helper() {
    global $grid_args, $post;
    $taxonomy = 'book_type'; //change me
    $term = get_query_var( 'term' );
    $term_obj = get_term_by( 'slug' , $term , $taxonomy );
    $cpt = 'wps_books'; //change me

    if ( function_exists( 'genesis_grid_loop' ) ) {
		$grid_args_tax = array(
			'features' => 0,
			'feature_image_size' => 'book_featured',
			'feature_image_class' => 'aligncenter post-image',
			'feature_content_limit' => 100,
			'grid_image_size' => 'book_thumb',
			'grid_image_class' => 'aligncenter post-image',
			'grid_content_limit' => 0,
			'more' => '',
			'posts_per_page' => 10,
			'post_type' => $cpt,
			'paged' => get_query_var('paged') ? get_query_var('paged') : 1,
			'tax_query' => array(
				array(
					'taxonomy' => $taxonomy,
					'field' => 'slug',
					'terms' => array( $term_obj->slug ),
				)
			)		
		);

			printf('<h2 class="book-section"> %s Books</h2>' , $term_obj->name );
			genesis_grid_loop($grid_args_tax);
	} else {
		genesis_standard_loop();
	}
}

Now, this can be rather complicated and intimidating, so let me break this down for you. While everything is the same as the previous Grid posts, there is one major change and that is the ‘tax_query’ (WordPress Codex). But just for those readers, who didn’t take my advice to read the previous articles, let me briefly explain the $grid_args_tax (for those who know the basic args, skip the next paragraph).

‘features’ refers to the number of featured posts in the grid loop. So if you want to display 10 but feature 2, you would set this number to 2, posts_per_page to 10 and Genesis will do the math to ensure that everything is kosher. However, in our example, we want zero features for the taxonomy listing. ‘feature_image_size’ and ‘grid_image_size’ are the post thumbnail size that you want the image to appear as. ‘feature_image_class’ and ‘grid_image_class’ refer to the CSS image class for styling. ‘feature_content_limit’ and ‘grid_content_limit’ refers to the number of characters allowed in the content. See the StudioPress articles for futher explanations.

Now ‘tax_query’ refers to the taxonomy args. It must take an array of arrays of the following args:

  • taxonomy (string): the taxonomy
  • field (string): select taxonomy term by ‘id’ or ‘slug’
  • terms (int/string/array): taxonomy terms
  • operator (string): ‘IN’, ‘NOT IN’, ‘AND’

In our example, we have the template for a predetermined specific taxonomy and the template dynamically grabbing the appropriate taxonomy term (so someone may be searching for a ‘Fiction’ Book Type). If you wanted, it could also fetch the taxonomy dynamically, if you wanted all of your taxonomy archives to be on the grid. To do this, simply add the following code: $taxonomy = get_query_var( 'taxonomy' );. For tags and categories, you probably could use this same method; however, there is also a simpler method which I will explain in a later post (Tags and Same Categories and Different Categories).

So, after you set the post type (‘post’, ‘page’, or some other custom post type registered name, e.g., ‘wps_books’) and the taxonomy (which is the same as the latter half of the file name, so in this example ‘book_type’), the function first grabs the slug of the term: $term = get_query_var( 'term' ); (more information: get_query_var). Then it calls for the genesis custom grid loop.

Now obviously, with this custom post type, I am going to want to determine my own grid loop content. To do this, I simply make these additions:

 <?php
add_action('genesis_before_post', 'wps_custom_grid');
function wps_custom_grid() {
	remove_action('genesis_post_content', 'genesis_grid_loop_content');
	add_action('genesis_post_content', 'wps_grid_loop_content');
}

function wps_grid_loop_content() {
global $_genesis_loop_args, $wp_query;
//do something
}

For an excellent post on customizing the content, see Bill Erickson’s post, Customizing the Genesis Grid Loop Content.

Some other good grid functions include the following:

<?php
// Add some extra post classes to the grid loop so we can style the columns
add_filter( 'genesis_grid_loop_post_class', 'wps_grid_loop_post_class' ); 
/**
 * Add some extra body classes to grid posts.
 *
 * Change the $columns value to alter how many columns wide the grid uses.
 *
 * @author Gary Jones
 * @link http://dev.studiopress.com/genesis-grid-loop-advanced.htm
 *
 * @global array $_genesis_loop_args
 * @global integer $loop_counter
 * @param array $classes
 */
function wps_grid_loop_post_class( $grid_classes ) {
    global $_genesis_loop_args, $loop_counter;

    // Alter this number to change the number of columns - used to add class names
    $columns = 3;

    // Only want extra classes on grid posts, not feature posts
    if ( $loop_counter >= $_genesis_loop_args['features'] ) {

        // Add genesis-grid-column-? class to know how many columns across we are
        $grid_classes[] = sprintf( 'genesis-grid-column-%s', ( ( $loop_counter - $_genesis_loop_args['features'] ) % $columns ) + 1 );

        // Add size1of? class to make it correct width
        $grid_classes[] = sprintf( 'size1of%s', $columns );
    }
    return $grid_classes;
}

// Make sure the first page has a balanced grid
add_action( 'genesis_loop', 'wps_bal_grid_loop' ); 
function wps_bal_grid_loop() {
    global $query_string, $paged, $grid_args, $_genesis_loop_args;

    if ( 0 == $paged )
        // If first page, add number of features to grid posts, so balance is maintained
        $grid_args['posts_per_page'] += $grid_args['features'];
    else
        // Keep the offset maintained from our page 1 adjustment
        $grid_args['offset'] = ( $paged - 1 ) * $grid_args['posts_per_page'] + $grid_args['features'];
}
post

Helpful Custom Post Type and Custom Taxonomy Functions

Understanding WordPress Custom Post Types

Here are two great posts regarding custom post types’ functions: An Important Update: WordPress 3.0 Post Types And Taxonomies, from New2WP written by  Jared (@Tweeaks), and Custom Post Types in WordPress from Justin Tadlock (@justintadlock). that I wanted to reproduce in part in this series.

The following are functions you can use for various things related to post types. The function name is linked to the line in /wp-includes/post.php where it is created for those that would like to check out the source code which makes them work. I’ve also added a short description for each that is used in the source to describe them [slightly modified by Travis Smith].

Post Type Functions:

  • is_post_type() – Checks to see if current post is of a specified post type.
    <?php
    if ( is_post_type( 'zombie', $post_id ) )
    	echo 'This is a not a blog post.  It is a zombie!';
    else
    	echo 'This is not a zombie. [insert sad face]';
  • get_post_types( $post ) – Get a list of all registered post type objects.
    • $args - An array of key => value arguments to match against the post type objects.
    • $output - The type of output to return, either post type ‘names’ or ‘objects’. ‘names’ is the default.
    • $operator - The logical operation to perform. ‘or’ means only one element from the array needs to match; ‘and’ means all elements must match. The default is ‘and’.
    • Returns an array listing post type names or objects.
  • get_post_type_object() – Retrieves a post type object by name
    $post_type = get_post_type_object( 'zombie' );
    
    if ( $post_type->show_ui )
    	custom_function_name();
    
  • register_post_type() – Register a post type. Do not use before init.
    • A simple function for creating or modifying a post type based on the parameters given.
    • The function will accept an array (second optional parameter), along with a string for the post type name.
  • get_post_type_capabilities() – Builds an object with all post type capabilities out of a post type object.
  • Accepted keys of the capabilities array in the post type object:
    • edit_post - The meta capability that controls editing a particular object of this post type. Defaults to “edit_ . $capability_type” (edit_post).
    • edit_posts - The capability that controls editing objects of this post type as a class. Defaults to “edit_ . $capability_type . s” (edit_posts).
    • edit_others_posts - The capability that controls editing objects of this post type that are owned by other users. Defaults to “edit_others_ . $capability_type . s” (edit_others_posts).
    • publish_posts - The capability that controls publishing objects of this post type. Defaults to “publish_ . $capability_type . s” (publish_posts).
    • read_post - The meta capability that controls reading a particular object of this post type. Defaults to “read_ . $capability_type” (read_post).
    • read_private_posts - The capability that controls reading private posts.Defaults to “read_private . $capability_type . s” (read_private_posts).
    • delete_post - The meta capability that controls deleting a particular object of this post type. Defaults to “delete_ . $capability_type” (delete_post).
  • get_post_type_labels( $post_type_object ) – Builds an object with all post type labels out of a post type object.
  • Accepted keys of the label array in the post type object:
    • name - general name for the post type, usually plural. The same and overriden by $post_type_object->label. Default is Posts/Pages
    • singular_name - name for one object of this post type. Default is Post/Page
    • add_new - Default is Add New for both hierarchical and non-hierarchical types.
    • add_new_item - Default is Add New Post/Add New Page
    • edit_item - Default is Edit Post/Edit Page
    • new_item - Default is New Post/New Page
    • view_item - Default is View Post/View Page
    • search_items - Default is Search Posts/Search Pages
    • not_found - Default is No posts found/No pages found
    • not_found_in_trash - Default is No posts found in Trash/No pages found in Trash
    • parent_item_colon - This string isn’t used on non-hierarchical types. (In hierarchical ones the default is Parent Page)
  • _get_custom_object_labels() – Builds an object with custom-something object (post type, taxonomy) labels out of a custom-something object
  • add_post_type_support( $post_type, $feature ) – Register support of certain features for a post type.
  • All features are directly associated with a functional area of the edit screen, such as the editor or a meta box:
    • ‘title’,
    • ‘editor’,
    • ‘comments’,
    • ‘revisions’,
    • ‘trackbacks’
    • ‘author’,
    • ‘excerpt’,
    • ‘page-attributes’,
    • ‘thumbnail’,
    • ‘custom-fields’

    Additionally, the ‘revisions’ feature dictates whether the post type will store revisions, and the ‘comments’ feature dicates whether the comments count will show on the edit screen.

  • set_post_type( $post_id = 0, $post_type = ‘post’ ) – Updates the post type for the post ID.
    • $post_id Post ID to change post type. Not actually optional.
    • $post_type Optional, default is post. Supported values are ‘post’ or ‘page’ to name a few.
    • Return int Amount of rows changed. Should be 1 for success and 0 for failure.
  • get_posts() – Retrieve list of latest posts or posts matching criteria.
  • The defaults are:
    • ‘numberposts’ - Default is 5. Total number of posts to retrieve.
    • ‘offset’ - Default is 0. See { WP_Query::query() } for more.
    • ‘category’ - What category to pull the posts from.
    • ‘orderby’ - Default is ‘post_date’. How to order the posts.
    • ‘order’ - Default is ‘DESC’. The order to retrieve the posts.
    • ‘include’ - See { WP_Query::query() } for more.
    • ‘exclude’ - See { WP_Query::query() } for more.
    • ‘meta_key’ - See { WP_Query::query() } for more.
    • ‘meta_value’ - See { WP_Query::query() } for more.
    • ‘post_type’ - Default is ‘post’. Can be ‘page’, or ‘attachment’ to name a few.
    • ‘post_parent’ - The parent of the post or post type.
    • ‘post_status’ - Default is ‘published’. Post status to retrieve.

Functions For Taxonomies You Should Know About

The following are functions which you can use when working with taxonomies. I’m not going to link to the line of each function or include descriptions of each since the file which contains them is way smaller than posts.php where the post type functions are, so if you’re interested in viewing the source of these you should’ve have a hard time finding the line they are on.

The functions which make up taxonomies are located in /wp-includes/taxonomy.php of the WordPress source.

post

Custom Post Types and Custom Taxonomies

Understanding WordPress Custom Post Types
To me, custom post types cannot be divorced from custom taxonomies. Two of the criteria that I consider before creating a custom post type is:

  1. Can my goal/objective be accomplished through the use of custom taxonomies?
  2. Do I need to use custom taxonomies?

This being said, WordPress’s out of the box compatibility with custom taxonomies is still developing. However, one individual, Michael Fields, is pioneering WordPress’s custom taxonomies functionality and capabilities. So I wanted to highlight some of the things he has already created.

Michael has excellent posts on Taxonomy in WordPress. To highlight one in particular, New and Exciting Ways to Organize Your WordPress Powered Website, which is all about how to achieve better organization in WordPress (for a text-only page, see Understanding Taxonomy in WordPress). In this post, he includes this video:

However, Michael has more on Taxonomy in WordPress including some extremely helpful plugins and widgets. Consider these:

Taxonomy Images Plugin

May 31, 2011 – This plugin allows you to associate images from your media library to categories, tags and custom taxonomies. … Download the plugin

Taxonomy List Shortcode Plugin

The Taxonomy List Shortcode plugin adds a shortcode to your WordPress installation which enables you to display multiple unordered lists containing every term of a given taxonomy. After speaking with Michael, Michael informed me that a massive overhaul is coming soon introducing full
theme integration plus special option(s) that integrate with Taxonomy Images. It should be very exciting.  … View this page, Download the plugin

Dealing with Long Taxonomy Descriptions in the WordPress Administration Panels

Probably Michael’s most under-rated plugin. This plugin allows you to take full advantage of the taxonomy system the the latest version of WordPress. Unfortunately, the taxonomy administration panels tend to get quickly bloated where terms have descriptions that are longer than a few words. It trims the term description down to a short length when viewing multiple terms in the administration panels. If you have really long taxonomy descriptions then you might only be able to view one or two terms per screen. This plugin fixes that. Here is a quick and easy method to help put an end to long descriptions messing with your work flow. … View the code, Download the plugin

Taxonomy Widget Plugin

The Taxonomy Widget Plugin enables users of all skill levels to create widgets in their sidebar that display all terms of any given post taxonomy including tags and categories. Users can choose between 3 different templates including two types of lists, a term cloud or a dropdown menu. … View this page, Download the plugin

Taxonomy Terms List Plugin

This plugin will create a list for each taxonomy whose terms have been associated to a given post. These list will appear after the post content. This plugin will not effect builtin taxonomies such as categories, tags and link categories. … View this page, Download the plugin

One particular post that deserves some attention (and got Michael’s attention) is Otto’s post on Custom Taxonomies.

Advanced Taxonomy Queries in WordPress 3.1

Otto does a great job of explaining some of the additions to the taxonomy system in WordPress 3.1. I’ve been using this article as a reference for the past few days. … View this Bookmark

Other posts by Michael include:

Set Default Terms for your Custom Taxonomies

Sep 14, 2010 – If you’ve ever created a post in WordPress, you’ll know that you have to put it in a category. There’s no way around this, if you try to fight it, you will lose! On the other hand, there is really no way to define a default for custom taxonomies. I created the following code to … View this post

Append a posts taxonomy terms to post class.

Jul 11, 2010 – The following code snippet will enable your theme to append the slug of every term of a given taxonomy that has been associated to the current post. You will most likely want to change the value of the $taxonomy variable to match a taxonomy registered for the post type you are targeting. View this post

Dynamically Create Actions for Every Defined Taxonomy’s Column Header

Jun 4, 2010 – Taxonomy support in WordPress 3.0 has improved in many places. During the time I spent updating a few of my plugins, I noticed that dynamic filters had been defined for the columns that appear on edit-tags.php – the file that lists the terms for each taxonomy in the administration panels. The following snippet demonstrates how … View this post

Remove Taxonomy Box from WordPress Administration Panels

While Michael only posted this for his own reference, it’s good stuff nonetheless. I’m posting this here pretty much for my own reference. The idea is to create an array of taxonomy slugs that you want to hide from the Edit screens in The WordPress Administration Panels. You can then loop over the global $wp_taxonomies variable and if the taxonomy is present in the $hide array, the WordPress … View this post

Besides these excellent posts, Michael has a plethora of taxonomy plugins that are extremely useful. There was one particular instance that I needed something like wp_dropdown_categories() regarding custom taxonomies and Michael submitted a trac ticket in WordPress and via PasteBin. So Michael created a forked version of wp_dropdown_categories() calling it mfields_dropdown_taxonomy_terms(). Michael has since moved and revised the code in the Taxonomy Widget. The much simplified version which uses only a custom walker in the code of the taxonomy widget plugin (code starts on line 365 … The custom walker is used on line 300 – args start on line 288).

post

Custom Post Types, Post Formats, Custom Taxonomies, and Custom Fields and Meta Boxes

Understanding WordPress Custom Post Types
This is the new WordPress Soup: Custom Post Types, Post Formats, Custom Taxonomies, and Custom Fields/Meta Boxes. First and foremost, since we have already talked about what custom post types are, let’s define the other two: post formats and custom taxonomies.

Post Formats

Tapestry Theme - A Tumblog-Style Theme for WordPress using Post FormatsPost formats are not post types, that is, they are not content types. Instead, they are varying types of posts. They are posts with varying formatting. For example, consider the following:

  • a shared link should have a link as its focus.
  • a video should have a video as its focus, maybe its only content
  • an image should have an image as its focus, maybe again, its only content
  • a quote should have a quote as its focus, maybe its only content
  • Etc.

As Mark Jaquith states:

A Post Format is a formatting designation made to a post. For example, a post could be a short “aside,” or a Kottke.org-style link post, or a video post, or a photo gallery post. The data you input might be slightly different — video post should contain a video, an aside should probably not be very long, a link post should have a link. And the way that the post is displayed on the site might be very different — an aside will typically be displayed without a title, a link post may have the title point to the link. A video post may be wider, or have social sharing buttons auto-appended. But they’re all still posts. They still show up in your feed, and you still find them in the Posts section of the WordPress backend.

There are two major differences between custom post types and post formats. They are:

  1. Post formats will appear in the main RSS. Custom post types do not appear in the RSS feed by default without further coding (though in my opinion this should be part of the registration coding as it is with searching).
  2. Post formats are a WordPress “standardized convention.” In other words, instead of using categories to customize output and display (that may or may not be supported across themes/frameworks), post formats provides a standard method of doing this.

Simply, think Tumblr! StudioPress’s Tapestry Child Theme makes good use of Post Formats.

As far as WordPress is concerned, there are ONLY 10 Post Formats available to users/theme developers. They are:

  1. standard – regular post
  2. aside – Typically styled without a title. Similar to a Facebook note update.
  3. gallery – A gallery of images. Post will likely contain a gallery shortcode and will have image attachments.
  4. link – A link to another site.
  5. image – A single image.
  6. quote – A quotation. Probably will contain a blockquote holding the quote content. Alternatively, the quote may be just the content, with the source/author being the title.
  7. status – A short status update, similar to a Twitter status update.
  8. video – A single video.
  9. audio – An audio file. Could be used for Podcasting.
  10. chat – A chat transcript

Now, just like thumbnail images, post formats must be activated by the theme.

add_theme_support( 'post-formats' , array( 'aside' , 'chat' , 'gallery' , 'image' , 'link' , 'quote' , 'status' , 'video' , 'audio' ) );

To style post formats, use the following new CSS classes:

Standard: Normal CSS
Aside: .format-aside {}
Audio: .format-audio {}
Chat: .format-chat {}
Gallery: .format-gallery {}
Image: .format-image {}
Link: .format-link {}
Quote: .format-quote {}
Status: .format-status {}
Video: .format-video {}

Custom Taxonomies

Think Categories and Tags. These both represent two types of taxonomies: hierarchical, where terms can have a parent-child relationship (e.g.,categories) and non-hierarchical, where all terms are equal (e.g., tags). Custom taxonomies give you the ability to name and create taxonomies that act like Tags and Categories but are named whatever you’d like to name them.

Other built-in taxonomies include Link Category and Nav Menu. So what are some custom taxonomies? These can be determined by custom post types and can be whatever you need them to be; for example, an employee custom post type could use an employee departments hierarchical taxonomy. Another example could be a movie custom post type utilizing multiple taxonomies of genre, director, stars/actors, etc. (More information forthcoming…)

Custom Fields and Meta Boxes

These are designated areas to input information on a per post/custom post (or content entry) basis. Generally speaking, if the Title, Editor, etc. that is found on a post won’t do what you want it to do with the content, then most people add custom fields that creates an easy way to input content as well as display the content. Custom Meta Boxes and Custom Fields are sets of additional editable fields that may be added to any post type, whether page, post, or a custom post type. The custom fields can be used to store any sort of content/data that you want. They are often single line input boxes, checkboxes, dropdown boxes, paragraph text areas, radio buttons, etc. There will be more on this later as Custom Meta Boxes and Custom Fields are usually extremely important to Custom Post Types. (More information forthcoming…)

Summary

So, in short, custom post types are content types for custom storing with custom displays on the backend and front end. Post formats are types or variations of displaying content on the front end only coming with a standardize set of 10 choices. Custom taxonomies are terms, whether hierarchical or not, that are used for organizing content. Custom Meta Boxes and Fields are designated areas to add more information beyond the standard title, editor, etc. (which are displayed via built-in meta boxes).

More Information/Further Reading

Post Formats Links

Custom Taxonomies Links

Other