post

Developing a Custom Post Type and a Custom Taxonomy in Genesis with Custom Pages, Part 4

Now, in Developing a Custom Post Type and a Custom Taxonomy in Genesis with Custom Pages, Part 1, we have the registration of the custom post type, custom taxonomy and the addition of the metaboxes. In Part 2, we discussed the Single Page Template for the custom post type. In Part 3, we discussed the Taxonomy Template for the custom taxonomy. For good measure, let’s create a basic page template to wrap this all up. This will create a front page of sorts for the custom taxonomy and the single custom post type pages.

A. File Setup

First, create the file as page-{whatever}.php (WordPress Codex). While you can use page-{slug}.php, this can cause some unexpected issues. So naming it page-{whatever}.php forces the user to assign it via the page templates area. So in our case, it will be page-brakes.php.

B. Template Name

The first thing you must enter with any page template is the Template Name.

<?php
/*
 *Template Name: Disc Brakes Template
 */

B. Menu Move

Now, for this example, I want to use a menu system. So I will be using the secondary menu system to accomplish this, and I want this to appear below the title.

<?php
// Place the secondary navigation menu below the title
remove_action( 'genesis_after_header', 'genesis_do_subnav' );
add_action( 'genesis_after_post_title', 'genesis_do_subnav' );

// Enable the secondary navigation menu for single post type
add_filter('genesis_options', 'wps_define_genesis_setting' , 10, 2);
function wps_define_genesis_setting( $options, $setting ) {
    if( $setting == GENESIS_SETTINGS_FIELD ) {
        $options['subnav'] = 1;
    }
    return $options;
}

If you notice, I programmatically turn on the secondary menu. However, again, in Genesis > Theme Settings, site-wide, I have the secondary navigation system turned off. Now, for this page template, I have selectively turned it on.

If you use the secondary navigation for your site, simply register a new navigation system and then add it. See the previous tutorial for this information.

C. Include the Genesis Framework **VERY IMPORTANT

<?php
genesis();

So here is our finished product: page-brakes.php

<?php

/*
 *Template Name: Disc Brakes Template
 */

// Place the secondary navigation menu below the title
remove_action( 'genesis_after_header', 'genesis_do_subnav' );
add_action( 'genesis_after_post_title', 'genesis_do_subnav' );

// Enable the secondary navigation menu for single post type
add_filter('genesis_options', 'wps_define_genesis_setting' , 10, 2);
function wps_define_genesis_setting( $options, $setting ) {
    if( $setting == GENESIS_SETTINGS_FIELD ) {
        $options['subnav'] = 1;
    }
    return $options;
}

genesis();
post

Developing a Custom Post Type and a Custom Taxonomy in Genesis with Custom Pages, Part 3

In the first tutorial, Developing a Custom Post Type and a Custom Taxonomy in Genesis with Custom Pages, Part 1, we covered the following:

  1. Register your Custom Post Type
  2. Register your Custom Taxonomy
  3. Create my Metaboxes
  4. Clear Permalinks

In the previous tutorial Developing a Custom Post Type and a Custom Taxonomy in Genesis with Custom Pages, Part 2, we covered how to Create the Single Page Template for the Custom Post Type.

In this tutorial, we will walk through how to Create a Custom Taxonomy Page Template. Now the specifics will be different from custom taxonomy to custom taxonomy. This is how a taxonomy archives will appear, just like if someone clicks on a specific category or tag (via category.php). However, I will walk you through a basic setup.

A. File Setup

First, create the file as taxonomy-{taxonomy_registered_name}.php (WordPress Codex). So in our case, it will be single-wps_axlesizes.php.

B. Menu Move

Now, for this example, I want to use a menu system. So I will be using the secondary menu system to accomplish this, and I want this to appear below the title. (**This assumes that your site hasn’t done anything with Secondary Navigation.)

<?php
// Place the secondary navigation menu below the title
remove_action( 'genesis_after_header', 'genesis_do_subnav' );
add_action( 'genesis_after_post_title', 'genesis_do_subnav' );

// Enable the secondary navigation menu for single post type
add_filter('genesis_options', 'wps_define_genesis_setting' , 10, 2);
function wps_define_genesis_setting( $options, $setting ) {
    if( $setting == GENESIS_SETTINGS_FIELD ) {
        $options['subnav'] = 1;
    }
    return $options;
}

If you notice, I programmatically turn on the secondary menu. However, in Genesis > Theme Settings, sitewide, I have the secondary navigation system turned off. Now, for this page template, I have selectively turned it on.

If you already use the secondary navigation for your site, simply register a new additional navigation system and then add it. See the previous tutorial for this information.

C. Post Meta/Post Info

Now, I would like to remove the post meta and post info. (**This assumes that your site hasn’t done anything with Secondary Navigation.

<?php
// Remove the post info function
remove_action( 'genesis_before_post_content', 'genesis_post_info' );

// Remove the post meta function
remove_action( 'genesis_after_post_content', 'genesis_post_meta' );

D. Custom Loop **VERY IMPORTANT

Now, I want to create my custom display of the content via the loop. This section will dramatically change from custom taxonomy to custom taxonomy based on what type of information you’d like to display and how you’d like to display it. This would be where you would introduce the Genesis Grid Loop, if you wanted to go that route. Since this file refers to all the terms in the custom taxonomy, we have to code thinking about them all.

<?php
remove_action('genesis_loop', 'genesis_do_loop');
add_action('genesis_loop', 'wps_do_axlesizes_loop');
function wps_do_axlesizes_loop() {
	global $query_args;  // any wp_query() args

	// Get term
	$term = get_query_var( 'term' );

	$args = array(
		'tax_query' => array(
			array(
				'taxonomy' => 'wps_axlesizes',
				'field' => 'slug',
				'terms' => $term
			)
		)
	);

	genesis_custom_loop( wp_parse_args( $query_args , $args ) );
}

E. Custom Content **VERY IMPORTANT

Finally, I want to create my custom display of the content via the content. Again, this section will dramatically change from custom taxonomy to custom taxonomy based on what type of information you’d like to display and how you’d like to display it.

<?php
remove_action('genesis_post_content', 'genesis_do_post_content');
add_action('genesis_post_content', 'wps_do_axlesizes_content');
function wps_do_axlesizes_content() {
	global $post;

	$size = 'thumbnail'; // Change this to whatever add_image_size you want
	$default_attr = array(
			'class'	=> "alignleft attachment-$size",
			'alt'	=> $post->post_title,
			'title'	=> $post->post_title,
		);

	// check if the post has a Post Thumbnail assigned to it.
	if ( has_post_thumbnail() ) {
		printf( '<a href="%s" title="%s">%s</a>', get_permalink(), the_title_attribute( 'echo=0' ), genesis_get_image( array( 'size' => $size, 'attr' => $default_attr ) ) );
	}

	the_content( __( '[Read more...]' , 'genesis' ) );

	printf( '<a href="%s" title="%s">%s</a>', get_permalink(), the_title_attribute( 'echo=0' ), __( 'click for specifications' ) );

	echo '<div class="clear"></div>';
}

Now, for SEO purposes, we wanted to include the page name that will be associated with

tags.
// Add a page title (optional). This can be hard coded to pull the title from a specific page, but it is easier just to enter the page name here.

<?php
add_action( 'genesis_before_content' , 'wps_page_title' , 10 );
function wps_page_title() {
	?>
	<h1>Disc Brake Kits</h1>
	<?php
}

F. Include the Genesis Framework **VERY IMPORTANT

<?php
genesis();

The next step would be to style the taxonomy archive accordingly and as needed, which I am not going to cover here.

So our finished product is this: single-wps_axlesizes.php

<?php
/**
 * Taxonomy Template: wps_axlesizes
 *
 * This file is responsible for the display of
 * taxonomy archives for wps_axlesizes custom taxonomy.
 *
 * @author       Travis Smith <travis@wpsmith.net>
 * @copyright    Copyright (c) 2011, Travis Smith
 * @license      http://opensource.org/licenses/gpl-2.0.php GNU Public License
 *
 */

// Place the secondary navigation menu below the title
remove_action( 'genesis_after_header', 'genesis_do_subnav' );
add_action( 'genesis_after_post_title', 'genesis_do_subnav' );

// Enable the secondary navigation menu for single post type
add_filter('genesis_options', 'wps_define_genesis_setting' , 10, 2);
function wps_define_genesis_setting( $options, $setting ) {
    if( $setting == GENESIS_SETTINGS_FIELD ) {
        $options['subnav'] = 1;
    }
    return $options;
}

// Remove the post info function
remove_action( 'genesis_before_post_content', 'genesis_post_info' );

// Remove the post meta function
remove_action( 'genesis_after_post_content', 'genesis_post_meta' );

remove_action('genesis_loop', 'genesis_do_loop');
add_action('genesis_loop', 'wps_do_axlesizes_loop');
function wps_do_axlesizes_loop() {
	global $query_args;  // any wp_query() args

	// Get term
	$term = get_query_var( 'term' );

	$args = array(
		'tax_query' => array(
			array(
				'taxonomy' => 'wps_axlesizes',
				'field' => 'slug',
				'terms' => $term
			)
		)
	);

	genesis_custom_loop( wp_parse_args( $query_args , $args ) );
}

remove_action('genesis_post_content', 'genesis_do_post_content');
add_action('genesis_post_content', 'wps_do_axlesizes_content');
function wps_do_axlesizes_content() {
	global $post;

	$size = 'thumbnail'; // Change this to whatever add_image_size you want
	$default_attr = array(
			'class'	=> "alignleft attachment-$size",
			'alt'	=> $post->post_title,
			'title'	=> $post->post_title,
		);

	// check if the post has a Post Thumbnail assigned to it.
	if ( has_post_thumbnail() ) {
		printf( '<a href="%s" title="%s">%s</a>', get_permalink(), the_title_attribute( 'echo=0' ), genesis_get_image( array( 'size' => $size, 'attr' => $default_attr ) ) );
	}

	the_content( __( '[Read more...]' , 'genesis' ) );

	printf( '<a href="%s" title="%s">%s</a>', get_permalink(), the_title_attribute( 'echo=0' ), __( 'click for specifications' ) );

	echo '<div class="clear"></div>';
}

add_action( 'genesis_before_content' , 'rdwd_page_title' , 10 );
function rdwd_page_title() {
	?>
	<h1>Disc Brake Kits</h1>
	<?php
}

genesis();