We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4195
    • 398 Posts
    Based of a snippet I found made by zenmaster (see this topic) I created this pagination plugin.

    installation is very simple:

    - create a new plugin
    - paste the code
    - check the OnLoadWebDocument event

    and you are done.

    Out of the box:

    Installing this plugin will automatically make documents paginated when a {BREAK} delimiter is detected in the content of the document.
    You can ofcourse change the delimiter to anything you prefer and change the template for the pagination.

    /*
     *  Name: Pip (Pagination Plugin)
     *  Version: 1.0
     *  Author: Armand "bS" Pondman ([email protected])
     *  Updated: June 7, 2006 12:00 CET
     *
     *  Description:
     *  will paginate a document when delimiter is found in the content. 
     *
     *  Configuration:
     *  check the OnLoadWebDocument event
     *
     *    optional: 
     *    Edit the values under the CUSTOMIZE Header
     *
     */
    
    ## CUSTOMIZE ##
    
    $delimiter = '{BREAK}';
    $tplLinkNext = '<a href="[+link+]">Next</a>';
    $tplLinkPrev = '<a href="[+link+]">Prev</a>';
    $tplLinkNav = '
      <div style="margin-top: 10px;font-size: small;">
      [+linkprev+]
       Page [+current+] of [+total+] 
      [+linknext+] 
      </div>';
    
    ## DO NOT EDIT BELOW THIS LINE ##
    
    $e = &$modx->Event;
    
    switch($e->name) {
      case 'OnLoadWebDocument':
        $pip_content = $modx->documentObject['content'];
    	$pip_pagecontent = explode($delimiter,$pip_content);
    	$pip_pagecount = count($pip_pagecontent);
    	
    	if ($pip_pagecount > 1)
    	{
    	  $pip_currentpage = isset($_GET["page"]) ? $_GET["page"]: 1;
    	  if ($pip_currentpage > $pip_pagecount || $pip_currentpage < 1) { $pip_currentpage = 1; }
    	
    	  $char = ($modx->config['friendly_urls'] == 0) ? "&" : "?";
    	  $url = $modx->makeurl($modx->documentObject["id"],'',$char.'page=');
    	  
    	  $prevpage = $pip_currentpage-1;
    	  $nextpage = $pip_currentpage+1;
    	  
    	  $linkprev = ($prevpage>0) ? str_replace("[+link+]",$url.$prevpage,$tplLinkPrev) : '';
    	  $linknext = ($nextpage>$pip_pagecount) ? '' : str_replace("[+link+]",$url.$nextpage,$tplLinkNext);
    	  
    	  $pip_template = str_replace("[+linkprev+]",$linkprev,$tplLinkNav);
    	  $pip_template = str_replace("[+linknext+]",$linknext,$pip_template);
    	  $pip_template = str_replace("[+total+]",$pip_pagecount,$pip_template);
    	  $pip_template = str_replace("[+current+]",$pip_currentpage,$pip_template);
    	
    	  $pip_content= $pip_pagecontent[$pip_currentpage-1].$pip_template;
    	}
    	$modx->documentObject['content'] = $pip_content;
    
        break;
      default:
        return;
        break;
    }
      Armand Pondman
      MODx Coding Team
      :: Jot :: PHx
      • 7455
      • 2,204 Posts
      could it also be adapted that it count words or charachters and break after a certan nummber of words/characters?
        follow me on twitter: @dimmy01
        • 4195
        • 398 Posts
        Quote from: Dimmy at Jun 07, 2006, 10:14 AM

        could it also be adapted that it count words or charachters and break after a certan nummber of words/characters?

        yes it could.. I will have to dig into the regular expressions for that (i feel another version coming up lol)
          Armand Pondman
          MODx Coding Team
          :: Jot :: PHx
          • 7455
          • 2,204 Posts
          That would be great that I have not to count my zelf and insert the breack dellimitter

          Great job

          (now also a way to get the next page not as a next page but insite a nother div hehe (I feel a 2 columb desing plugin being cooced hehe)
            follow me on twitter: @dimmy01
            • 4195
            • 398 Posts
            Quote from: Dimmy at Jun 07, 2006, 11:25 AM

            That would be great that I have not to count my zelf and insert the break delimiter

            Only downside to this approach is that it will cut of sentences. In my opinion someone will always manually use break because you want to divide one not-to-big document into different parts without the extra effort of making sub documents.

            Quote from: Dimmy at Jun 07, 2006, 11:25 AM

            (now also a way to get the next page not as a next page but insite a nother div hehe (I feel a 2 columb desing plugin being cooced hehe)

            could be incoorporated into the same plugin, with extra parameter. you have to create a second plugin ofcourse but you can use the same code smiley
            But why would you want that?


              Armand Pondman
              MODx Coding Team
              :: Jot :: PHx
              • 32982
              • 674 Posts
              great plugin very usefoul
              thanks for share
                Jabiertxof (formerly XYZVISUAL)
                My bussines: http://marker.es
                https://www.youtube.com/user/jabiertxof/videos
                • 7455
                • 2,204 Posts
                Quote from: bS at Jun 07, 2006, 11:45 AM


                could be incoorporated into the same plugin, with extra parameter. you have to create a second plugin ofcourse but you can use the same code smiley
                But why would you want that?


                When somtime I make sites that have fixed div’s that hold the content
                like this site i made http://dts.kinghosting.nl I made a secend tv that holds the right part of the content that way I need to split the text by hand aslo but I need also an extra tv.

                maybe I am the only one that thinks out of the 2/3 columb stretching to the bottom sites box.

                Greets Dimmy
                  follow me on twitter: @dimmy01
                  • 18436
                  • 135 Posts
                  Don’t worry, I can see plenty of mileage for a two or even three column plugin although PIP wouldn’t be the proper name for it. Are you using two columns as a design feature or only because you’re struggling to fit content in your fixed width/height site?

                  If you’re struggling with space why not simply assign the container div with overflow: auto and make sure the actual content is about 20px narrower than the container so you can avoid any ugly horizontal scrollbars?
                    • 33337
                    • 3,975 Posts
                    Great Plugin man!

                    Thanks for sharing.

                    regards,

                    zi
                      Zaigham R - MODX Professional | Skype | Email | Twitter

                      Digging the interwebs for #MODX gems and bringing it to you. modx.link
                      • 7455
                      • 2,204 Posts
                      Quote from: Marschant at Jun 08, 2006, 08:14 AM

                      Don’t worry, I can see plenty of mileage for a two or even three column plugin although PIP wouldn’t be the proper name for it. Are you using two columns as a design feature or only because you’re struggling to fit content in your fixed width/height site?
                      as a design feature

                      If you’re struggling with space why not simply assign the container div with overflow: auto and make sure the actual content is about 20px narrower than the container so you can avoid any ugly horizontal scrollbars?

                      I use that a lot also
                        follow me on twitter: @dimmy01