Author Topic: [MOD] limited number of categories per page (updated 08-06-2006)  (Read 119010 times)

0 Members and 1 Guest are viewing this topic.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Many people asked about a MOD, that would let limit number of categories per page.

Installation:

Step 1.
Open /function.php
Find:
Code: [Select]
global $site_template, $site_db, $site_sess, $config, $lang;Replace with:
Code: [Select]
global $site_template, $site_db, $site_sess, $config, $lang, $HTTP_GET_VARS;
Step 1.2. (updated 05-27-03)
Find:
Code: [Select]
  $total = sizeof($visible_cat_cache);Add after:
Code: [Select]
//Begin configuration:

$perpage = 10; //how many categories per page
$cat_text = "Found {total_cat_images} categories on {total_pages} page(s). Displayed category {first_page} to {last_page}";

//u can use those tags:
//{total_cat_images} - total categories
//{total_pages} - total pages
//{first_page} - displayed from (number first category displayed)
//{last_page} - displayed to (number last category displayed)
//End configuration

$page = (isset($HTTP_GET_VARS['cat_page'])) ? $HTTP_GET_VARS['cat_page'] : 0;
if (!class_exists("Paging")) {
  include(ROOT_PATH.'includes/paging.php');
}
$link_arg = $site_sess->url(ROOT_PATH.($cat_id ? "categories.php?".URL_CAT_ID."=".$cat_id : "index.php"));
$getpaging = new Paging($page, $perpage, $total, $link_arg, $cat_text, "", "cat_page");
$offset = $getpaging->get_offset();
$limit = ($offset + $perpage > $total) ? $total : $offset + $perpage - 1;
$total = $limit - $offset;
$site_template->register_vars(array(
  "cat_paging" => $getpaging->get_paging(),
  "cat_paging_stats" => $getpaging->get_paging_stats()
));
$cache = array();
$i = 0;
foreach ($visible_cat_cache as $key => $category_id) {
  if ($i >= $offset && $i <= $limit) {
    $cache[] = $category_id;
    $cache_sql .= (($cache_sql != "") ? ", " : "").$category_id;
  }
  $i++;
}
$total = count($cache);
You can change some setting at the beginning of inserted code ;)

Step 1.3.
Find:
Code: [Select]
foreach ($visible_cat_cache as $key => $category_id) {Replace with:
Code: [Select]
foreach ($cache as $category_id){

Step 2. (updated 05-27-03)
If u have not updated your /includes/paging.php file, then download it from Universal Paging Class


Step 3.
Add in /templates/<yourtemplate>/categories.html and in /templates/<yourtemplate>/home.html
those tags:
{cat_paging} and if u want {cat_paging_stats}


Step 4 (added 07-06-2006)
This step needed only for these who is using 4images v1.7 with [MOD] Cache System for 4images v1.7 or 4images v1.7.1, v1.7.2 with activated cache system.
In index.php and categories.php find:
Code: [Select]
    isset($user_info['lightbox_image_ids']) ? substr(md5($user_info['lightbox_image_ids']), 0, 8) : 0,
Insert above:
Code: [Select]
    isset($HTTP_GET_VARS['cat_page']) ? intval($HTTP_GET_VARS['cat_page']) : 0,
« Last Edit: July 21, 2009, 04:18:15 PM by V@no »
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline lakeside

  • Full Member
  • ***
  • Posts: 123
    • View Profile
[MOD] limited number of categories per page
« Reply #1 on: May 11, 2003, 09:03:07 PM »
It works fine, but I get an error at the top of my categories pages that says:
Warning: Division by zero in /home/xxxx/xxxxx/gallery/includes/functions.php on line 1024
 

The following is whats on line 1024 of my functions.php

Code: [Select]
$table_rows = $total / $table_columns;

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] limited number of categories per page
« Reply #2 on: May 11, 2003, 09:43:48 PM »
two solutions:
1. check your 4images settings, what number is set under "Number of table cells" it must be atleast 1
2. if above variant wont help, then try to replace:
Code: [Select]
if ($total <= $table_columns) {with:
Code: [Select]
if ($total <= $table_columns || !$table_columns) { but this is not supposed to be like that...
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline lakeside

  • Full Member
  • ***
  • Posts: 123
    • View Profile
[MOD] limited number of categories per page
« Reply #3 on: May 11, 2003, 10:35:42 PM »
In my settings it lists 2 for table cells

I've replaced what you said, but it still gives the same error.

Okay, after looking some more, I see that indeed it does list 2 for table cells, but I now changed it to 3, and it works fine with what you posted above for changes.

Thanks,

P.S.
I dont know if this is related to this or not, but I have it set to display 20 categories, but it shows 21 categories on the first page, and shows the following:
Found 26 galleries on 2 page(s). Displaying Galleries 1 to 20
when in reality it's displaying 21 categories not 20.

Offline Gawd

  • Pre-Newbie
  • Posts: 4
    • View Profile
Re: [MOD] limited number of categories per page
« Reply #4 on: May 18, 2003, 01:07:24 PM »
Quote from: V@no

Step 1.2.
Find:
Code: [Select]
$total = count($visible_cat_cache);

I can't find that bit of code.... Searched the entire site.
the closest I could find to that is the following.

Code: [Select]
$total = sizeof($visible_cat_cache);

But when I added what you said after that it would only place 1 category in each column, and then all remaining categories in the last column on the page.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] limited number of categories per page
« Reply #5 on: May 18, 2003, 06:23:11 PM »
Quote from: Gawd
I can't find that bit of code.... Searched the entire site.
the closest I could find to that is the following.

ops...yes, u are right...that's how 4images comes by default...I have changed all sizeof operators in all files, because they are alias for count: http://www.php.net/manual/en/function.sizeof.php and might be deleted or renamed to something else in next versions of PHP.

Quote from: Gawd
But when I added what you said after that it would only place 1 category in each column, and then all remaining categories in the last column on the page.
maybe u might also need this fix:
http://4homepages.de/forum/viewtopic.php?t=3160
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline mantra

  • Sr. Member
  • ****
  • Posts: 358
    • View Profile
    • DREAM WITH MANTRA
[MOD] limited number of categories per page
« Reply #6 on: May 19, 2003, 04:07:39 AM »
Quote
The new file in Step 2. is more universal then default /includes/pagin.php. Because of that, u can use that file if u want add different types of paging system or more then one for different types of whatever u do  
I will post separate thread for people who might need it.


Can you give me example V@no :?:

Offline Gawd

  • Pre-Newbie
  • Posts: 4
    • View Profile
[MOD] limited number of categories per page
« Reply #7 on: May 19, 2003, 12:10:00 PM »
Thanx, I'll give it a try as soon as I have my template done, and am ready to start putting the categories in again (stupid lop.com messed me up lost my mysql db as i was getting rid of it.)

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] limited number of categories per page
« Reply #8 on: May 27, 2003, 09:33:33 PM »
Found very bad bug :oops:
Because of witch it didnt displayed properly subcategories, when their ID did follow each other (3, 10, 45, 40)

I have corrected my post, but who already installed this mod, u'll need do this:
In my peace of code find:
Code: [Select]
foreach ($visible_cat_cache as $key => $category_id) {
if ($key >= $offset && $key <= $limit) {
$cache[] = $category_id;
}
}
replace with:
Code: [Select]
$i = 0;
foreach ($visible_cat_cache as $key => $category_id) {
if ($i >= $offset && $i <= $limit) {
$cache[] = $category_id;
    $cache_sql .= (($cache_sql != "") ? ", " : "").$category_id;
}
$i++;
}


also, no need anymore create new allpaging.php file now u can use Univeral Paging Class
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline uksoreeyes

  • Full Member
  • ***
  • Posts: 117
    • View Profile
    • http://www.myleeneklass.com
Re: [MOD] limited number of categories per page
« Reply #9 on: June 14, 2003, 03:07:19 AM »
Quote from: V@no
Quote from: Gawd
I can't find that bit of code.... Searched the entire site.
the closest I could find to that is the following.

ops...yes, u are right...that's how 4images comes by default...I have changed all sizeof operators in all files, because they are alias for count: http://www.php.net/manual/en/function.sizeof.php and might be deleted or renamed to something else in next versions of PHP.

Does this mean that we should change all the
Code: [Select]
$total = sizeof($visible_cat_cache);
in functions.php to

Code: [Select]
$total = count($visible_cat_cache);

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] limited number of categories per page
« Reply #10 on: June 14, 2003, 11:23:25 PM »
Quote from: uksoreeyes

Does this mean that we should change all the
Code: [Select]
$total = sizeof($visible_cat_cache);
in functions.php to

Code: [Select]
$total = count($visible_cat_cache);

wont hurt ;)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Legendary

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • http://www.idols-unlimited.com
Re: [MOD] limited number of categories per page
« Reply #11 on: June 04, 2005, 02:10:16 PM »
I could not get this to work.  Its really weird some how.  I have the latest paging.php, and i installed everything as directions.  But somehow, when you click on page 2, it just doesn't go to page 2.

you can visit: http://idols-unlimited.com to see this. 

it didn't give me any error either, but the page doesn't load page 2, 3, 4..etc

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] limited number of categories per page
« Reply #12 on: June 04, 2005, 03:51:05 PM »
you can visit: http://idols-unlimited.com to see this.
where exactly is it? I couldnt find any paging there...
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Tiburon

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
    • http://www.hintergrundbilder.de
Re: [MOD] limited number of categories per page
« Reply #13 on: June 21, 2005, 11:32:53 AM »
v@no

I have the same problem like Legendary.

There ist no problem installing the Mod and the "{cat_paging}" is shown on categories.html. There is also the number of categories on the page that I wrote into functions.php.

The only thing that does not work is that I canīt go to page 2 or 3 or 4. When I click on page 2 it shows again page 1 and so on. Really frustrating !  :(
----------------------------------

Have a nice Day

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] limited number of categories per page
« Reply #14 on: June 21, 2005, 02:31:22 PM »
below this line:
Code: [Select]
$page = (isset($HTTP_GET_VARS['cat_page'])) ? $HTTP_GET_VARS['cat_page'] : 0;Insert:
Code: [Select]
echo $page;
Then go to second or third page and see what number it shows.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)