Pagination, removing “Newer Entries” and “Older Entries” in WordPress

Script made by: Eric Martin

Files to change

  1. wp-content/themes/your template/index.php
  2. wp-content/themes/your template/functions.php
  3. wp-content/themes/your template/style.css

Open index.php, find:

1
2
3
4
<div class="navigation">
    <div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    <div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
</div>

replace with:

1
<? if (function_exists("emm_paginate")) { emm_paginate(); }  ?>

Open style.css, at the end, add:

1
2
3
4
5
6
7
8
9
10
11
12
13
.pagination {
    float: right;
    margin-right: 6px;
}
.pagination a {
    border: 1px solid #583925;
    padding: 6px;
    margin: 3px;
    background-color: #80573B;
    color: #D6B163;
    text-decoration: none;
    font-weight: normal;
}

Open functions.php, find

1
<?php

or

1
<?

Just after, add:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
function emm_paginate($args = null) {
    $defaults = array(
        'page' => null, 'pages' => null, 
        'range' => 3, 'gap' => 3, 'anchor' => 1,
        'before' => '<div class="pagination">', 'after' => '</div>',
        'title' => __('Pages: '),
        'nextpage' => __('&raquo;'), 'previouspage' => __('&laquo'),
        'echo' => 1
    );

    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);

    if (!$page && !$pages) {
        global $wp_query;

        $page = get_query_var('paged');
        $page = !empty($page) ? intval($page) : 1;

        $posts_per_page = intval(get_query_var('posts_per_page'));
        $pages = intval(ceil($wp_query->found_posts / $posts_per_page));
    }
    
    $output = "";
    if ($pages > 1) {   
        $output .= "$before$title";
        $ellipsis = "...";

        if ($page > 1 && !empty($previouspage)) {
            $output .= "<a href='" . get_pagenum_link($page - 1) . "'>$previouspage</a>";
        }
        
        $min_links = $range * 2 + 1;
        $block_min = min($page - $range, $pages - $min_links);
        $block_high = max($page + $range, $min_links);
        $left_gap = (($block_min - $anchor - $gap) > 0) ? true : false;
        $right_gap = (($block_high + $anchor + $gap) < $pages) ? true : false;

        if ($left_gap && !$right_gap) {
            $output .= sprintf('%s%s%s', 
                emm_paginate_loop(1, $anchor), 
                $ellipsis, 
                emm_paginate_loop($block_min, $pages, $page)
            );
        }
        else if ($left_gap && $right_gap) {
            $output .= sprintf('%s%s%s%s%s', 
                emm_paginate_loop(1, $anchor), 
                $ellipsis, 
                emm_paginate_loop($block_min, $block_high, $page), 
                $ellipsis, 
                emm_paginate_loop(($pages - $anchor + 1), $pages)
            );
        }
        else if ($right_gap && !$left_gap) {
            $output .= sprintf('%s%s%s', 
                emm_paginate_loop(1, $block_high, $page),
                $ellipsis,
                emm_paginate_loop(($pages - $anchor + 1), $pages)
            );
        }
        else {
            $output .= emm_paginate_loop(1, $pages, $page);
        }

        if ($page < $pages && !empty($nextpage)) {
            $output .= "<a href='" . get_pagenum_link($page + 1) . "'>$nextpage</a>";
        }

        $output .= $after;
    }

    if ($echo) {
        echo $output;
    }

    return $output;
}
function emm_paginate_loop($start, $max, $page = 0) {
    $output = "";
    for ($i = $start; $i <= $max; $i++) {
        $output .= ($page === intval($i)) 
            ? "$i " 
            : "<a href='" . get_pagenum_link($i) . "'>$i</a>";
    }
    return $output;
}

Save, upload all files.