htmlbootstrap-4jinja2erpnextfrappe

ERPNext Web Template - How to show specific category of Blog Posts


I want to show only a select/specific category of Blog Posts in Webpage Section added using the built in Page Builder.

Have created this Web Template in EPRNext to Show Blog postings on any WebPage by adding a Section using Page-Builder. This works fine to show the Blog Posts. But I want to show only a select category of Posts. What should I add.

`

<section class="container my-5">
    <h2 class="section-title">{{ _('जलक्रांतीच्या गाथा') }} </h2>
    <p class="section-description">{{ _('ब्लॉगच्या माध्यमातुन') }} </p>

    <div class="row">
        {% for post in frappe.get_all("Blog Post", fields=["title", "blogger", "blog_intro", "route", "meta_image"], order_by="published_on desc", limit=6) %}
        <div class="col-md-4 mb-4">
            <div class="card h-100">
                <img src={{ post.meta_image }} alt="" class="image-wiih-blur card-img-top image-loaded" max-width="400" max-height="400">
                <div class="card-body">
                    <h5 class="card-title">{{ post.title }}</h5>
                    <p class="card-subtitle mb-2 text-muted">{{ _('By {0}').format(post.blogger) }}</p>
                    <p class="card-text">{{ post.blog_intro }}</p>
                </div>
                <div class="card-body flex-grow-0">
                    <a href="{{ post.route }}" class="card-link">{{ _('पुढे वाचा') }}</a>
                </div>
            </div>
        </div>
        {% endfor %}
    </div>
</section>

`


Solution

  • <section class="container my-5">
        <h2 class="section-title">{{ _('जलक्रांतीच्या गाथा') }} </h2>
        <p class="section-description">{{ _('ब्लॉगच्या माध्यमातुन') }}</p>
    
     {% set category = frappe.get_doc("Blog Category", selected_category_name) %}
    
    
        <div class="row">
            {% for post in frappe.get_all("Blog Post", fields=["title", "blogger", "blog_intro", "route", "meta_image"], filters={"blog_category": category.name}, order_by="published_on desc", limit=6) %}
            <div class="col-md-4 mb-4">
                <div class="card h-100">
                    <img src={{ post.meta_image }} alt="" class="image-wiih-blur card-img-top image-loaded" max-width="400" max-height="400">
                    <div class="card-body">
                        <h5 class="card-title">{{ post.title }}</h5>
                        <p class="card-subtitle mb-2 text-muted">{{ _('By {0}').format(post.blogger) }}</p>
                        <p class="card-text">{{ post.blog_intro }}</p>
                    </div>
                    <div class="card-body flex-grow-0">
                        <a href="{{ post.route }}" class="card-link">{{ _('पुढे वाचा') }}</a>
                    </div>
                </div>
            </div>
            {% endfor %}
        </div>
    </section>