Aligns the posting system

Asked

Viewed 59 times

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 him to print the vertical line posting of 3 every time 3 posting on a vertical line he jumps the line

I need that help

  • Hello Vitor! You are from Portugal?

  • Hello, I’m from Brazil

  • Your question got confused. It wouldn’t be "horizontal line" instead of "vertical line"?

  • Because "line" usually means "horizontal", while "vertical" has more to do with "column".

  • horizontal in the case

  • Got it. The answer below solves?

  • Not yet, he’s jumping, and he’s not making you whole or 3 ,

  • So it’s because 3 doesn’t fit on the screen on the same line.

  • http://farolandia.atspace.cc/png/

  • to see if it’s easy

  • The idea is the answer of @Cayo Henrique Rodrigues... Put a <br clear="all" /> instead of <br />, and in the CSS remove the height:40px;, which, by the way, I don’t know what it’s for.

  • Has a tag <h4> with a <a> inside and you glued one </h4>within the <a>... this tah wrong too

  • Your HTML would look something like this: https://jsfiddle.net/m3w6bypm/

  • Thanks, it worked out

  • How nice. Success!

Show 10 more comments

1 answer

-1


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

<?php
    foreach ($posts as $index => $post): 
        if($index % 3 == 0) {
?>
           <br />
<?php } ?>
  • it wasn’t, he’s jumping the line,

  • however , and on that basis the logic,

  • 3 posting on a row ai it automatically jumps line

  • There’s three more, so go

  • What exact behavior do you want? It wasn’t to jump line every 3 items?

  • http://farolandia.atspace.cc/png/

  • to see if it gets a little easy

  • as I had explained, like, every 3 horizontal posts, it skips the line, and puts 3 more posts,

  • worked together with the other

  • worked yes, thanks the problem was my css

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.