1 (edited by Avaray 2014-12-25 13:31:03)

Topic: Need help with code - Bootstrap and Pagination

Im beginner so I need your help.
I want to use pagination to default blog plugin that comes with monstra.
Im pretty sure I must do something with file /plugins/blog/views/frontend/pager.view.php
Probably I must use just:

<ul class="pagination">
</ul>

But where? Please help.

2 (edited by Avaray 2015-01-03 17:56:08)

Re: Need help with code - Bootstrap and Pagination

So I played today a little bit with it.
Its almost perfect, but "buttons" are not showing only at 1st page. Any ideas?
You can see it here: http://avaray.info/blog?page=2

<br><br>
<?php
    if (Request::get('tag')) $tag = '&tag='.Request::get('tag'); else $tag = '';
    $neighbours = 6;
    $left_neighbour = $page - $neighbours;
    if ($left_neighbour < 1) $left_neighbour = 1;
    $right_neighbour = $page + $neighbours;
    if ($right_neighbour > $pages) $right_neighbour = $pages;
    if ($page > 1) {
        echo ' <nav> <ul class="pagination"> <li> <a href="?page=1'.$tag.'">'.__('begin', 'blog').'</a> </li> <li><a href="?page=' . ($page-1) . $tag.'"> '.__('prev', 'blog').'</a></li> ';
    }
    for ($i=$left_neighbour; $i<=$right_neighbour; $i++) {
        if ($i != $page) {
            echo ' <li><a href="?page=' . $i . $tag.'">' . $i . '</a></li>';
        } else {
            echo ' <li><a href="#"><b>' . $i . '</b></a></li>';
        }
    }
    if ($page < $pages) {
        echo  ' <li><a href="?page=' . ($page+1) . $tag.'">'.__('next', 'blog').'</a></li>  <li><a href="?page=' . $pages . $tag.'">'.__('end', 'blog').'</a> </li></ul></nav>';
    }
?>

Re: Need help with code - Bootstrap and Pagination

Try this:

<br><br>
<?php
    if (Request::get('tag')) $tag = '&tag='.Request::get('tag'); else $tag = '';
    // total posts to show
    $neighbours = 6;
    // left pages = page - total
    $left_neighbour = $page - $neighbours;
    if ($left_neighbour < 1) $left_neighbour = 1;
     // right pages = page + total
    $right_neighbour = $page + $neighbours;
    if ($right_neighbour > $pages) $right_neighbour = $pages;
    // Start pagination out of if condition
    $html = '<nav> <ul class="pagination"> ';
    // Start in page 1
    if ($page > 1) {
       $html .=' <li> <a href="?page=1'.$tag.'">'.__('begin', 'blog').'</a> </li> 
                <li><a href="?page=' . ($page-1) . $tag.'"> '.__('prev', 'blog').'</a></li> ';
    }
    // i = pages - total and  i < pages + total 
    for ($i=$left_neighbour; $i<=$right_neighbour; $i++) {
        if ($i != $page) {
             $html .=' <li><a href="?page=' . $i . $tag.'">' . $i . '</a></li>';
        } else {
             $html .=' <li><a href="#"><b>' . $i . '</b></a></li>';
        }
    }
    // if page less than pages
    if ($page < $pages) {
         $html .=
                 '<li><a href="?page=' . ($page+1) . $tag.'">'.__('next', 'blog').'</a></li>  
                  <li><a href="?page=' . $pages . $tag.'">'.__('end', 'blog').'</a> </li>';
    }
   // End pagination out of if condition
    $html .='</ul></nav>';
   // render html
   echo $html;
?>
..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

4 (edited by Avaray 2015-01-03 23:53:38)

Re: Need help with code - Bootstrap and Pagination

Ok, nevermind. My friend told me theres small fault in code in line 12.

Is:

if ($page > 1) {

Should be:

if ($page >= 1) {

And thanks Nakome for code smile