Author Topic: Random Category  (Read 9129 times)

0 Members and 1 Guest are viewing this topic.

Offline Naveen

  • Newbie
  • *
  • Posts: 43
    • View Profile
Random Category
« on: November 08, 2006, 05:15:56 PM »
Hi  :D,

I did search the forum regarding this but ended up with nothing.

Can we have a Mod for Random Category? I would like to display Random Categories on my home page.

Something similar to what we have for "Random Images Mod"

Thanx  :mrgreen:

Offline Naveen

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Random Category
« Reply #1 on: November 12, 2006, 10:05:39 AM »
Anyone?  8)

Offline Nicky

  • Administrator
  • 4images Guru
  • *****
  • Posts: 3.195
    • View Profile
Re: Random Category
« Reply #2 on: November 15, 2006, 06:32:06 PM »
as text link?
how much categories should be shown?

etc.. :)
cheers
Nicky
Your first three "must do" before you ask a question ! (© by V@no)
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

nicky.net 4 4images
Signature stolen from mawenzi

Offline Naveen

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Random Category
« Reply #3 on: November 27, 2006, 05:14:30 AM »
Yeah as text, Should show 10 categories.  :mrgreen:

Offline Naveen

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Random Category
« Reply #4 on: December 07, 2006, 05:31:28 PM »
bumpty bump  :oops:

Offline Naveen

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Random Category
« Reply #5 on: September 06, 2007, 10:23:43 PM »
I'm still looking for this mod, can anyone help?

Offline Nicky

  • Administrator
  • 4images Guru
  • *****
  • Posts: 3.195
    • View Profile
Re: Random Category
« Reply #6 on: September 06, 2007, 10:27:06 PM »
lol.... it's a long time ago..

good idea.. i will do it tomorrow
cheers
Nicky
Your first three "must do" before you ask a question ! (© by V@no)
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

nicky.net 4 4images
Signature stolen from mawenzi

Offline Nicky

  • Administrator
  • 4images Guru
  • *****
  • Posts: 3.195
    • View Profile
Re: Random Category
« Reply #7 on: September 07, 2007, 08:50:47 PM »
demo: http://www.nicky.net/4test/test.php

Code: [Select]
<?php
/**************************************************************************
 *                                                                        *
 *    4images - A Web Based Image Gallery Management System               *
 *    ----------------------------------------------------------------    *
 *                                                                        *
 *             File: random_categories.php                                 *
 *        Copyright: (C) 2002 Jan Sorgalla                                *
 *            Email: jan@4homepages.de                                    *
 *              Web: http://www.4homepages.de                             *
 *    Scriptversion: 1.0 for 4images 1.7.4                                *
 *                                                                        *
 *    Never released without support from: Nicky (http://www.nicky.net)   *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *    Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz-       *
 *    bedingungen (Lizenz.txt) für weitere Informationen.                 *
 *    ---------------------------------------------------------------     *
 *    This script is NOT freeware! Please read the Copyright Notice       *
 *    (Licence.txt) for further information.                              *
 *                                                                        *
 *************************************************************************/

// PATH to your 4images Gallery / PFAD zu Ihrer 4images Gallerie
define('ROOT_PATH''./');

include(
ROOT_PATH.'config.php');
include(
ROOT_PATH.'includes/db_mysql.php');
include(
ROOT_PATH.'includes/constants.php');
$site_db = new Db($db_host$db_user$db_password$db_name);

// NUMBER OF CATEGORIES TO DISPLAY / NUMMER DER GEWÜNSCHTEN KATEGORIEN
$num_cats 10;

$sql "SELECT cat_id, cat_name 
        FROM "
.CATEGORIES_TABLE."
        WHERE auth_viewcat="
.AUTH_ALL.
        ORDER BY RAND()
        LIMIT 
$num_cats";
$result $site_db->query($sql);

while (
$row $site_db->fetch_array($result)){
    
$cat_name $row['cat_name'];
    
$cat_id $row['cat_id'];
    echo 
"<a href=\"".ROOT_PATH."categories.php?cat_id=$cat_id\">".$row['cat_name']."<br>\n";
}
?>


include into another file with
Code: [Select]
<?php
include('random_categories.php');
?>

cheers
Nicky
Your first three "must do" before you ask a question ! (© by V@no)
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

nicky.net 4 4images
Signature stolen from mawenzi

Offline Naveen

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Random Category
« Reply #8 on: September 10, 2007, 10:34:40 PM »
Hey   8)

Thank you, Thank you!

I needed it badly :), You guys are great!

Keep up the good work.  :mrgreen:


(BTW how do I use it in 4images itself?)

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: Random Category
« Reply #9 on: September 11, 2007, 01:27:33 AM »
Quote
BTW how do I use it in 4images itself?)

Like this -

// Step 1

In includes/page_header.php file,

find:

Quote
//-----------------------------------------------------
//--- Random Image ------------------------------------
//-----------------------------------------------------

add after:

Code: [Select]
$num_cats = (defined('RANDOM_CATS_VALUE') && RANDOM_CATS_VALUE > 0) ? "LIMIT " . (int)RANDOM_CATS_VALUE : "";

$sql = "SELECT cat_id, cat_name
           FROM ".CATEGORIES_TABLE."
           WHERE auth_viewcat=".AUTH_ALL."
           ORDER BY RAND()
           " . ((isset($num_cats)) ? $num_cats : "");
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);

if (isset($num_rows) && $num_rows > 0) {

$random_cats_template = "";
while ($row = $site_db->fetch_array($result)){
    $cat_id = $row['cat_id'];
    $cat_name = $row['cat_name'];

$site_template->register_vars(array(
"cat_id" => (int)$cat_id,
"cat_name" => format_text($cat_name, 2),
"cat_url" => $site_sess->url(ROOT_PATH . "categories.php?" . URL_CAT_ID . "=" . (int)$cat_id),
"num_rows" => (int)$num_rows
));
$random_cats_template .= $site_template->parse_template("random_cats");
$site_template->register_vars("random_cats_template", trim($random_cats_template));

}
}

// Step 2

In includes/constants.php file,

add after ?>:

Code: [Select]
define('RANDOM_CATS_VALUE', 10);

// Step 3

In your templates/your_template folder, create file: random_cats.html .

Create HTML table and use:

Code: [Select]
{cat_id}
{cat_name}
{num_rows}

and for {cat_url}

Code: [Select]
<a href="{cat_url}" class="link" />{cat_name}</a>

// Step 4

Add: {random_cats_template} anywhere HTML template (ones with: {header} and {footer} - other no work).

;)
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?