Community Forums › Forums › Archived Forums › General Discussion › Custom Post Type Structure
- This topic has 7 replies, 2 voices, and was last updated 9 years, 4 months ago by Porter.
-
AuthorPosts
-
February 21, 2015 at 9:14 am #141636PorterParticipant
I'm going to attempt to rebuild my setup using Custom Post Types (I currently use pages, and Advanced Custom Fields). That being said, I have a few questions about the structure that I'm hoping I can get some insight on.
For starters, a bit about my site. My site is focused on night life / tourism in the Burlington, Vermont area. As of now, I plan to cover bars, dining, music, hotels, local events, and eventually more (such as taxi companies). Within each category, I have sub categories, like so:
Bars
Music
-Artists
-ShowsDining
-Restaurants
-Diners
-Delis
-Street VendorsLodging
-Hotels
-Inns
-Bed And Breakfasts
-ResortsMy two largest concerns are as follows:
-Do I make a custom post type for each main category (Bars, Music, Dining, Lodging), for every category (sub categories each getting their own, with a parent custom post type of the main), or do I simply make a "Venue" custom post type? I've never actually worked with custom post types, so I'm not sure how much organization here is "over engineering", or if being as specific as possible is preferred.
-This part really confuses me - do I use the archive pages for these custom post types, or can I keep my normal "page" setup for the hubs of each category? Every main category has a template (for all of them, handled dynamically), as does every sub category (also using a template, dynamic). For instance, I need the url structure to remain site.com/dining/restaurants/venue-name, with site.com/dining being a "hub" page that leads to all dining options (my template does this), restaurants being the hub for restaurants (it has a template as well), and the venue using the specified template. Can I retain the hierarchy for my urls, and should I keep using "pages" for the "hub" areas, or should I handle it differently?
I know that's a lot to read / take in, but I really want to make sure I structure this correctly, as there's kind of no going back once I lock it in and starting building out. Keep in mind that this site is for me only, and that code / structure is for my eyes only.
anightinburlington.com
February 21, 2015 at 9:49 am #141641Victor FontModeratorSounds to me like you're over engineering this. Custom post types are still just posts. Why wouldn't you just use posts? What advantage do you think CPTs will provide?
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?February 21, 2015 at 9:55 am #141642PorterParticipantRegardless of if I use custom post types or not, they're more like "pages", not posts. I'm not using WordPress as a blog by any means, I'm creating a full blown site / turning it into more of a CMS. All of this content is static, like a directory of sorts.
That being said, seemingly, the advantage is organization. There will be roughly 50+ restaurants, 20+ bars, 10+ hotels, etc etc. With the current structure, everything I create is piled under "pages" (with actual articles I write going under "posts"). This makes the pages section extremely cluttered, and it's a bit hard to properly navigate the back end. If I use custom post types, my dashboard will have designated areas for at the very least venues, or even further for each category. If I wanted to add a Restaurant, I'd visit that tab, create a new entry, and specifically have meta boxes for all "restaurant" related items (think fields for price range, does it deliver, do take out, etc).
Assuming that I can replicate exactly what I'm doing now with pages and the Advanced Custom Fields plugin, even just the added organization would be a bonus.
February 21, 2015 at 10:32 am #141646Victor FontModeratorIt's still going to be complicated and you'll have to do a lot of custom coding to display the custom post types on the front end. You'll still have to use custom fields or build custom metaboxes for the additional details. For each custom post type you create, you need to create a custom page template to display the posts associated with that category.
For example, for each custom post type, you would need to a make a copy of page_blog.php from the main Genesis directory and rename it to page_cptname.php, copy the new file to your child theme directory, then add the following code:
remove_action('genesis_loop', 'genesis_do_loop'); add_action('genesis_loop', 'mycpt_do_loop'); function mycpt_do_loop() { global $paged; $args = array('post_type' => 'mycpt_name'); genesis_custom_loop( $args ); } genesis();
Remember to save permalinks after you create the cpts or they won't display.
Because you want to use a CPT for each category, you won't be able to create a category hierarchy using categories. You can create a hierarchy though using a menu.
Hope this helps.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?February 21, 2015 at 10:55 am #141651PorterParticipantThanks for the input, much appreciated.
The coding aspect isn't an issue in the slightest for me (6+ years of programming, game development, etc), it's just the organization / structural aspect that's hanging me up (a common occurrence with me and programming). Due to the nature of my names, I've actually already programmed some very handy dynamic code. I'm currently grabbing a string from the url, parsing it, and dynamically loading all related content based on that. Since "Bars" will show "bars" in the url, Dining "dining", and so on, I was able to create a system that queries anything I need with a single template that I apply to any "sub-category". That being said, the querying aspect isn't an issue, nor is the programming, it's just a structure / organization / is this future-proof question. Long story short, I don't want to half-ass this setup, and I want to do it once, and set it in stone.
Also, I found this in the WordPress Codex:
"hierarchical
(boolean) (optional) Whether the post type is hierarchical (e.g. page). Allows Parent to be specified. The 'supports' parameter should contain 'page-attributes' to show the parent select box on the editor page.
Default: false"What I'm gathering from that, is I can actually set that boolean to true, and enable the "page" parent / child relationship behavior. While a bit advanced, what I'm seeing in the codex is a LOT of exposed variables, allowing me to essentially create "Pages" (hierarchy system in place), with custom meta boxes, that get their own organization on the back end. Any experience or knowledge about that hierarchical boolean?
February 21, 2015 at 11:20 am #141656Victor FontModeratorWhat the hierarchy does is allow you to create a parent child relationship within a single custom post type. You will not be able to create a hierarchy of different post types the way you want to engineer this. You will see the hierarchy in the all posts admin screen and when displayed on the front end, the permalink will display the hierarchy. Here is some code that you can add to your functions.php that will allow you to experiment with hierarchy.
add_action( 'init', 'register_my_cpts' ); function register_my_cpts() { $labels = array( 'name' => 'CPTs', 'singular_name' => 'CPT', ); $args = array( 'labels' => $labels, 'description' => 'My Custom Post type', 'public' => true, 'show_ui' => true, 'has_archive' => true, 'show_in_menu' => true, 'exclude_from_search' => false, 'capability_type' => 'post', 'map_meta_cap' => true, 'hierarchical' => true, 'rewrite' => array( 'slug' => 'cpt', 'with_front' => true ), 'query_var' => true, 'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'comments', 'revisions', 'thumbnail', 'page-attributes', 'post-formats' ), 'taxonomies' => array( 'category', 'post_tag' ) ); register_post_type( 'cpt', $args ); // End of register_my_cpts() }
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?February 21, 2015 at 11:51 am #141660PorterParticipantAh, so it would simply allow me to create a "venues" custom post type, and have instances of that custom post type have parent child relationships with each other, which isn't of any use to me.
I think I'm going to have to do some hands on work with this to see what I can and can't come up with.
May 10, 2015 at 11:39 am #151529PorterParticipantI ended up going with a single "Venues" custom post type, and used the Advanced Custom Fields plugin to organize smaller details, such as "category", and various other information.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.