Community Forums › Forums › Archived Forums › Design Tips and Tricks › Oh woe is me, for I am a man with custom post type & taxonomy display disorder!
Tagged: CPT, custom post types
- This topic has 4 replies, 2 voices, and was last updated 9 years, 9 months ago by
blommie.
-
AuthorPosts
-
June 9, 2015 at 5:25 am #155558
blommie
MemberHath not thou mercy for such a soul as I? Canst not thou see mine struggles?!?
I really CAN NOT grasp displaying custom content types.
I have the following custom post type set up (in a plugin):
// Initialise custom post type add_action( 'init', 'jb_create_property_listing' ); function jb_create_property_listing() { register_post_type( 'properties', array( 'labels' => array( 'name' => 'Properties', 'singular_name' => 'Property', 'add_new' => 'Add New', 'add_new_item' => 'Add New Property', 'edit' => 'Edit', 'edit_item' => 'Edit Property', 'new_item' => 'New Property', 'view' => 'View', 'view_item' => 'View Property', 'search_items' => 'Search Properties', 'not_found' => 'No Properties found', 'not_found_in_trash' => 'No Properties found in Trash', 'parent' => 'Parent Property' ), 'public' => true, 'menu_position' => 15, 'supports' => array( 'title', 'editor', 'comments', 'thumbnail', 'custom-fields', 'excerpt', 'revisions' ), 'taxonomies' => array( 'jb_property_types', 'jb_number_of_rooms', 'jb_number_of_bathrooms', 'jb_number_of_bathrooms_ensuite', 'jb_location' ), 'menu_icon' => 'dashicons-admin-home', 'has_archive' => true ) ); } add_filter( 'template_include', 'include_template_function', 1 ); function include_template_function( $template_path ) { if ( get_post_type() == 'properties' ) { if ( is_single() ) { // checks if the file exists in the theme first, // otherwise serve the file from the plugin if ( $theme_file = locate_template( array ( 'my-templates/single-properties.php' ) ) ) { $template_path = $theme_file; } else { $template_path = plugin_dir_path( __FILE__ ) . '/single-properties.php'; } } } return $template_path; }
This is for creating a real estate custom post type. (I'll be adding some taxonomies with the next tutorial I follow.)
The problem is, how the heck do I display this CPT in a single page (or is it post???) and create an archive page for it.
This, for now, would be great to start with (for a single view):
<p><?php the_field('property_type'); ?> <p><?php the_field('area'); ?> <p><?php the_field('number_of_rooms'); ?> <p><?php the_field('number_of_bathrooms'); ?> <p><?php the_field('number_of_garages'); ?> <p><?php the_field('floor_size'); ?> <p><?php the_field('plot_size'); ?> <p><?php the_field('garden'); ?> <p><?php the_field('map_location'); ?> <p><?php the_field('property_images'); ?> <p><?php the_field('distance_from_beach'); ?>
I'll add style later.
I use the Genesis framework, Dynamik and Advanced Custom Fields Pro. Wish I could blame my tools, but it's me that's stoopid.
I've tried reading Carrie Dills' stuff, Brad Dalton, Nick the Geek; you name them, I've read them. STILL, I cannot figure out how to go about doing this correctly.
Living in Jeffreys Bay is a drag!
June 9, 2015 at 8:18 am #155567Brad Dalton
ParticipantWould be far easier modifying AgentPress Pro as it already includes all the code you need for CPT's taxonomies as well as custom fields, single cpt and archive cpt and taxonomy. It also integrates with the AgentPress Pro Listings plugin.
June 9, 2015 at 8:28 am #155569blommie
MemberHi Brad,
Thanks for your reply.
I don't like AgentPress Pro, for the reason that I prefer to use Dynamik.
Maybe I could hack some code out of there for the single and archive pages. That's an idea.
Thanks!
When you coming over for a surf?
Living in Jeffreys Bay is a drag!
June 9, 2015 at 9:45 am #155581Brad Dalton
ParticipantI surf nearly every day but Jeffreys Bay has too many Noah's arks!
You could also grab all the PHP code from the Executive Pro theme which includes all the templates.
June 9, 2015 at 9:50 am #155582blommie
MemberThat's a great idea. Think I'll rip some code out of that template.
The surf's been cooking the last week or so. If ever you're over here, say howzit! In fact, I might be able to offer you some free accommodation.
Cheers!
Living in Jeffreys Bay is a drag!
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.