Jump to content

Inserting pagination in Announcements


Recommended Posts

Just insert the code bellow where you want to show your announcements (please backup your current file):

whmcs/templates/yourtheme/announcements.tpl

 

{php}

//Conectando ao banco de dados

$link = mysql_connect($db_host,$db_username,$db_password);

mysql_select_db($db_name);

//O que puxar do banco de dados

$campos_query = "*";

$final_query = "FROM tblannouncements";

//Em que página estamos

$pagina = $_GET["pagina"];

if($pagina == "") {

$pagina = "1";

}

// Itens por página

$maximo = 5;

$inicio = $pagina - 1;

$inicio = $maximo * $inicio;

//Pega número de registros da tabela announcements

$strCount = "SELECT COUNT(*) AS 'num_registros' $final_query";

$query = mysql_query($strCount);

$row = mysql_fetch_array($query);

$total = $row["num_registros"];

//Se não tem nada, retorna mensagem

if($total<=0) {

echo "Nenhum registro encontrado.";

}

//Se achou algo, vamos puxar os dados

else {

$strQuery = "SELECT $campos_query $final_query ORDER BY date DESC LIMIT $inicio,$maximo";

$query = mysql_query($strQuery);

while($row = mysql_fetch_array($query)) {

//Titulo

echo "

<h2><a href="">".$row["title"]."</a></h2>

";

//Formatando a data

$formadata = date('d/m/Y', strtotime($row["date"]));

echo "<span class="\"data\"">".$formadata."</span>";

//o Anuncio

echo $row["announcement"];

//Separador

echo "<hr />";

}

//

$menos = $pagina - 1;

$mais = $pagina + 1;

$pgs = ceil($total / $maximo);

if($pgs > 1 ) {

echo "

<div class="\"centra\"">";

if($menos > 0) {

echo "<a class="pagina" href="">anterior</a> ";

}

for($i=1;$i <= $pgs;$i++) {

if($i != $pagina) {

echo " <a class="pagina" href="">$i</a>";

}

else {

echo " <span class="pagina_atual">".$i."</span>";

}

}

if($mais <= $pgs) {

echo " <a class="pagina" href="">próxima</a>";

}

}

}

{/php}</div>

 

Remeber that you have to turn friendly urls or adapt the code above if you choose to keep it.

You can also comment your .htaccess file in the announcements section with # to keep using cool urls and still use the code above.

 

Related CSS:

.data {font-size:10px; color:#666666 }

span.pagina_atual {border:1px solid #000000; padding:5px; font-weight:bold; text-align:center; text-decoration:underline}

a.pagina {border:1px solid #CC0000; padding:5px; text-align:center; }

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated