rozanchetta

Wordpress - Paginação interna de Posts/Pages

Dec 17th, 2012
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.46 KB | None | 0 0
  1. /* Paginação interna de posts ou pages */
  2.  
  3. // No functions.php
  4.  
  5. if (!function_exists('custom_wp_link_pages')) :
  6.  
  7.     function custom_wp_link_pages($args = '') {
  8.         $defaults = array(
  9.             'before' => '<p class="post-pagination"><span class="post-pages">' . __('Páginas:') . '</span>',
  10.             'after' => '</p>',
  11.             'text_before' => '',
  12.             'text_after' => '',
  13.             'next_or_number' => 'number',
  14.             'nextpagelink' => __('Next page'),
  15.             'previouspagelink' => __('Previous page'),
  16.             'pagelink' => '%',
  17.             'echo' => 1
  18.         );
  19.         $r = wp_parse_args($args, $defaults);
  20.         $r = apply_filters('wp_link_pages_args', $r);
  21.         extract($r, EXTR_SKIP);
  22.         global $page, $numpages, $multipage, $more, $pagenow;
  23.         $output = '';
  24.         if ($multipage) {
  25.             if ('number' == $next_or_number) {
  26.                 $output .= $before;
  27.                 for ($i = 1; $i < ( $numpages + 1 ); $i = $i + 1) {
  28.                     $j = str_replace('%', $i, $pagelink);
  29.                     $output .= ' ';
  30.                     if ($i != $page || ( (!$more ) && ( $page == 1 ) ))
  31.                         $output .= _wp_link_page($i);
  32.                     else
  33.                         $output .= '<span class="current-post-page">';
  34.  
  35.                     $output .= $text_before . $j . $text_after;
  36.                     if ($i != $page || ( (!$more ) && ( $page == 1 ) ))
  37.                         $output .= '</a>';
  38.                     else
  39.                         $output .= '</span>';
  40.                 }
  41.                 $output .= $after;
  42.             } else {
  43.                 if ($more) {
  44.                     $output .= $before;
  45.                     $i = $page - 1;
  46.                     if ($i && $more) {
  47.                         $output .= _wp_link_page($i);
  48.                         $output .= $text_before . $previouspagelink . $text_after . '</a>';
  49.                     }
  50.                     $i = $page + 1;
  51.                     if ($i <= $numpages && $more) {
  52.                         $output .= _wp_link_page($i);
  53.                         $output .= $text_before . $nextpagelink . $text_after . '</a>';
  54.                     }
  55.                     $output .= $after;
  56.                 }
  57.             }
  58.         }
  59.         if ($echo)
  60.             echo $output;
  61.         return $output;
  62.     }
  63.  
  64. endif;
  65.  
  66.  
  67. // No single.php ou template após o the_content();
  68.  
  69. custom_wp_link_pages();
Advertisement
Add Comment
Please, Sign In to add comment