How to Effectively Use the Blog Template with the Genesis Easter Egg, query_args

Ok, surprisingly, there is little to nothing written on the fun Easter Egg within the Genesis loop. So with little to no coding knowledge one can easily take advantage of this rarely known secret.

So with this, your possibilities are almost endless. You can do anything rather quickly. So what are the steps:

Genesis Theme Settings Blog Page

  1. Create a New Page
  2. Select Blog Template
  3. Add a query_args custom field

Category Pages

First, you can create Category Pages, if and only if you have not removed it from the Theme Settings > Blog Page. So in the image below, I cannot use categories 255 and 253 for my query_args.

query_args Custom Field

Custom Post Type Pages

Second, you can easily create Custom Post Type templates, using this method as well. While you won’t be able to set or arrange all the specific fields as you may want or have the customizations like remove_post_info or remove_post_meta, you can quickly create these.

query_args Custom Field

Now many plugins that have custom fields come with shortcodes on entering those custom fields into the body of the test, just as AgentPress even does. However, for those that do not have those shortcodes, you can easily add this to your functions.php to get those custom fields outputted.

***NOTE: The following shortcuts are done on a per post basis. If you do this on the template page, it will not work. It must be done on the posts of the custom post type for each post.

[php]
/**
* Returns the value of a custom field.
*
* Supported shortcode attributes are:
* field (field name),
*
* @author Travis Smith
* @param array $atts Shortcode attributes
* @return string Shortcode output
*/
add_shortcode( ‘post_field’, ‘wps_post_field_shortcode’ );

function wps_post_field_shortcode( $atts ) {

$defaults = array(
‘field’ => ”,
);
$atts = shortcode_atts( $defaults, $atts );

return genesis_get_custom_field( $atts[‘field’] );
}
[/php]

To use this shortcode, simply enter the field id, so that: [post_field field=”the-custom-field-id”] and it will appear.

Now, when the page displays the various custom post types content items (or posts), then they will appear in default fashion with post meta, post info, etc. However, one way I easily remove post info or post meta is using a custom field again. However, you need to make sure you have this conditional function in your functions.php file. Something like this:

[php]
// Customize the post meta function
add_filter( ‘genesis_post_info’, ‘wps_post_info_filter’ );
function wps_post_info_filter( $post_info ) {
if ( genesis_get_custom_field ( ‘wps_no_post_info’ ) ) //again, no_post_info can be whatever you name your custom field
$post_info = ”;
return $post_info;
}

// Customize the post meta function
add_filter( ‘genesis_post_meta’, ‘post_meta_filter’ );
function post_meta_filter( $post_meta ) {
if ( genesis_get_custom_field ( ‘wps_no_post_meta’ ) ) //again, no_post_info can be whatever you name your custom field
$post_meta = ”;
return $post_meta;
}}
[/php]

No Post Info

If you wanted, you could also use the various possible shortcodes available to you and conditionally set your post meta and post info. StudioPress has an excellent Shortcodes Reference Guide.

The functions then would look something like this:

[php]
// Customize the post meta function
add_filter( ‘genesis_post_info’, ‘wps_post_info_filter’ );
function wps_post_info_filter( $post_info ) {
if ( genesis_get_custom_field ( ‘wps_no_post_info’ ) ) //again, no_post_info can be whatever you name your custom field
$post_info = genesis_get_custom_field ( ‘wps_post_info’ );
return $post_info;
}

// Customize the post meta function
add_filter( ‘genesis_post_meta’, ‘post_meta_filter’ );
function post_meta_filter( $post_meta ) {
if ( genesis_get_custom_field ( ‘wps_post_meta’ ) ) //again, no_post_info can be whatever you name your custom field
$post_meta = genesis_get_custom_field ( ‘wps_post_meta’ );
return $post_meta;
}
[/php]

Custom Post Info and Post Meta

What can I do for you!?

Custom Development

We develop plugins by determining both business/functional and technical requirements, following WordPress development best practices, and using agile methodology to ensure you get the best solution.

Consulting

Have questions? Need a reliable developer to consult? Please contact us today!

Customized Theme

We can customize your theme or child theme, or create a child theme for you based on your needs while enhancing the performance of every individual attribute.

Customized Plugin

We can customize your plugins, extend plugins (e.g., Gravity Forms, Jetpack, Soliloquy) based on your needs ensuring security, performance, and positive business impact.

Comments

  1. says

    Thanks for the info… I am using query_args to create a category page and was hoping to set an order for the posts but it does not seem to be working. Wondering if you have tried to do this with any luck?
    cat=4&orderby=date&order=ASC

  2. says

    I’n using Genesis version 1.8.2. I would like to create some Category pages but at this point I cannot remove any categories from the Theme Settings > Blog Page. I understand that if I do this I will not be able to create a category page. I would be willing to live with a category archive page but I can’t seem to remove ANY categories from the Blog page. I am using a page called Blog with the Blog template selected. Help!

Leave a Reply