WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Apr 29 2011

How to Write a Genesis Custom Loop for Specific Categories in a Genesis Page Template

So I was creating page templates that called for a custom loop for specific categories that I blocked from my blog in my Genesis Settings. To do this, use this page template.

You do not need to use 'cat' which requires the category ID; however, it is always my preference. You can also choose from wp_query:

  • cat (int) - use category id.
  • category_name (string) - use category slug (NOT name).
  • category__and (array) - use category id.
  • category__in (array) - use category id.
  • category__not_in (array) - use category id.

[php]
<?php
/**
*
* Template Name: Projects
* This file handles blog posts with the category Projects within a page.
*
*/

remove_action('genesis_loop', 'genesis_do_loop');
add_action('genesis_loop', 'custom_do_cat_loop');

function custom_do_cat_loop() {
global $query_args; // any wp_query() args
$args= array('cat' => '30');
genesis_custom_loop(wp_parse_args($query_args, $args));
}

genesis();

[/php]

Written by Travis Smith · Categorized: Genesis, Tutorials

StudioPress Premium WordPress Themes     WP Engine Managed WordPress Hosting

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.

Contact Us

About Travis Smith

As a WordPress enthusiast, developer, and speaker, Travis writes about what he learns in WordPress trying to help other WordPress travelers, beginners and enthusiasts with tutorials, explanations, & demonstrations.

Comments

  1. Duncan says

    April 9, 2012 at 7:50 pm

    Hi, you’ve written an extremely helpful post here.

    I had a (hopefully) simple question though regarding the display of category’d posts on a custom template page.

    I’ve successfully managed to create custom template pages that call the specific posts of a specific category on them, however the site I am working with is one that has many posts in each relevant category. I am aiming to build a custom template page that will display only a titled-link and thumbnail of the featured image to the posts with a certain category, having the link and thumbnail link take the user to the specific post of that given category. This will keep clutter down and keep those older posts relevant and viewable (as opposed to burying them 30 pages deep because each FULL post is displayed rather than a link to it).

    Surprisingly i’ve dug around and cannot find any information on this within the Genesis framework. The idea is a page that displays links, like an archive, to posts of a specific category (that I define).

    Any ideas would be GREATLY appreciated! Thanks, and again, good information here

    Reply
    • Travis Smith says

      May 13, 2012 at 7:33 pm

      Hi, you probably want to investigate Display Posts by Bill Erickson.

      Reply
  2. Matt says

    March 15, 2013 at 9:53 pm

    Hey Travis,
    Just wanted to drop you a quick line to say thank you for all the work you have done supporting the WordPress / Genesis community. I have been reading your site for several, several months now off and on and you have helped me out tremendously.

    I have used this post and related other posts specifically to help me do various things on my own site

    Thank you and keep up the good work bro. I really do appreciate it.

    Regards,
    Matt

    Reply
  3. Terence says

    March 28, 2013 at 11:17 am

    HI Travis,
    Brad Dalton send me in your direction because I am trying to figure out how to use the loop in Genesis to integrate a plugin ~ which Duncan (above) can use, I think ~ to integrate Cornerstone content instead of simply running a blog with all the posts in it.

    I want to get rid of the separate blog altogether and integrate all posts using the site’s structure to place them in the correct cornerstone sections.

    I am new to Genesis so I am having difficulties tracking down how the loop works exactly, which is why I ended up here.

    The loop is generally started with the following code:

    [php]
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    [/php]

    For working with posts, I want to organize this new site’s content into “sections” using the Cornerstone plugin [ http://wordpress.org/extend/plugins/cornerstone/ ] and not fake the site structure with categories and tags, so I want to use a couple different functions in place of the default ones:

    [php]
    <?php if ( cnr_have_children() ) : while ( cnr_have_children() ) : cnr_next_child(); ?>
    [/php]

    In the loop, displaying the post’s content should be exactly the same as with any other template in a theme. So I assume I can use template tags such as [php]the_title(), the_excerpt(),[/php] etc.

    Here’s an example loop that displays the title and an excerpt with a link for each post in the section when using Cornerstone…

    [php]
    <?php if ( cnr_have_children() ) : while ( cnr_have_children() ) : cnr_next_child(); ?>
    <h3><?php the_title(); ?></h3>
    <div><?php the_excerpt(); ?></div>
    <?php endwhile; endif; ?>
    [/php]

    So my questions are ~

    A) how is this form of post structuring likely to affect (or not) the loop and other functions within Genesis in general, and more specifically in Dynamik for Genesis?, and

    B) where does the loop start in Genesis?

    C) Can I simply use a Dynamik Custom Hook Box with “genesis_loop” to replace the Genesis loop entirely and not worry about A) & B) ?

    Any ideas?

    Terence.

    Reply
    • Travis Smith says

      May 31, 2013 at 9:05 am

      Hello Terence,

      You are asking several questions here. If you are dealing with a single post page, your structure is simple and straight forward. Here is a sample single post page with the hooks. To look at the Framework, Nick has a great series called Genesis Explained. I hope that helps.

      Reply
      • Terence says

        May 31, 2013 at 9:11 am

        Hi Travis,

        In the intervening period, the entire population of China lost its chance of democracy, the European economy collapsed to an all time low and I gave up struggling with Genesis 1.x.

        Here’s hoping the coming months will be a little more positive for us all.

        Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

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