0
I’m making a site posts... and I’m having difficulties to set up how many letters can have at the beginning of my site... because the button itself I already have but I wonder how can "Set" up how many letters can have in the post...
is currently like this on my website: http://prntscr.com/jb35jk When you open the site appears ALL the content of the post I did but it is not cool to leave all the text at the beginning because then the "Continue reading" button would be useless!
My code looks like this: my text appears with the variable "$descricao
"
<div class="">
<?php
if(isset($_GET['posts'])){
$pg = (int)$_GET['posts'];
}else{
$pg = 1;
}
$maximo = 2;
$inicio = ($pg * $maximo) - $maximo;
$seleciona = mysql_query("SELECT * FROM posts ORDER BY id DESC LIMIT $inicio, $maximo");
$conta = mysql_num_rows($seleciona);
if($conta <= 0){
echo "<code>Nenhuma nova notícia foi declarada! que pena :/";
}else{
while($row = mysql_fetch_array($seleciona)){
$id = $row['id'];
$titulo = $row['titulo'];
$descricao = $row['descricao'];
$imagem = $row['imagem'];
$data = $row['data'];
$hora = $row['hora'];
$postador = $row['postador'];
$sql = "SELECT * FROM usuarios WHERE usuario = '$postador'";
$query = mysql_query($sql);
$linha = mysql_fetch_assoc($query);
?>
<div id="panel" align="left" style="color: #000;">
<p><a href="?pagina=post&id=<?php echo $id;?>" class="titulo"><?php echo $titulo;?></a></p>
<?php if($descricao != null){?><p class="descricao"><?php echo $descricao;?></p><? }?>
<a href="?pagina=post&id=<?php echo $id;?>" class="lermais">Continuar lendo</a>
<br>
<br>
<?php if($imagem != null){?><p><img src="<?php echo $imagem;?>" class="foto"/></p><? }?>
<span class="glyphicon glyphicon-user" aria-hidden="true"></span> Postado por: <?php echo $linha['nome'];?> <img src="https://minotar.net/avatar/<?php echo $postador?>/20"></p>
<p><span class="glyphicon glyphicon-time" aria-hidden="true"></span> Postado em: <?php echo $data." às ".$hora;?></p></br>
</div>
<?php }}?>
</div>
<nav align="center">
<ul class="pagination">
<?php
$seleciona = mysql_query("SELECT * FROM posts");
$totalPosts = mysql_num_rows($seleciona);
$pags = ceil($totalPosts/$maximo);
$links = 2;
echo '<li><a href="?pagina=inicio&posts=1" aria-label="Página Inicial"><span aria-hidde="true">«</span></a></li>';
for($i = $pg - $links; $i <= $pg -1; $i++){
if($i <= 0){}else{
echo '<li><a href="?pagina=inicio&posts='.$i.'">'.$i.'</a></li>';
}
}
echo '<li><a href="?pagina=inicio&posts='.$pg.'">'.$pg.'</a></li>';
for($i = $pg + 1; $i <= $pg + $links; $i++)
if($i > $pags){}else{
echo '<li><a href="?pagina=inicio&posts='.$i.'">'.$i.'</a></li>';
}
echo '<li><a href="?pagina=inicio&posts='.$pags.'" aria-label="Última página"><span aria-hidde="true">»</span></a></li>';
?>
</ul>
</nav>
Use the function
substr
to "cut" the text.– Valdeir Psr
You could use substr, the problem is that if there are HTML tags in the middle of the cut, it will break the rest of the page.
– Sam
Yeah, I put it here and... you totally took the text... there’s no such thing as how much you’re gonna cut?
– Gustavo Gbn
Well, there are no htmls tags inside the $Description is just text, however I would like to not remove all text.
– Gustavo Gbn
Your first answer helped me, thanks!
– Gustavo Gbn