Happy Halloween! Get 20% off GP Premium with the discount code: HALLOWEEN20

[Resolved] Building custom template for CPT single / archive php pages with GP

Home Forums Support Building custom template for CPT single / archive php pages with GP

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #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

    #893231
    Brad

    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.

    #893492
    Tom
    Lead Developer
    Lead Developer

    GP 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 the content-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 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.

    Let me know if that makes sense or not 🙂

    #893505
    Brad

    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).

    https://staging.jaclynloveyogi.com/recommends/

    #893520
    Tom
    Lead Developer
    Lead Developer

    Would 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
    #893522
    Brad

    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.

    #893523
    Brad

    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.

    #893539
    Tom
    Lead Developer
    Lead Developer

    Exactly, 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#L42

    With this:

    get_template_part( 'content', 'recommends' );

    That will call the content-recommends.php file.

    #893554
    Brad

    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

    #894224
    Tom
    Lead Developer
    Lead Developer
    #894352
    Brad

    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/

    #894502
    Brad

    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.

    https://docs.generatepress.com/article/creating-columns/

    #894614
    Tom
    Lead Developer
    Lead Developer

    Definitely nothing wrong with that – glad you got something working.

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.