Jump to content

Sistema de notícas (ao mostrar aparecer "Read More")


n0TTT_
 Share

Recommended Posts

Bom dia.

Eu queria saber como fazer quando tou a mostrar as noticias na página inicial, que apareça algo do género disto:

Bem vindo ao website... Read More

Que não apareça todo o conteúdo da noticia.. e que a frente apareça 'Read More'..

Cumprimentos.

Link to comment
Share on other sites

o que queres criar é um excerto, basta fazer truncate ao texto ;)

este é o melhor funçao que gosto de usar:

http://www.the-art-of-web.com/php/truncate/

<?php
// Original PHP code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header.
// http://www.the-art-of-web.com/php/truncate/
function myTruncate($string, $limit, $break=".", $pad="...")
{
 // return with no change if string is shorter than $limit
 if(strlen($string) <= $limit) return $string;
 // is $break present between $limit and the end of the string?
 if(false !== ($breakpoint = strpos($string, $break, $limit))) {
   if($breakpoint < strlen($string) - 1) {
  $string = substr($string, 0, $breakpoint) . $pad;
   }
 }
 return $string;
}
?>
<?php $text="The World Wide Web. When your average person on the street refers to the Internet, they're usually thinking of the World Wide Web. The Web is basically a series of documents shared with the world written in a coding language called Hyper Text Markup Language or HTML. When you see a web page, like this one, you downloaded a document from another computer which has been set up as a Web Server.";
<p><?php echo myTruncate($text,$nr_palavras); ?></p>

B2R » Beat2Revolution v3.0b | Regista e divulga-nos

beat2revolution.net
Link to comment
Share on other sites

Então, tens de pegar na string com a notícia e apresentar só, por exemplo 200 caracteres, no fim disso fazes uma concatenação com (... Read More).

Depois podes aperfeiçoar as coisas...

Fazes controlos para saber se a noticia tem ou não mais do que 200 caracteres, etc etc..

PS: Procura como dividir uma string em x caracteres!

Abraço,

Rafael.

Link to comment
Share on other sites

E eu quero fazer uma lista de noticias na página inicial, no máximo quero que apareça 5 noticias.. mas depois apareça noticias antigas, e mude ara outras 5 noticias como faço?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.