• Hi there,

    I’m using the pagepost plugin to span my articles across several pages. Now I wish to add the string “Page” to the pagebar, so that visitors have an easier way of navigating. Now it just says “1, 2, …”, which makes it quite strange to my less tech-savvy readers.

    This is the code for the plugin:

    require_once('language.php');
    
    $pagepost_default_pluginpath = get_settings('siteurl') . "/wp-content/plugins/pagepost";
    
    if (get_settings('permalink_structure') != '') {
        add_action('init', 'pagepost_fancy_url');
    }
    
    function pagepost_fancy_url() {
        $req = rtrim($_SERVER['REQUEST_URI'], '/');
        if (preg_match('!^(.+/)post-page-([0-9]+)$!', $req, $match) && (url_to_postid($req) == 0)) {
            $_GET['pp'] = $match[2];
            $req = $match[1];
            $_SERVER['REQUEST_URI'] = $req;
            $_SERVER['PATH_INFO'] = $req;
        }
    }
    
    function pagepost($content) {
        global $post, $pagepost_show_all;
        $id = $post->ID; //Johnson.Wang
        $n = 1;
        $pages = array();
        $titles = array();
        while (preg_match('/^(.*?)(<p>)?\s*<!--\s*page\s*(:[^>]*)?\s*-->\s*(<\/p>)?(.*)$/is', $content, $match)) {
            if ((trim($match[1]) != "") || (trim($titles[$i-1]) != "")) {
                $pages[$n] = $match[1];
                $n++;
            }
            $titles[$n] = ltrim(trim($match[3]), ':');
            $content = $match[5];
        }
        $pages[$n] = $content;
        if ($n == 1) {
            return $content;
        }
        $curpage = (isset($_GET['pp'])
            && is_numeric($_GET['pp'])
            && ($_GET['pp'] >= 0)
            && ($_GET['pp'] <= $n)) ? $_GET['pp'] : 1;
        if ($curpage > 0) {
            $content = $pages[$curpage];
            $pagebar = "<a href=\"#pp0\" onclick=\"pagepost($id, 0);\">" .
                       $pagepost_show_all[WPLANG] .
                       "</a> &nbsp; ";
        }
        else {
            $content = join('', $pages);
            $pagebar = '<strong style="color: #1E90FF;">' .
                       $pagepost_show_all[WPLANG] .
                       '</strong> &nbsp; ';
        }
        $top_href_tag = "<a name=\"pp0\"></a>"; //Johnson.Wang
        for ($i = 1; $i <= $n; $i++) {
        	if ($i != $curpage) {
                $pagebar .= "<a href=\"#pp$i\" title=\"{$titles[$i]}\" onclick=\"pagepost($id, $i);\">$i</a> ";
            }
            else {
                $pagebar .= "<strong style=\"color: #1E90FF;\" title=\"{$titles[$i]}\">$i</strong> ";
            }
            $top_href_tag.="<a name=\"pp$i\"></a>"; //Johnson.Wang
        }
        $pagebar_loading = "<strong id=\"pagebar_loading_$id\"></strong>";
        $pagebar_top =  "<div id=\"pagebar_top_$id\" class=\"pagebar\">" . $top_href_tag . $pagebar . "<strong id=\"pagebar_loading_$id\" style=\"color: green;\"></strong></div>"; //Johnson.Wang
        $pagebar_bottom = "<div id=\"pagebar_bottom_$id\" class=\"pagebar\">" . $pagebar . "</div>";
        return "<div id=\"pagepost_$id\" " .
            "class=\"pagepost\">" .
            $pagebar_top . $content . $pagebar_bottom . '</div>';
    }
    
    function pagepost_js() {
        global $pagepost_default_pluginpath;
        if ((!defined('PHPRPC_JS_CLIENT_LOADED')) || (PHPRPC_JS_CLIENT_LOADED == false)) {
            echo "<script type=\"text/javascript\" src=\"$pagepost_default_pluginpath/phprpc_client.js\"></script>\n";
            define('PHPRPC_JS_CLIENT_LOADED', true);
        }
        if ((!defined('INNERHTML_JS_LOADED')) || (INNERHTML_JS_LOADED == false)) {
        echo "<script type=\"text/javascript\" src=\"$pagepost_default_pluginpath/innerhtml.js\"></script>\n";
            define('INNERHTML_JS_LOADED', true);
        }
        echo "<script type=\"text/javascript\" src=\"$pagepost_default_pluginpath/pagepost.js.php\"></script>\n";
    }
    
    function pagepost_css() {
        global $pagepost_default_pluginpath;
        echo "<link rel=\"stylesheet\" href=\"$pagepost_default_pluginpath/pagepost.css\" />\n";
    }
    add_filter('the_content', 'pagepost', 10000);
    add_action('wp_head', 'pagepost_js');
    add_action('wp_head', 'pagepost_css');
    
    ?>

    I’m guessing it has to go somwhere in the pagebar-section… Thanks in advance!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Adding string to PagePost plugin’ is closed to new replies.