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]