Aligns the post system

0
<?php
    require_once 'Postagem/system/config.php';
    require_once 'Postagem/system/database.php';
?>

<!DOCTYPE html>
<html lang="pt-BR">
<?php include 'include/head.php'; ?>
<?php include 'include/nav.php'; ?>


<div class="card mb-3">
  <img class="card-img-top" src="img/cap.png" alt="Card image cap">
  <div class="card-block">
    <h4 class="card-title"><span style="margin-left: 15px;">Forex</span></h4>
    <p class="card-text"><span style="margin-left: 15px;">O maior site de conteudo forex da America Latina.</p>
    <p class="card-text"><small class="text-muted"></span></small></p>
  </div>
</div>

<style type="text/css">
.inserirLayout{
    height:auto;
    width: auto;
}

.inserirLayout li{
    list-style-type: none;
    float: left;
    text-align: right;
    padding: 0 15px 0;
    display: block;
    height:40px;
}
</style>

<!--Exibindo alguns dados-->


<main>

    <?php
        $posts = DBRead('posts', "WHERE status = 1 ORDER BY data DESC");

        if (!$posts)
            echo '<h2>Nenhuma postagem encontrada!</h2>';
        else
            foreach ($posts as $post): 
    ?>


<ul class="inserirLayout">
    <li>
    <div class="card" style="width: 20rem;  ">

        <img class="card-img-top" src="Postagem/painel/uploads/<?php echo $post['image_text']; ?>" alt="Card image cap" height="318px" width="180px">

            <div class="card-body">
                <h4 class="card-title">
                    <a href="Postagem/exibe.php?id=<?php echo $post['id']; ?>" title="<?php echo $post['titulo']; ?>">
                        <?php echo $post['titulo']; ?></h4>

                    </a>    
                            <p class="card-text">
                                <?php
                                    $str = strip_tags($post['conteudo']);
                                    $len = strlen($str);
                                    $max = 500;

                                    if ($len <= $max)
                                        echo $str;
                                    else
                                        echo substr($str, 0, $max) . '...';

                                ?>
                            </p>

                            <p class="card-text"><small class="text-muted"><?php echo date('d/m/Y', strtotime($post['data'])) ?>
                                , Visitas <b><?php echo $post['visitas']; ?></b>,
                                por <b><?php echo $post['autor']; ?></b>
                            </small>
                            </p>



                        <a href="Postagem/exibe.php?id=<?php echo $post['id']; ?>" title="<?php echo $post['titulo']; ?>" class="btn btn-primary">Leia a Materia</a>
            </div>

    </div>


    </li>
</ul>

    <?php endforeach; ?>




</main> 

</html>

I want it to print the vertical online postage of 3 every time you have 3 posts in a vertical line it skips line

I need this help

    
asked by anonymous 21.10.2017 / 02:45

1 answer

-1

Hello, in your foreach, you can take the index and divide it by 3, if the division has 0 rest, you add a
So

<?php
    foreach ($posts as $index => $post): 
        if($index % 3 == 0) {
?>
           <br />
<?php } ?>
    
23.10.2017 / 02:54