WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Jun 06 2011

How to Create a Genesis Page Template with a Custom Post Type with Custom Content in Custom Fields

Recently, someone asked me how I would create a Genesis Page Template with a Custom Post Type using Custom Fields. One of the great things about Genesis is its ability to easily pull custom fields content. Previously I mentioned how to create a WordPress Custom Post Type Page Template in Genesis. Now, what if I want to have this page template to display custom content via custom fields?

Well here's the right way to do it via Genesis hooks:
[php]
<?php
/*
*Template Name: Author Interview
*/

remove_action('genesis_loop', 'genesis_do_loop');
add_action('genesis_loop', 'custom_do_loop');
function custom_do_loop() {
$mycpt = 'books';
$posts_per_page = 10;
global $paged;
$args = array('post_type' => $mycpt, 'posts_per_page' => $posts_per_page);

genesis_custom_loop( $args );
}

remove_action( 'genesis_post_content' , 'genesis_do_post_content' );
add_action( 'genesis_post_content' , 'genesis_do_custom_post_content' );

function genesis_do_custom_post_content() { ?>
<div id="post-<?php the_ID(); ?>" class="book-info">
<h3>Book Information</h3>
<p class="book-description"><strong>Description</strong>: <?php echo genesis_get_custom_field('_type'); ?></p>
<p class="book-pages"><strong><?php echo genesis_get_custom_field('_type'); ?></strong>: <?php echo genesis_get_custom_field('_pages'); ?> pages </p>
<p class="book-publisher"><strong>Publisher</strong>: <?php echo genesis_get_custom_field('_publisher'); ?> (<?php echo genesis_get_custom_field('_pub_date'); ?>)</p>
</div><!--end .book-info -->
<div id="post-<?php the_ID(); ?>" class="book-review">
<?php the_content(); //OR, the_excerpt(); OR, the_content_limit( (int)genesis_get_option('content_archive_limit'), __('[Read more...]', 'genesis') ); ?>
</div><!--end .book-review -->
<?php
}

genesis();
?>
[/php]

Written by Travis Smith · Categorized: WordPress

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. Scott says

    March 26, 2012 at 5:24 pm

    Hello, and thanks for sharing this. One question: how do I add the page title to this? I tried removing the post title and creating a custom post title, but that adds it to every entry. Thanks, Scott.

    Reply
    • Travis Smith says

      April 2, 2012 at 8:12 am

      Hello Scott,

      You will need to add the page title to the genesis_before_loop hook, so it appears outside the hook as a page title.

      Thanks,

      Travis

      Reply
  2. chuck says

    June 27, 2012 at 12:19 pm

    Thank you so much for your great tutorials. I have this working great. But, what I would like to do is filter this by taxonomy or category without creating a separate template. I have looked for how to do this and I cant seem to find the solution.
    I have a page, I am selecting the template to use. But how to I tell the page to filter just one category or taxonomy? I have tried through urls, query_args, adding categories to the page, nothing seems to work. Maybe you can just point me in the right direction. Thank you very much for any help you can give.

    thanks,

    chuck

    Reply
    • Travis Smith says

      July 17, 2012 at 10:28 am

      Hello Chuck,

      What do you mean filter by taxonomy or category? Not really following you there.

      Reply
  3. David Hilditch says

    August 2, 2012 at 8:23 pm

    I have the same problem as chuck – see the following two links – they produce the SAME output.

    I want to use the grid loop but I want it to behave like the standard loop in that it should pull back only the relevant posts based on the /category/slug/ and the ?tag=xxx.

    e.g. http://www.fitness-saver.com/category/buying-guides/?tag=cycling-2 should be different to http://www.fitness-saver.com/category/buying-guides/?tag=football but they’re not 🙁

    See the problem? The grid loop shows the same content regardless of which category the page is on. There must be something fundamental both myself and Chuck are not getting.

    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