Skip Navigation

[Résolu] Adding A Static Item To A View

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
The user has a grid view and would like to add a static element(add button) as the last grid cell when the view has results less than 18.

Solution:
The best/easy way is to hook into the view and test how many results it has, if less than 18, we'll inject a default post.
Inside the loop we'll create a condition to display a different content template for that default post.

A sample code to inject the post is:

add_filter( 'wpv_filter_query_post_process', 'jts_inject_draft_promo', 10, 3 );
  
function jts_inject_draft_promo( $query, $view_settings, $view_id ) {
    // replace this with the default/draft promo post idate
    $default_promo_id = 123;
     
    if ( $view_id == 784 ) {
        if ( $query_post_count < 18 ) {
            $default_promo = get_post( $default_promo_id );
            $query->found_post[] = $default_promo;
            $query->found_count = $query->found_count + 1;
        }
    }
     
    return $query;
}

A sample code to conditionally display a different Elementor template for the default post is:

[wpv-conditional if="( '[wpv-post-id]' eq '123' )" evaluate="false" ]
<div class="col-md-2">
    [elementor-template id="278"]
</div>
[/wpv-conditional]
[wpv-conditional if="( '[wpv-found-count]' lt '18' )" ]
    <div class="col-md-2">
    [elementor-template id="867"]
</div>
[/wpv-conditional]

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query_post_process

https://toolset.com/documentation/user-guides/using-toolset-with-elementor-page-builder/create-templates-for-custom-post-types-with-elementor-and-toolset/

This support ticket is created Il y a 3 années et 10 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

Marqué : ,

This topic contains 17 réponses, has 2 voix.

Last updated by Ed Il y a 3 années et 10 mois.

Assisted by: Jamal.

Auteur
Publications
#1660499

Ed

Now, I feel like a schmuck, for wanting to use my solution, after you've spent all this time on it. It's simpler (like my brain) and works the way I need it to.

I wouldn't have been able to work through it without following your thought process. I appreciate your help and will probably need more help in the future!

Thank you.

#1660505

Jamal
Supporter

Languages: Anglais (English ) Français (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Awesome! I am really glad I could be of help 🙂

Please mark this ticket as resolved and open a new ticket whenever you need help with the Toolset plugins.

Cheers,
Jamal

#1660507

Ed

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.