Reusable Template Parts

Support MB Views Reusable Template PartsResolved

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #45500
    UnakritiUnakriti
    Participant

    Hi Support,

    Folowing up from the my question at https://support.metabox.io/topic/mb-view-css-on-hover-not-applying/#post-45492

    Besides an archive page, I want to display service cards as a section on the home page, and so I followed the MB docs (Create Reusable Template Parts) to use the following code but I am not getting the desired result. Could you please advise?

    {% set args = {post_type: 'service', posts_per_page: -1} %}
    {% set posts = mb.get_posts( args ) %}
    <div class="service-card">
        {% for post in query.posts %}
            <div class="card-inner">
                <p class="card-icon" style="width:2em;">{{ post.service_icon }}</p>
                <h5 class="card-title">{{ post.title }}</h5>
                <p class="card-excerpt">{{ post.service_excerpt }}</p>
            </div>
        {% endfor %}
    </div>

    Kind regards,

    #45506
    PeterPeter
    Moderator

    Hello,

    I assume that you are following the documentation https://docs.metabox.io/tutorials/create-reusable-template-parts/

    How do you show the View template on the homepage? Please share a screenshot of that step and a full screenshot of the View template.

    #45508
    UnakritiUnakriti
    Participant

    Thank you

    I use a shortcode to output the MB View on the home page.

    Here's a screenshot please https://imgur.com/a/EAc5a8s

    Kind regards,

    #45509
    UnakritiUnakriti
    Participant

    PS: Forgot to attach the remaining two screenshots. Here these are for your reference:

    1. In Gutenberg: https://imgur.com/a/zP4B0vU
    2. In MB Views: https://imgur.com/a/QWEYpRR

    Kind regards,

    #45520
    UnakritiUnakriti
    Participant

    PS: I also looked up this tutorial here - https://docs.metabox.io/tutorials/display-latest-products-mb-views/

    Apprecaite your support.

    Kind regards,

    #45535
    PeterPeter
    Moderator

    Hello,

    I see the issue. You can check the code to open the loop in the documentation

    {% for post in posts %}
    

    https://docs.metabox.io/tutorials/display-latest-products-mb-views/#3-displaying-posts-and-its-information-on-the-page

    but in your code, it is

    {% for post in query.posts %}
    

    remove the query variable and check the issue again. Or use another variable name to avoid confusion:

    {% set service_posts = mb.get_posts( args ) %}
    <div class="service-card">
        {% for post in service_posts %}
    ...
    
    #45539
    UnakritiUnakriti
    Participant

    That was it! Thanks Peter. Appreciate your support.

    Kind regards,

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