Support Forum
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,
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.
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,
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,
PS: I also looked up this tutorial here - https://docs.metabox.io/tutorials/display-latest-products-mb-views/
Apprecaite your support.
Kind regards,
Hello,
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 %}
...
That was it! Thanks Peter. Appreciate your support.
Kind regards,