How to get the current pagination page number? I have the following URL http: //site/gallery/foto-svyazannie-s-nami/page/2. How do I check if there is a pagination (ie, there is a page parameter) and if it is, get a number (current page number from my urla it is 2)
2 answers
In wordpress, query variables are easily obtained using the built-in function get_query_var($name_var) . You need the 'paged' parameter. This is one of the WP_Query parameters and contains the current page number. This code will just show you the page number.
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; echo 'Мы находимся на странице: '.$paged; - Please try to write more detailed answers. I am sure the author of the question would be grateful for your expert commentary on the code above. - Nicolas Chabanovsky ♦
- Good. From now on I will try to answer in more detail. - Ivan
- You can always make changes to an existing answer (or question). To do this, click the edit link located under the body of the answer. - Nicolas Chabanovsky ♦
|
This code will give the desired result:
$page = $_SERVER['REQUEST_URI']; // получили путь if (!strpos($page, 'page')) return; // нет слова page в url $page = substr($page, 0, -1); // удалили последний / $pos = strrpos($page, '/'); // нашли позицию крайнего справа / $num = substr($page, $pos + 1); |