WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Aug 15 2011

How to Make a Custom Taxonomy Genesis Grid Archive Template

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

  • Customizing the Genesis Grid Content, by Bill Erickson
  • How to Use the Genesis Grid Loop, by Brian Gardner
  • Genesis Grid Loop Advanced, by Gary Jones

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]<?php
/*
Template Name: Book Type Taxonomy Archive
*/[/php]

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]<?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();
}
}
[/php]

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] <?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
}
[/php]

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]<?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'];
}
[/php]

Written by Travis Smith · Categorized: Genesis, Genesis Grid Loop, Tutorials

Aug 03 2011

How to Force a Specific Layout for a Page Template in Genesis

The other day, I was creating a page template using the standard approach used in forcing a specific layout. However, when using page templates, this will work if they have not selected a specific layout on the page in the Genesis Layouts metabox. So you could either hide the Genesis metabox, or you can have the page template ignore any changes made in the layout metabox (less coding!).

The normal procedure is as follows:

[php]
add_filter('genesis_pre_get_option_site_layout', '__genesis_return_full_width_content');
[/php]

However, this ignores any custom fields that may upset this. So since this is pre_get_option_*, the user can accidentally over-ride the "forced" specific layout. So if you don't want the user to over-ride it you need to go a step further. You can add one more line of code to correct and ensure that a page can never have a different layout. One way is to set the post meta to always be whatever you want.

[php]
global $post;
// Force Page Layout for Page Template
update_post_meta( $post->ID, '_genesis_layout', 'full-width-content' );
[/php]

However, the Genesis approach would be to set it via the pre site layout Filter.

Written by Travis Smith · Categorized: Genesis, Tutorials

Aug 02 2011

Pinkalicious Release Sale!

Pinkalicious is not ‘just another WordPress theme’. It has built in features that will get your website up and running quickly, and it will look delicious! Featuring an awesome pink and chocolate color pallette, it is the perfect theme for blogs or even an eCommerce site. [purchase_link id="15517" text="Purchase" style="button" color="gray"]

Pinkalicious
Click for a Larger Image

The home page features an image slider that will allow you to present your posts, products, or services in a spectacular fashion. An optional 1, 2, or 3 column widgetized area under the slider is a quick and painless way to present your most critical information in a way that you want. Furthermore, it is packaged with a portfolio page template making portfolios easy!

Pinkalicious also has some funaliciousness! Introducing two unique features:

  1. the very first Grid Page Template and
  2. the very first Grid Posts widget

While both of these features are based on the Genesis Grid Loop, there isn't a single Genesis Child theme that has incorporated these features so integrated and easy to use. These fantastic features also make Genesis Grids easy to implement for any category, term, taxonomy, or post type regardless of location. Do you want one category for features and another for grid posts? NO Problem! It is completely flexible, and easy to use!

The theme is extensively styled and the color scheme is very … pinkalicious.

Give Pinkalicious a try – Pinkalicious Demo | [purchase_link id="15517" text="Purchase" style="button" color="gray"]

Written by Travis Smith · Categorized: WordPress

Jul 19 2011

Announcing My First Two New Genesis Child Themes: MinFocus & Pinkalicious

Here are my first two developed Child Themes. While I have built many custom child themes for clients, many of them have morphed into examples that I would rather not show. Some have been from PDF (probably originally Word), AI, and PSD to WordPress Genesis Child Theme. So here are my first two Genesis Child Themes.

MinFocus

MinFocus
Click for Larger Image

MinFocus is a flexible theme that could be used for a photoblog, blog or other personal website. Besides the default Genesis templates, it offers a Portfolio template and an extremely flexible Grid Blog template.

The home page features a space for a slider which is widgetized for easy customization. Furthermore, it easily integrates with WP-Cycle becoming auto-enabled upon activation. And MinFocus contains a default image setting for posts without a thumbnail or image inserted into the post.

MinFocus Demo

Pinkalicious

Pinkalicious
Click for a Larger Image

Pinkalicious is a Genesis Child theme that can also be used for a photoblog, blog or other personal website. Besides the default Genesis templates, it too offers a Portfolio template and an extremely flexible Grid Blog template.

The home page features a slider that can be customized in the theme settings page, and contains a default image setting for posts without a thumbnail or image inserted into the post.

Pinkalicious Demo | [purchase_link id="15517" text="Purchase" style="button" color="gray"]

Please let me know if you would like to give one of these a test drive via a comment or Twitter (@wp_smith)

Written by Travis Smith · Categorized: Genesis, WordPress

Jul 16 2011

Conditionally Remove Post Info from Posts Using Custom Fields

So recently, someone asked me how to remove post info only from specific posts using custom fields. Here is what I came up with:

First, set your custom field name to whatever you'd like it to be. I used no_post_info. And then set its value. I used true, but it really can be anything (other than false or null).

Then add to your functions.php:
[php]<?php
add_filter('genesis_post_info', 'wps_post_info_filter');
function wps_post_info_filter($post_info) {
if (genesis_get_custom_field('no_post_info')) //again, no_post_info can be whatever you name your custom field
$post_info = '';
return $post_info;
}
[/php]

Written by Travis Smith · Categorized: Genesis, Tutorials

  • « Previous Page
  • 1
  • …
  • 35
  • 36
  • 37
  • 38
  • 39
  • …
  • 61
  • Next Page »
  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

Copyright © 2025 � WP Smith on Genesis on Genesis Framework � WordPress � Log in