- This topic has 12 replies, 2 voices, and was last updated 4 years, 1 month ago by
Tom.
-
AuthorPosts
-
May 8, 2019 at 10:00 am #893170
Brad
Objective:
Create a CPT with a flexbox “grid box like” layout for archive page, custom layout for CPT single template.CPT single page has specific layout elements as well with metaboxes in two column, two row responsive div, entry for data within Wp admin. This is a whole other topic / post. Editor will be hidden.
Question on best practice to build CPT custom template for my specific objective:
How do you recommend I go about doing this (build custom template for CPT) with the Generate Press theme?
I’m old school and use to created a duplicate of a template file, renaming it, putting it in my child theme, doing the div layout within the template and then CHOOSING THIS TEMPLATE from within Wp-Admin.
This has confused me for months in how to go about this with GP file structure.
I am aware of Wp template heiarche but that doesn’t seem to be following logic in my initial coding attempts.
On a FB forum a member in another’s post mentioned using get_template_part, create child theme folder structure and create conditional statement to check page being called, this pulling in correct template part.
What is your guy’s suggestions. Please see whiteboard pics. Hopefully it’ll give you a general idea of the single CPT template php I want to build.
The archive CPT template I’ve named as follows in child theme:
archive-recommends.php
CPT is recommends
I haven’t coded the flexbox loop yet but so far it’s NOT inherenting the archive layout of posts which is perplexing.
Question:
Any idea why? I duplicated archive.php naming it archive-recommends.php, put it in the child theme.I replaced the loop with a custom query to only pull on CPT posts named recommends. I would think this would work but it shows all CPT IN FULL VIEW IN A LIST, rather than just CPT TITLE, FEATURE IMAGE.
Thoughts. Thanks in advance for suggestions, feedback and input. I hope all is well.
Brad
May 8, 2019 at 10:45 am #893231Brad
Ok I already discovered one of my mistakes.
I renamed archive-recommends.php
TO
content-recommends.php
Not sure if I’ll get layout changes yet.
May 8, 2019 at 4:14 pm #893492Tom
Lead DeveloperLead DeveloperGP uses standard WordPress templates, so your “old school” way should still work fine.
We do use
get_template_part()
in our templates though, which is where thecontent-xx.php
files are coming from.If you need to adjust the code outside of the
content.php
file, you can just copy the code from thecontent.php
file and replace theget_template_part()
function in the main file with it. That will give you full control over the template all in one file.Let me know if that makes sense or not 🙂
May 8, 2019 at 4:31 pm #893505Brad
I’m a little lost still.
“If you need to adjust the code outside of the content.php file, you can just copy the code from the content.php file and replace the get_template_part() function in the main file with it. That will give you full control over the template all in one file.”
?????
My main goal is a flexbox CPT archive template page for the CPT named recommend.
Would I duplicate content.php, rename it content-recommend.php and place it in my child theme?
right now what’s happening is the entire single posts are listed in list view (rather than just title and image).
May 8, 2019 at 4:42 pm #893520Tom
Lead DeveloperLead DeveloperWould I duplicate content.php, rename it content-recommend.php and place it in my child theme?
If the code you need to adjust exists in
content.php
, then yes.If the code you need to adjust is in
archive.php
(or another template file), you would need to copy that file instead.If you need to adjust the code in both, then you would need both files:
content-recommends.php archive-recommends.php
May 8, 2019 at 4:50 pm #893522Brad
There’s a plugin I think it’s called “what file” or “what file am I using”.
I’m on iPhone now. Not at home. I’m not sure what template is being called. The custom loop is in the content-recommends.php file but that is just being pulled into content.php as it’s considered an archive template part?
I’ll hack away when at home. If you can point me in the right direction I’d sincerely appreciate it.
May 8, 2019 at 4:56 pm #893523Brad
Actually I guess archive-recommends.php would hold my flexbox code.
The get template part being
content-recommends.php would have my custom query loop for the CPT recommends.Or like you mentioned (if I’m following you correctly) just replace the get_tenp_part in archive-recommends.php with my custom CPT loop.
May 8, 2019 at 5:45 pm #893539Tom
Lead DeveloperLead DeveloperExactly, that’s probably the easiest route.
Otherwise, you want to replace this line in your
archive-recommends.php
file: https://github.com/tomusborne/generatepress/blob/2.2.2/archive.php#L42With this:
get_template_part( 'content', 'recommends' );
That will call the
content-recommends.php
file.May 8, 2019 at 6:26 pm #893554Brad
Sincere thanks! I think I’ve got it. Will code it up tomorrow when back on desktop and confirm here.
Thanks again. Have a great night.
Brad
May 9, 2019 at 7:43 am #894224Tom
Lead DeveloperLead DeveloperGlad I could help 🙂
May 9, 2019 at 9:15 am #894352Brad
Ok, hacking away. I posted this in a ACF Facebook group.
Are there any Generate Press Tutorial sites out there that you know of by chance on intermediate developer topics?
____
Confused / new to setting up ACF Pro Flexible Content.
Anyone know of a good tutorial resource regarding coding the template end of the process?
I found a few you tube videos and understand the first half of the process – setting up the desired metabox layout in Wp admin for use.
It’s the second half, coding the template to output it correctly I’m having problems with. Discovering the correct template file, reverse engineering the divs and classes of the parent theme’s developer and then placing the code in the correct area.
Thanks in advance for suggestions.
https://www.advancedcustomfields.com/resources/flexible-content/
May 9, 2019 at 11:53 am #894502Brad
Update — learning acf flexible content on the template side is too complex for this time around with my current deadline / priorities.
Solution – Throwing manually coded grid in CPT post txt editor for responsive layout control. Far from ideal but it’ll work for now. Will have to place acf pro flexible content on my learning curve bucket wish list.
May 9, 2019 at 2:04 pm #894614Tom
Lead DeveloperLead DeveloperDefinitely nothing wrong with that – glad you got something working.
-
AuthorPosts
- You must be logged in to reply to this topic.