如何修复空白分页链接?

时间:2015-04-10 作者:RLM

我正在写一个Wordpress博客,它似乎是为帖子定制分页。As you can see here 页面底部呈现的链接数量正确,但这些链接是空白的。下面是functions.php

function emm_paginate($args = null) {
    $defaults = array(
        \'page\' => null, \'pages\' => null, 
        \'range\' => 3, \'gap\' => 3, \'anchor\' => 1,
        \'before\' => \'<div class="emm-paginate">\', \'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<span class=\'emm-title\'>$title</span>";
        $ellipsis = "<span class=\'emm-gap\'>...</span>";

        if ($page > 1 && !empty($previouspage)) {
            $output .= "<a href=\'" . get_pagenum_link($page - 1) . "\' class=\'emm-prev\'>$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) . "\' class=\'emm-next\'>$nextpage</a>";
        }

        $output .= $after;
    }

    if ($echo) {
        echo $output;
    }

    return $output;
}

/**
 * Helper function for pagination which builds the page links.
 *
 * @access private
 *
 * @author Eric Martin <[email protected]>
 * @copyright Copyright (c) 2009, Eric Martin
 * @version 1.0
 *
 * @param int $start The first link page.
 * @param int $max The last link page.
 * @return int $page Optional, default is 0. The current page.
 */
function emm_paginate_loop($start, $max, $page = 0) {
    $output = "";
    for ($i = $start; $i <= $max; $i++) {
        $output .= ($page === intval($i)) 
            ? "<span class=\'emm-page emm-current\'>$i</span>" 
            : "<a href=\'" . get_pagenum_link($i) . "\' class=\'emm-page\'>$i</a>";
    }
    return $output;
}
****编辑****

我已经从我的functions.phpindex.php 并添加

<?php the_posts_pagination( array(
                \'mid_size\' => 2,
                \'prev_text\' => __( \'Back\', \'textdomain\' ),
                \'next_text\' => __( \'Onward\', \'textdomain\' ),
            ) ); ?> 
给我的index.php 同样的问题。数字显示出来,生成空白页。我还注意到archives.php 根文件夹中缺少。添加了它,但仍然没有任何结果。

1 个回复
SO网友:Frankenmint

你能帮我们转到这个页面吗:

../wp admin/options permalink。php

选择的结构是什么?这将为您提供如何调整底部功能的答案

编辑:还有,为什么这部分是这样的:

 if ($echo) {
    echo $output;
}

return $output;
}
$输出不应该在括号中吗?

结束

相关推荐

更改修订版查看器管理页面revision.php中的某些语言

我有一个自定义的post类型,其中术语“post”是irelevent。我通过各种钩子成功地将“post”的所有引用更改为主post编辑页面中的其他内容。我突然在自定义帖子中启用了修订支持,然后意识到修订页面上的一些文本需要更新。不过,我还没有找到一种快速且相当简单的方法来实现这一点。这真的很小,比如页面左上角的链接,当前状态是“返回到post editor”。有什么想法吗?