Community Forums › Forums › Archived Forums › Design Tips and Tricks › Implementing Custom Post Type Data
Tagged: custom post types
- This topic has 2 replies, 2 voices, and was last updated 9 years, 11 months ago by brettatkin.
-
AuthorPosts
-
October 28, 2014 at 9:50 pm #129664brettatkinMember
I'm trying to implement the correct code to output custom post type data. This is what I have and it mostly works, but I know it isn't "correct" as far as using the framework goes - I'm not using the genesis() function. The sidebar placement is after the content as well.
Implementing CPT's isn't new to me, just new for Genesis. I created my own plugin to create the new post type and then the Advanced Custom Fields plugin to do the rest.
The working example is http://www.samrhine.com.php53-3.ord1-1.websitetestlink.com/schedule/genetic-update-conference/
This code is in the single-conference.php file. Can someone point me in the right direction here? I'd like to do it the correct way using the genesis() function? I'm betting it would fix my sidebar placement issue as well.
Here is my code:
http://www.samrhine.com.php53-3.ord1-1.websitetestlink.com/schedule/genetic-update-conference/<?php get_header(); ?> <?php while ( have_posts() ) : the_post(); ?> <h1><?php the_title(); ?></h1> <div class="one-third first"> <h2>Date & Time:</h2> <?php $date = DateTime::createFromFormat('Ymd', get_field('conference_date')); ?> <p> <?php echo $date->format('d/m/Y'); ?><br /> <?php the_field('conference_time'); ?> </p> </div> <div class="one-third"> <h2>Location:</h2> <p> <?php the_field('conference_location'); ?><br /> <?php the_field('conference_address'); ?><br /> <?php the_field('conference_city'); ?>, <?php the_field('conference_state'); ?> <?php the_field('conference_zip'); ?> </p> </div> <div class="one-third"> <h2>Host:</h2> <p> <?php the_field('host_name'); ?><br /> <?php the_field('host_school'); ?> </p> </div> <div style="clear:both;"></div> <?php the_content(); ?> <?php endwhile; // end of the loop. ?> <?php get_sidebar(); ?> <?php get_footer(); ?>
October 29, 2014 at 3:06 am #129680Sridhar KatakamParticipantYou can find a sample implementation here: http://www.sridharkatakam.com/single-archive-templates-custom-post-type-genesis/
More @ http://www.sridharkatakam.com/?s=advanced+custom+fields
October 29, 2014 at 12:36 pm #129780brettatkinMemberThank you, I got it working. I'm sure I'll have some more questions, but this got things moving in the right direction.
Here is the code I'm using. I followed the same process for the archive page.
<?php //* Remove the entry meta in the entry header (requires HTML5 theme support) remove_action( 'genesis_entry_header', 'genesis_post_info', 12 ); //* Remove the entry meta in the entry footer (requires HTML5 theme support) remove_action( 'genesis_entry_footer', 'genesis_post_meta' ); //* Display custom fields above entry content add_action( 'genesis_entry_content', 'sr_post_content', 9 ); function sr_post_content() { echo '<div class="one-third first">'; echo '<h2>Date & Time:</h2>'; $date = DateTime::createFromFormat('Ymd', get_field('conference_date')); echo '<p>'; echo $date->format('m/d/Y').'<br />'; echo the_field('conference_time'); echo '</p>'; echo '</div>'; echo '<div class="one-third">'; echo '<h2>Location:</h2>'; echo '<p>'; echo the_field('conference_location'). '<br />'; echo the_field('conference_address') . '<br />'; echo the_field('conference_city') . ', ' . get_field('conference_state') . ' ' . get_field('conference_zip_code'); echo '</p>'; echo '</div>'; echo '<div class="one-third">'; echo '<h2>Host:</h2>'; echo '<p>'; echo the_field('host_name') . '<br />'; echo the_field('host_school'); echo '</p>'; echo '</div>'; echo '<div style="clear:both;"></div>'; } genesis(); ?>
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.