Site logo

[Resolved] How to customize Custom post Archive, category and single

Home Forums Support [Resolved] How to customize Custom post Archive, category and single

Home Forums Support How to customize Custom post Archive, category and single

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2495437
    Utopia – Arquitectura e Engenharia Lda

    Hi,
    I created a custom post type.

    Now I want co customize the following:
    – custom post type archive
    – custom post type categories
    – custom post type single post

    I noticed that when in the wordpress backend I select / customize / layout / blog / I can make changes on buttons, but things like columns just don’t work on custom post types.

    So, my questions are:
    1) Can we make blog settings affect custom post types? ( This would be great for customization.)
    2) Do you have a good tutorial for customizing archives and categories pages display properties with elements?
    3) Can we customize the sinle custom post type template and insert things like navigating only inside category? Can you point me to a good elements tutorial on this?

    #2495632
    Ying
    Staff
    Customer Support

    1) Can we make blog settings affect custom post types? ( This would be great for customization.)

    No, as the theme doesn’t know about the CPT. you will need to use some filters to make the blog settings apply to cpt.

    2) Do you have a good tutorial for customizing archives and categories pages display properties with elements?

    If you have the GenerateBlocks plugin installed, you can create a block element, add a Query loop block in it, set it to inherit the default loop, and set the location accordingly.

    In this way, you can control the layout and style of the CPT archives.

    3) Can we customize the sinle custom post type template and insert things like navigating only inside category? Can you point me to a good elements tutorial on this?

    Yes, you can use theblock element - content template and assign it to CPT posts.
    Yes, you can use the block element - hook to insert the navigation and assign it to category archives.

    You can see all documents about block elements:
    https://docs.generatepress.com/?s=block+element

    #2504104
    Utopia – Arquitectura e Engenharia Lda

    Hi Ying,
    Great support, thanks.
    I just couldn’t find a way to navigate inside the category. It navigates on all categories… Sorry for beeing so noob.

    If i add a block element hook, I need code to place there.
    a) Can you point me to the code I should insert to restrict the navigation to the most specific category?
    Also, I noticed that we could add a block element and a post navigation too. It has templates but I couldn’t manage to restrict it to same category too.
    b) What are the advantages of each aproach: The block element vs hook element?

    #2504627
    David
    Staff
    Customer Support

    Hi there,

    a. Post Navigation
    Built in Theme Navigation
    The theme outputs a post nav for you. And it offers this filter hook generate_category_post_navigation.
    It it is used to limit next/prev post links to posts within the same term.
    You can make it so by adding this PHP Snippet to your functions.php:

    add_filter('generate_category_post_navigation','__return_true');

    Hook Element
    This would require custom PHP.
    to create the next and previous links you can use core functions eg.

    https://developer.wordpress.org/reference/functions/get_next_post/
    https://developer.wordpress.org/reference/functions/get_previous_post/

    And those functions have params to set various options.

    eg. get_previous_post(true) would return the previous post that is in the same term.

    Block Element Post Navigation
    If you add a Dynamic Link and set its Links Source to Next Post or Previous Post, you can select the Option: In same term. See here for an example using on of the prebuilt layouts:

    https://www.screencast.com/t/PUOdyPblWCXe

    b. Hook Element vs Block Element
    The Block element can do more than the hook element.
    With it you can create Loop Templates and Content Templates whereas you cannot do this with Hook Element.
    Block Element can also use ALL the hooks that are available in Hook Element.

    Hook Element is best for when wanting to add smaller amounts of code. Some examples:
    Scripts such as Google Analytics or Meta tags such as noindex that are added to the wp_head or wp_footer
    Adding additional content in the theme where there is no block element option to do so.

    Overall the main decision will come down to if you preper building advanced layouts without ( or with less ) code.

    #2505170
    Utopia – Arquitectura e Engenharia Lda

    Hi David
    As always, your help is great!
    The explanation was perfect, thank you!
    🙂

    #2505609
    David
    Staff
    Customer Support

    Glad to be of help!

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