Myrdin
Myrdin

Reputation: 45

How to display articles from a specific category instead of all the articles

I'm working on a version of the mediumish theme for bludit.

By default the theme displays on the homepage a list of all articles in the first section of the page. I would like to display instead the list of articles from one specific category.

I have tried to add an if condition matching the right category but I may be wrong.

Here is what I tried:

<?php if ($WHERE_AM_I == 'home'): ?>

    <!-- Begin Featured
    ================================================== -->
    <section class="featured-posts">
    <div class="section-title">
        <h2><span>La structure</span></h2>
    </div>
    <div class="card-columns listfeaturedtag">

        <?php if ($category->key() == 'structure'): ?>

        <?php 
            // Get the first and second page from the content
            $featured = array_slice($content, 0, 2);
            $content = array_slice($content, 2); ?>

        <?php endif; ?>

        <?php
            foreach ($featured as $page):
        ?>
        <!-- begin post -->
                <!-- Here goes the code for each post -->
        <!-- end post -->
        <?php endforeach; ?>

    </div>
    </section>
    <!-- End Featured
    ================================================== -->
    <?php endif; ?>

I expect it to display the articles from category called structure but I have nothing on the page.

Here are some snippets about categories in bludit.

Upvotes: 2

Views: 567

Answers (1)

Myrdin
Myrdin

Reputation: 45

Ok I found out how to do what I want :

        <?php 
            $categoryKey = 'structure';
            $category = getCategory($categoryKey);

            $featured = array_slice($category->pages(), 0, 3);
            $content = array_slice($content, 1); ?>

        <?php
            foreach ($featured as $pageKey):
        ?>

        <?php $page = new Page($pageKey); ?>


Upvotes: 2

Related Questions