how do I foreach loop through pages in a category?

Post Reply
johnny
Jr. Bludit
Posts: 1
Joined: Fri Oct 19, 2018 9:25 am

How can I foreach loop through pages in a certain category?
For example I want to loop through all pages in the category "nav" and display their title:

Code: Select all

<div class="collapse navbar-collapse" id="navbarResponsive">
    <ul class="navbar-nav ml-auto">
        <!-- currently I'm just displaying all page titles -->
        <?php foreach ($content as $page): ?>
        <li class="nav-item">
            <a class="nav-link js-scroll-trigger" href="#<?php echo $page->title(); ?>"><?php echo $page->title(); ?></a>
        </li>
        <?php endforeach ?>
    </ul>
</div>
another example would be looping though all pages in the category "video" and display their title and content:

Code: Select all

<section id="videos" class="about-section projects-section text-center">
    <div class="container">
        <div class="row videos-section text-center">
            <?php foreach($content as $page): ?>
            <div class="col-lg-6">
                <div class="bg-black text-center h-100 project">
                    <div class="d-flex h-100">
                        <div class="project-text w-100 my-auto text-center text-lg-left">
                            <h4 class="text-white">                     
                                <?php echo $page->title(); ?>
                            </h4>
                            <p class="mb-0 text-white-50">
                                <?php echo $page->content() ?>
                            </p>
                            <hr class="d-none d-lg-block mb-0 ml-0">
                        </div>
                    </div>
                </div>
            </div>
            <?php endforeach ?>
        </div>
    </div>
</section>
User avatar
diego
Site Admin
Posts: 773
Joined: Sat May 16, 2015 2:53 pm
Been thanked: 1 time
Contact:

Hi,
take a look in the documentation, there are a few code snippet.

https://docs.bludit.com/en/dev-snippets/categories
Post Reply