Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: Standalone Paginator  (Read 3899 times)

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Standalone Paginator
« on: December 10, 2007, 02:36:25 pm »

This one was given to me by one of the Dudes --I've forgotten who unfortunately so I can't give credit where it's due-- bramsyuur (thanks, brams!) and it has been of good use to me, so I thought I'd share it.

What the mod does is allow you to place the paginator anywhere you like on the page, unlike the default paginator which always ends up in the center function, after the articles. This gives you a little more flexibility in terms of page layout and styling.

You can see the standalone paginator at work on www.frdk.com and www.frdk.com/snews/ (n/a)

If you're using codetwist's excellent Support For 'Home'-less URL's MOD, then you will need to tweak the the startup function a little for the standalone paginator to work properly. More on that later. Here is the standard MOD:

----------------------------- * -----------------------------

0. BACKUP

1. New function: show_paginator(). Place this towards the end of snews.php, just before the js() function:
Quote
//STANDALONE PAGINATOR
function show_paginator() {
    $article = get_id('article');
    $currentPage = strpos($article, l('paginator')) === 0 ? str_replace(l('paginator'), '', $article) : '';
    $home = l('home_sef'); $categorySEF = get_id('category');
    $categorySEF = empty($categorySEF) ? $home : $categorySEF;
    $use_cat_id = $categorySEF == $home ? 0 : retrieve('id', 'categories', 'seftitle', $categorySEF);
    $query_articles = "SELECT * FROM ".db('prefix')."articles WHERE published = 1 AND SUBSTRING(position, 1, 1) != '2'";
      if (!empty($article) && empty($currentPage)) {$query_articles .= " AND seftitle = '$article'";}
    else if ($categorySEF == $home && s('display_page') <> 0) {$id_page = s('display_page'); $query_articles .= " AND id = '$id_page'";}
          else {
            if (s('display_new_on_home') == 'on') {$query_articles .= $use_cat_id != 0 ? " AND category = $use_cat_id" : '';}
    else {$query_articles .= " AND category = $use_cat_id";}
    $query_articles .= " AND position <> 3 ORDER BY date DESC";
            $result_articles = mysql_query($query_articles);
            $numrows_articles = mysql_num_rows($result_articles);
            if (!$result_articles || !$numrows_articles) {echo $title_not_found; return;}
            else {
                $articleCount = s('article_limit');
                $article_limit = (empty($articleCount) || $articleCount < 1) ? 100 : $articleCount;
                $totalPages = ceil($numrows_articles/$article_limit);
                if (!isset($currentPage) || !is_numeric($currentPage) || $currentPage < 1) {$currentPage = 1;}
                else if ($currentPage > $totalPages) {$currentPage = $totalPages;}
                $query_articles .= " LIMIT ".($currentPage - 1) * $article_limit.", ".$article_limit;
            }
    if (!empty($currentPage) && ($numrows_articles > $article_limit) && s('display_pagination') == 'on') {
        paginator($categorySEF, $currentPage, $totalPages, '', l('paginator'));
    }
}}

2. In center, comment out or remove the default paginator code (it's at the end of center()). Commenting out the old code is safer as it makes it easy to roll back. Example:
Quote
...
         if (!empty($article) && empty($currentPage) && $infoline == true) {
            if ($commentable == 'YES') {comment('unfreezed');}
            else if ($commentable == 'FREEZ') {comment('freezed');}
} rel_articles($id,$keywords,3); }

/*         if (!empty($currentPage) && ($numrows_articles > $article_limit) && s('display_pagination') == 'on') {
            paginator($categorySEF, $currentPage, $totalPages, '', l('paginator'));
         }*/
}}

3. In your index.php, add the call <?php show_paginator(); ?> wherever you want the standalone paginator to appear.
Note that we haven't done anything to the original paginator code, meaning that any tweaks, styling etc you may have done to that one will be preserved.

That's it. Enjoy your standalone paginator! ;)

--------------------- * ---------------------

FOR THOSE USING THE HOME-LESS URL MOD BY CODETWIST:
Discussion of problem here

Steps 0-2 as above.

New Step 3: Change your startup() function to this:
Quote
// STARTUP
function snews_startup() {
   connect_to_db();
   $categorySEF = get_id('category');
   $articleSEF = get_id('article');
   if (false !== strpos($categorySEF, 'rss-')) {rss_contents($categorySEF, $articleSEF);}//if ( (!isset( $articleSEF )) || empty($articleSEF) ) {
   if (isset($categorySEF)) {
   if ( !check_category($categorySEF) ) {
      // Look if category isn't page
      $pageId = retrieve('id', 'articles', 'seftitle', $categorySEF);
      if ( $pageId ) {
         $articlePosition = retrieve('position', 'articles', 'seftitle', $categorySEF);
         if ( $articlePosition == 3 || $articlePosition == 1 ) {
            // Twist it here
            $_GET['category'] = l('home_sef') . '/' . $_GET['category'];
            $articleSEF  = $categorySEF;
            $categorySEF = l('home_sef');
         }
      }
      else if ( (substr( $categorySEF, 0, 2) == l('paginator'))  && is_numeric(substr( $categorySEF, 2 )) ) {
         // Home-less home - Twist it here
         $_GET['category'] = l('home_sef') . '/' . $_GET['category'];
         $articleSEF  = $categorySEF;
         $categorySEF = l('home_sef');
      }
   }
}
   $homeSEF = l('home_sef');
   $categoryID = $categorySEF == $homeSEF ? 0 : retrieve('id', 'categories', 'seftitle', $categorySEF);
   $articleCatID = retrieve('category', 'articles', 'seftitle', $articleSEF);
   if (!empty($categorySEF) && $categorySEF != '404') {
      switch(true) {
         case ((!$categoryID || !is_numeric($categoryID)) && check_category($categorySEF) == false):
         case (!empty($articleSEF) && false === strpos($articleSEF,l('paginator')) && !is_numeric($articleCatID)):
         header('Location: '.db('website').'404/'); exit;
       break;
      }
   }
   if ($categorySEF == '404') {header('HTTP/1.1 404 Not Found');}
   update_articles();
   if (isset($_POST['Loginform'])) {
      $user = checkUserPass($_POST['uname']);
      $pass = checkUserPass($_POST['pass']);
      if (md5($user) === s('username') && md5($pass) === s('password') && mathCaptcha($_POST['calc'], $_POST['sum'])) {
         $_SESSION[db('website').'Logged_In'] = token();
}}}
snews_startup();

Step 4 = Step 3 as above.

What the startup function tweak does is to make sure that the paginator doesn't appear on Archive, Contact and Sitemap pages, where it is completely irrelevant.

Notes: This is an experimental mod and probably not interesting for the average end user.
Credits: The forgotten (but not forgotten) Dude that created bramsyuur for creating the standalone paginator code in the first place, and Valdis (codetwist) for expert help with the paginator/home-less URL conundrum.
« Last Edit: June 09, 2009, 01:06:58 pm by Fred K (agentsmith) »
Logged

bramsyuur

  • Hero Member
  • *****
  • Karma: 23
  • Posts: 873
    • http://snews.vietbee.net
Re: Standalone Paginator
« Reply #1 on: December 11, 2007, 04:47:53 pm »

Hi Fred,
I've crated this mod for you some time ago  ;)
Thanks for posting it for all the people.
Cheers!
Logged
La comunidad sNews en tu idioma!
Comunidad sNews en Español

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: Standalone Paginator
« Reply #2 on: December 11, 2007, 05:11:13 pm »

Frederic! Sorry I forgot it was you that wrote this mod -- I thought it was bobbo or philmoz, but there you go. My memory isn't the best...

Lots of karma to you! ;)
Logged

Kan

  • Newbie
  • *
  • Karma: 0
  • Posts: 22
Re: Standalone Paginator
« Reply #3 on: June 09, 2008, 04:19:20 pm »

Pagination on 'sitemap' and 'archive' doesn't work with this paginator. How to make these page paginable?
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: Standalone Paginator
« Reply #4 on: June 09, 2008, 04:39:29 pm »

F***** good question!

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: Standalone Paginator
« Reply #5 on: June 10, 2008, 01:17:48 am »

Pagination on 'sitemap' and 'archive' doesn't work with this paginator. How to make these page paginable?

For archive page is easy to make pagination as in "blog" page and in category page. I don't know for sitemap... is not logic to have many pages for sitemap... because you need a separated sitemap for sitemap pages :P  - but something must be changed for sure.


----------------------------
Maybe including in sitemap only static pages (hardcoded or not and with rss links),  and only categories, without articles. Maybe with an option in control panel to choose to show also articles or not (when you have a little site, with only few articles/projects/stories, then, you can show also articles). But for very big Blogs, displaying articles in sitemap is not a good ideea.
« Last Edit: June 10, 2008, 01:33:09 am by funlw65 »
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Re: Standalone Paginator
« Reply #6 on: June 10, 2008, 04:05:23 am »

Perhaps... (this is just me thinking out loud after looking at a rather long Sitemap page on a current project)... it might be worth making the category titles in the Sitemap Page as expandable... so that there are no articles (content links) showing until you click on a category title to show the links under that category. This would keep the page shorter and only as long as the links list within a given expanded category. I would use the same approach for expanding the category titles as is used in Philmoz's Admin Articles Lists by Categories mod.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Sasha

  • Hero Member
  • *****
  • Karma: 28
  • Posts: 938
    • cssanarchy.com
Re: Standalone Paginator
« Reply #7 on: January 10, 2009, 11:20:59 pm »

i like this mode.Anything with freedom to move snews code inside my page is good for me.Like designer more freedom with code allowed me to use my ideas in new designs :) ...well see what i'm capable to come up with this ;)....
Logged
Every morning, I get up and look through the 'Forbes' list of the richest people in America. If I'm not there, I go to work. | If you love your job, you haven't worked a day in your life. snews with ♥