Site logo

[Resolved] Any advanced docs? Elements – Content Template – Apply to Post w term – Location

Home Forums Support [Resolved] Any advanced docs? Elements – Content Template – Apply to Post w term – Location

Home Forums Support Any advanced docs? Elements – Content Template – Apply to Post w term – Location

Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #2105784
    Brad

    Any support links, tutorial, documentation you can point me to? Very difficult to google topic and get relevant hits. Elements – Content Template – Apply to – Post with term

    QUESTION:
    Is there any documentation on the “red marked section” on my screenshot.
    Also specifically on the “blue marked section”
    Display Location: Showcase Video Production Archive – All Video Production

    https://www.dropbox.com/s/c1oexqwtarudjso/location-elements.jpg?dl=0

    Trying to do something that’s going to be hard to explain; hence will just do one thing at a time and rule things out as to what works and what doesn’t.

    Sincere thanks for patience and your assistance.

    Brad

    _________________________________________
    _________________________________________

    1.
    BACKGROUND:
    I have a CPT named “showcase” which has six taxonomies with hierarchy: true so they “act like categories” of the CPT.
    (I’m getting ready to delete them all and just use WP Core Categories).
    The problem is they have no true archive page themselves.

    Using GenerateBlocks Pro I design Content Templates to replace the default template for the “showcase” archive.

    Location – All Showcase archives

    2.
    THE CHALLENGE:
    I have six (6) taxonomies (cpt categories) assigned to the “showcase” CPT. I’d like each one to have a different wrapper background color container.
    User would only see this on the archive page of the showcase page in a grid layout.

    3.
    ELEMENT CSS SOLUTION INTO HEADER:
    After a few days of research, trial and error, this is what I came up with…

    // add inline style to header for cpt container block

    add_action(‘wp_head’, ‘j66co_showcase_container_wrapper_colors’, 100);

    function j66co_showcase_container_wrapper_colors()
    {
    echo “<style>.j66co-cpt-main-wrapper{background-color: #1c2023;}</style>”; // dark black – archives all
    echo “<style>.j66co-cpt-main-wrapper-01{background-color: #0ab2e1;}</style>”; // bright blue – campaigns 01
    echo “<style>.j66co-cpt-main-wrapper-02{background-color: #1c2023;}</style>”; // dark black – j66 products 02
    echo “<style>.j66co-cpt-main-wrapper-03{background-color: #1c2023;}</style>”; // dark black – photography 03
    echo “<style>.j66co-cpt-main-wrapper-04{background-color: #57bb55;}</style>”; // moss green – video production 04
    echo “<style>.j66co-cpt-main-wrapper-05{background-color: #a6191b;}</style>”; // brick red – web apps 05
    echo “<style>.j66co-cpt-main-wrapper-06{background-color: #a6191b;}</style>”; // brick red – web design 06
    }

    add_action(‘wp_head’, ‘j66co_showcase_container_wrapper_colors’, 100);

    https://www.dropbox.com/s/l4plgfjkqghb47y/css-class-elements.jpg?dl=0

    4.
    THIS IS WHERE I’M AT NOW…

    Which brings me to the reason of the question of this post.. Display parameters.

    I’ve tried setting the Display – All CPT Taxonomy posts and it doesn’t show up on the archive page of showcase.
    If I can load all six variations of the element blocks posts on to the same archive page, the correct background-color class color will be applied because each element container of the 6 have a different class name.

    I’ll attempt coding a custom loop archive page. Just not sure where the GenerateBlocks “blue box” (Display Location: Showcase Video Production Archive – All Video Production ) markup applies. There’s no archive video_production page like there is with Wp category core

    #2106138
    David
    Staff
    Customer Support

    Hi there,

    have you watched this video:

    It shows how to create a Global/Fallback content template ( Using Display Rules Locations ) and then Content Templates for specific taxonomy terms ( Using the Apply To methods ).

    Might be just what you need.

    #2106439
    Brad

    Yes I have seen it. It’s great! Sincere thanks for forwarding the link. That’s what actually inspired me.

    The issue are these CPT with assigned taxonomies and the WP limitations out of the box to have it connected. Hopefully in future version they’ll see a need to “fix” this. I can’t be the only one though it’s difficult to google / find on stackexchange / other sites.

    This is a dev site install I’m working on. I’ll mess around with it.

    I may just ditch custom taxonomies, which I’d rather not do, and just use the built in Wp Core Categories. I think Leo’s video tutorial would allow me to accomplish my “Main Goal” (different colored wrapper containers for the CPT showcase based on one of six categories (this time using Wp core categories rather thank custom taxonomies)).

    Sincere thanks for all your guys and gals help / patience the last few support questions. I really appreciate it.

    This is going to be my business portfolio site so it’s important to me to really showcase my vision and style, be representational of creative solutions I design and develop for my products ideas for launch as well as the value I bring to the table with solving client needs.

    #2106486
    Brad

    Well, the idea of allowing use of categories to CPT actually doesn’t work surprisingly in my preliminary test. When you click on the category to look at the category archive, only post archive show up.

    Thus, Leo’s tutorial I don’t think will work. I use All in one migration form backups. I’ll give it a go and try it, reverse it if not.

    #2106635
    Brad

    Ok. This is what I have. This isn’t work though. Does this strategy make any sense. Appreciate input. My coding if statements may be incorrect. Basically I have a CPT named “showcase”. I now have six Wp core categories. I’m trying to run an if statement to check if..
    is_post_type_archive ( ‘showcase’ )
    And next if it has a Wp core category of …. one of six
    has_category(‘campaign’)

    If so, echo out inline style of background-color that i already got working in first function assigned to same class. Possibly the issue is it now needs to “override that style”???

    ________________________________

    // add inline style to header for cpt container block

    add_action(‘wp_head’, ‘j66co_showcase_container_wrapper_colors’, 100);

    function j66co_showcase_container_wrapper_colors()
    {
    echo “<style>.j66co-cpt-main-wrapper{background-color: #1c2023;}</style>”; // dark black – archives all
    }

    add_action( ‘wp_head’, ‘j66co_color_container’, 900 );

    function j66co_color_container() {
    if ( is_post_type_archive ( ‘showcase’ ) && has_category(‘campaign’)) {
    echo “<style>.j66co-cpt-main-wrapper{background-color: #0ab2e1;}</style>”; // bright blue – campaigns 01
    }
    if ( is_post_type_archive ( ‘showcase’ ) && has_category(‘j66_product’)) {
    echo “<style>.j66co-cpt-main-wrapper{background-color: #1c2023;}</style>”; // dark black – j66 products 02
    }
    if ( is_post_type_archive ( ‘showcase’ ) && has_category(‘photography’)) {
    echo “<style>.j66co-cpt-main-wrapper{background-color: #1c2023;}</style>”; // dark black – photography 03
    }
    if ( is_post_type_archive ( ‘showcase’ ) && has_category(‘video_production’)) {
    echo “<style>.j66co-cpt-main-wrapper{background-color: #57bb55;}</style>”; // moss green – video production 04
    }
    if ( is_post_type_archive ( ‘showcase’ ) && has_category(‘web_app’)) {
    echo “<style>.j66co-cpt-main-wrapper{background-color: #a6191b;}</style>”; // brick red – web apps 05
    }
    if ( is_post_type_archive ( ‘showcase’ ) && has_category(‘web_app’)) {
    echo “<style>.j66co-cpt-main-wrapper{background-color: #a6191b;}</style>”; // brick red – web design 06
    }
    }

    https://blocks-01.j66labs.co/showcase/

    #2106936
    David
    Staff
    Customer Support

    Question 1 – do you want your CPT to display in an Archive thats using the default Category Taxonomy ?
    If so then you need to add your CPT to those queries:

    https://wpbeaches.com/show-custom-post-types-category-archive-page/

    Question 2 – the styles adding to: j66co-cpt-main-wrapper do you want these applied to the individual archives or the individual posts that are displayed in /showcase ?

    #2106957
    Brad

    Hi David,

    Sincere thanks for the reply

    Question 1:
    Nice!! This is a bonus. Didn’t know it was possible. The only problem with it now is it’s defaulting to Wp template structure and not using the GeneratePress setup i have with either a Element header blocks or Element Content template for All CPT archives which would be the grid we just left, yes. Alternately, it may be the Wp core category layout archive grid layout. Not sure if I built one. I’ll check/

    Either way, Elements header isn’t being pulled in though

    https://blocks-01.j66labs.co/category/web-app/

    ______________________________________

    Question 2

    Style for class is to be applied only to the archive page for the CPT showcase. The class name, .j66co-cpt-main-wrapper , only exist in the Elements – Content Template that replaced the template for location – All Showcase Archives

    Hence, design goal is a color grid of CPT on showcase archive page. If statement echos <style> background-color into .j66co-cpt-main-wrapper of each archive post container wrapper conditionally based on if its a)showcase cpt b)which category it belongs to.

    #2107252
    David
    Staff
    Customer Support

    1. Make sure the Display Rules you have set in your Block Element – Content Template include those Archives.

    2. So if each post of a different category requires a different background then its simplest to target the category-* class on the container.

    https://www.screencast.com/t/4Dback9OcHJ

    eg,

    .category-web-app .j66co-cpt-main-wrapper {
        /* Add styles for the web app category */
    }

    OR that is where the video by Leo comes into play allowing you to create additional Content Templates for specific Apply to conditions.

    #2113510
    Brad

    Ok i actually got this to work. It finally made sense once I assigned Wp core categories to it cpt that i could use straight up css. Sincere thanks for the tip.

    Is there a filter though to make the other issue 1 work? It’s set correctly. It’s the same thing with Elements – Block – Header. Location won’t let me choose “All category archives”. It switches back to All Showcase archives. All continue to search the GP forum / google.

    #2113528
    Brad

    Just tried adding this.. full code as follows

    // show CPT in Categories
    // https://wpbeaches.com/show-custom-post-types-category-archive-page/

    function j66co_show_cpt_archives( $query ) {
    if( is_category() || is_tag() && empty( $query->query_vars[‘suppress_filters’] ) ) {
    $query->set( ‘post_type’, array(
    ‘post’, ‘nav_menu_item’, ‘showcase’
    ));
    return $query;
    }
    }
    add_filter( ‘pre_get_posts’, ‘j66co_show_cpt_archives’ );

    add_filter( ‘generate_elements_custom_args’, function( $args ) {

    $args[‘suppress_filters’] = true;

    return $args;

    } );

    #2113689
    Elvin
    Staff
    Customer Support

    Hi Brad,

    In cases where the display rule location dropdowns may not suffice, this may be the filter you need if you have to define a specific display:
    https://docs.generatepress.com/article/generate_element_display/

    Example usages are provided within the documentation. 🙂

    #2113895
    Brad

    Sincere thanks for the reply. Trying this solution. I can’t figure out how to find the ID of the cpt archive page though.

    Any workarounds to locate archive id. Slug is archive-showcase.php

    // Display an Element to a Parent Page and All Child Pages
    // Another useful example is to set the hook to display on the parent page and all the child pages automatically:

    add_filter( ‘generate_element_display’, function( $display, $element_id ) {
    global $post;

    if ( 605 === $element_id && ( is_page() && $post->post_parent == ‘415’ ) ) {
    $display = true;
    }

    return $display;
    }, 10, 2 );

    // You need to replace 1180 with the ID of your Element (YES – I DID THIS).
    // and 415 with the ID of the parent page (CAN’T DO THIS. CAN NOT FIND OUT ID OF the CPT ARCHIVE PAGE)

    #2113950
    Elvin
    Staff
    Customer Support

    The ID of the CPT archive page can be taken by doing a var_dump(get_queried_object_id()); or var_dump(get_queried_object());. 😀

    The 2nd one lists all the information about the archive page. The 2nd one only shows the ID. 🙂

    #2114073
    Brad

    Interesting…. on the archive-showcase.php and archive-photography.php pages it comes back int(0)

    I’m using the following code within the corresponding template file:

    $posts = get_posts( );
    echo ‘

    ';
    var_dump(get_queried_object_id());
    echo '

    ‘;
    die( );

    On single-showcase.php and single-photography.php it’s showing the actual id. Unfortunately this isn’t the id i need.

    Irregardless though. Generate Press isn’t accepting the Element Block Content Template Setting. It’s falling back to the wp default template category archive template.

    https://blocks-01.j66labs.co/showcase/ —-> int(0)

    Goal:
    To make the CPT category pages “accept” the layout of Archive Photography
    https://blocks-01.j66labs.co/photography/ —-> int(0)

    Or
    Archive Showcase
    https://blocks-01.j66labs.co/showcase/ —-> int(0)

    #2116204
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Trying to read through the topic but I’m a little lost.

    Goal:
    To make the CPT category pages “accept” the layout of Archive Photography

    So you want this page: https://blocks-01.j66labs.co/showcase/

    To look like this page?: https://blocks-01.j66labs.co/photography/

    If so, the regular Display Rules aren’t working if you include the showcase archives in them?

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