Reusable Template Parts
- This topic has 6 replies, 2 voices, and was last updated 1 year, 5 months ago by
Unakriti.
-
AuthorPosts
-
May 23, 2024 at 1:35 PM #45500
Unakriti
ParticipantHi 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,
May 23, 2024 at 6:09 PM #45506Peter
ModeratorHello,
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.
May 23, 2024 at 6:57 PM #45508Unakriti
ParticipantThank 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,
May 23, 2024 at 7:01 PM #45509Unakriti
ParticipantPS: 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/QWEYpRRKind regards,
May 24, 2024 at 2:31 PM #45520Unakriti
ParticipantPS: I also looked up this tutorial here - https://docs.metabox.io/tutorials/display-latest-products-mb-views/
Apprecaite your support.
Kind regards,
May 25, 2024 at 2:50 PM #45535Peter
ModeratorHello,
I see the issue. You can check the code to open the loop in the documentation
{% for post in posts %}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 %} ...May 25, 2024 at 9:35 PM #45539Unakriti
ParticipantThat was it! Thanks Peter. Appreciate your support.
Kind regards,
-
AuthorPosts
- You must be logged in to reply to this topic.