{"id":31569,"date":"2015-01-20T13:02:42","date_gmt":"2015-01-20T13:02:42","guid":{"rendered":"https:\/\/es.wordpress.org\/support\/topic\/problemas-con-paginador-numerico\/"},"modified":"2016-08-06T00:37:31","modified_gmt":"2016-08-06T00:37:31","slug":"problemas-con-paginador-numerico","status":"closed","type":"topic","link":"https:\/\/es.wordpress.org\/support\/topic\/problemas-con-paginador-numerico\/","title":{"rendered":"Problemas con PAGINADOR NUM\u00c9RICO"},"content":{"rendered":"<p>Estimados, tengo una funci\u00f3n que permite incluir un <strong>paginador num\u00e9rico<\/strong> si la cantidad  de post excede lo que yo determine en la plantilla. Esta funci\u00f3n anda perfecta si el loop lo tengo en una p\u00e1gina (page.php), sin embargo, no funciona si exactamente el mismo loop lo pongo en un single.php<\/p>\n<p>en single: <a href=\"http:\/\/www.designio.cl\/consejo\/hitos_home\/circuitos-culturales\/\">http:\/\/www.designio.cl\/consejo\/hitos_home\/circuitos-culturales\/<\/a><br \/>\nen page: <a href=\"http:\/\/www.designio.cl\/consejo\/prueba-circuitos\/\">http:\/\/www.designio.cl\/consejo\/prueba-circuitos\/<\/a><\/p>\n<p>la funci\u00f3n es:<\/p>\n<p>\/\/FUNCI\u00d3N PAGINACI\u00d3N<\/p>\n<p>\/\/para paginador<br \/>\ndefine(&#8216;requestPath&#8217;,&#8217;http:\/\/&#8217;.$_SERVER[\u00abHTTP_HOST\u00bb] . $_SERVER[\u00abREQUEST_URI\u00bb]);<br \/>\ndefine(&#8216;cleanPath&#8217;,&#8217;http:\/\/&#8217;.$_SERVER[\u00abHTTP_HOST\u00bb] . $_SERVER[\u00abSCRIPT_NAME\u00bb]);<br \/>\n$requestPath = cleanPath;<br \/>\n$getCleanURL = explode(&#8216;?&#8217;, $requestPath);<br \/>\n$getCleanURL = $getCleanURL[0];<\/p>\n<p>$fullURL = requestPath;<br \/>\n$getCleanFullURL = explode(&#8216;?&#8217;, $fullURL);<br \/>\n$getCleanFullURL = $getCleanFullURL[0];<\/p>\n<p>function get_current_page_link(){<br \/>\n\tglobal $post;<br \/>\n\treturn requestPath;<br \/>\n}<\/p>\n<p>function pagination($query, $current) {<br \/>\n\t$current_page = explode(&#8216;page&#8217;, $current);<br \/>\n\t$class = !empty($age) ? &#8216; class=\u00bb&#8216;.$age.'\u00bb&#8216; : \u00bb;<br \/>\n\tif (empty($current_page[1])){<br \/>\n\t\t$current_page = explode(\u00ab?\u00bb, $current);<br \/>\n\t}<br \/>\n\t$baseURL = $current_page[0];<br \/>\n\t$page = $query-&gt;query_vars[\u00abpaged\u00bb];<br \/>\n\tif ( !$page ) $page = 1;<\/p>\n<p>\t$qs = $_SERVER[\u00abQUERY_STRING\u00bb] ? \u00ab?\u00bb.$_SERVER[\u00abQUERY_STRING\u00bb] : \u00ab\u00bb;<br \/>\n\t\/\/ Only necessary if there&#8217;s more posts than posts-per-page<br \/>\n\tif ( $query-&gt;found_posts &gt; $query-&gt;query_vars[\u00abposts_per_page\u00bb] ) {<br \/>\n\t\techo &#8216;&lt;ul id=\u00bbnumero-pagina\u00bb&gt;&#8217;;<br \/>\n\t\t\t\t\/\/ Previous link?<br \/>\n\t\t\t\tif ( $page &gt; 1 ) {<br \/>\n\t\t\t\t\techo &#8216;<\/p>\n<li><a href=\"'.$baseURL.'page\/'.($page-1).'\/'.$qs.'\">&lt;<\/a><\/li>\n<p>&#8216;;<br \/>\n\t\t\t\t}else{<br \/>\n\t\t\t\t\techo &#8216;<\/p>\n<li><a href=\"#\">&lt;<\/a><\/li>\n<p>&#8216;;<br \/>\n\t\t\t\t}<br \/>\n\t\t\t\/\/ Loop through pages<br \/>\n\t\t\t\tfor ( $i=1; $i &lt;= $query-&gt;max_num_pages; $i++ ) {<br \/>\n\t\t\t\t\t\/\/ Current page or linked page?<br \/>\n\t\t\t\t\tif ( $i == $page ) {<br \/>\n\t\t\t\t\t\techo &#8216;&lt;li class=\u00bbpag_active\u00bb&gt;<a href=\"#\">&#8216;.$i.&#8217;<\/a>&#8216;;<br \/>\n\t\t\t\t\t} else {<br \/>\n\t\t\t\t\t\techo &#8216;<\/p>\n<li><a href=\"'.$baseURL.'page\/'.$i.'\/'.$qs.'\" title=\"'.__('Go to page').' '.$i.'\">&#8216;.$i.&#8217;<\/a><\/li>\n<p>&#8216;;<br \/>\n\t\t\t\t\t}<br \/>\n\t\t\t\t}<br \/>\n\t\t\t\t\/\/ Next link?<br \/>\n\t\t\t\tif ( $page &lt; $query-&gt;max_num_pages ) {<br \/>\n\t\t\t\t\techo &#8216;<\/p>\n<li><a href=\"'.$baseURL.'page\/'.($page+1).'\/'.$qs.'\">&gt;<\/a><\/li>\n<p>&#8216;;<br \/>\n\t\t\t\t}else{<br \/>\n\t\t\t\t\techo &#8216;<\/p>\n<li><a href=\"#\">&gt;<\/a><\/li>\n<p>&#8216;;<br \/>\n\t\t\t\t}<br \/>\n\t\t\t\techo \u00bb;<br \/>\n\t}<br \/>\n}<br \/>\n\/* fin de paginacion *\/<\/p>\n<p><strong>LOOP resumido&#8230;<\/strong><\/p>\n<p>&lt;?php $query = new WP_Query( array(<br \/>\n\t\t\t\t\t\t\t\t&#8216;post_type&#8217; =&gt; &#8216;circuitos_culturales&#8217;,<br \/>\n\t\t\t\t\t\t\t\t&#8216;showposts&#8217; =&gt; &#8216;1&#8217;,<br \/>\n\t\t\t\t\t\t\t\t&#8216;paged&#8217;     =&gt; get_query_var(&#8216;paged&#8217;)<br \/>\n\t\t\t\t\t\t\t) ); ?&gt;  <\/p>\n<p>&lt;?php if ( $query-&gt;have_posts&#8230;..<\/p>\n<p><strong>Despu\u00e9s del loop, lo que llama a la funci\u00f3n&#8230;<\/strong><\/p>\n<p>&lt;?php pagination($query, get_current_page_link()); ?&gt;<\/p>\n","protected":false},"template":"","class_list":["post-31569","topic","type-topic","status-closed","hentry","topic-tag-loop","topic-tag-single","topic-tag-template"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/es.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/31569","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/es.wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/es.wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/es.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/31569\/revisions"}],"wp:attachment":[{"href":"https:\/\/es.wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=31569"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}