* Data: 21-04-2013 / 03h30
* License: Comercial
*
**************************************************************/

/*Definir termos mais populares atraves da funcao*/
function termos_populares( ){
global $wpdb, $paged, $max_num_pages, $current_date;

/*Numero de termos por pagina*/
$post_per_page = 100;

$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
$offset = ($paged – 1)*$post_per_page;

/* Criar a consulta */
$sql = “SELECT meta_value
FROM wp_stt2_meta

ORDER BY meta_count DESC
LIMIT “.$offset.”, “.$post_per_page.” “;

$sql_result = $wpdb->get_results( $sql, OBJECT);

$sql_posts_total = $wpdb->get_var( “SELECT FOUND_ROWS();” );
$max_num_pages = ceil($sql_posts_total / $post_per_page);

//Devolve tudo num array
return $sql_result;
}

function get_random_number($min = 12, $max = 25) {
return rand($min,$max);
}
/**************************************************************/

/*Ciclo dos termos populares*/
$termos_pop = termos_populares();
foreach( $termos_pop as $termo ){
$nome = $termo->meta_value;
$permalink = get_bloginfo(‘url’).’/search/’.user_trailingslashit(pk_stt2_function_sanitize_search_link($nome));

echo ““.$nome.” “;
}

/*Paginação dos termos*/
function pagination($pages = 11, $range = 15){

/*Numero de termos por pagina*/
$post_per_page = 100;

$showitems = ($range * 2)+1;
$count_rows = mysql_query(“SELECT meta_value FROM wp_stt2_meta”);
$pages = mysql_num_rows($count_rows);
$max_num_pages = ceil($pages / $post_per_page);
$pages = $max_num_pages;

global $paged;
if(empty($paged)) $paged = 1;

if($pages == ”)
{
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages)
{
$pages = 1;
}
}

if(1 != $pages)
{
echo “

“;
echo “Página “.$paged.” de “.$pages.”

“;
//if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "« Primeiro“;
//if($paged > 1 && $showitems < $pages) echo "‹ Último“;

for ($i=1; $i <= $pages; $i++) { if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) { echo ($paged == $i)? "“.$i.”“:”“.$i.”“;
}
}

//if ($paged < $pages && $showitems < $pages) echo "Seguinte ›“;
// if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "Anterior »“;
echo “

\n”;
}
}

pagination();

?>

Deixe uma resposta