how do I foreach loop through pages in a category?

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

Fri Oct 19, 2018 1:45 pm

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>
        <?php endforeach ?>
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(); ?>
                            <p class="mb-0 text-white-50">
                                <?php echo $page->content() ?>
                            <hr class="d-none d-lg-block mb-0 ml-0">
            <?php endforeach ?>
User avatar
Site Admin
Posts: 688
Joined: Sat May 16, 2015 2:53 pm

Fri Oct 19, 2018 4:19 pm

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