Coppermine: Category -> album if there is only one.

Technical Q&A involving operating systems, networking, software, and hardware issues.

Moderator: jasonb

Post Reply
User avatar
jasonb
Site Administrator
Posts: 105
Joined: Tue Apr 22, 2003 1:54 pm
Location: Toronto, Canada
Contact:

Coppermine: Category -> album if there is only one.

Post by jasonb »

Here's how to reconfigure Coppermine so that if there's only a single album in a category, when you click on the category link it will take you directly to it - rather than requiring you to click on the category and then also on the album:

Find the file index.php in your coppermine folder.
then replace line 130:

Code: Select all

$link = "<a href=\"index.php?cat={$subcat['cid']}\">{$subcat['name']}</a>";
with:

Code: Select all

if ($album_count==1)
{
$sql = "SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = {$subcat['cid']} LIMIT 0,1";
$result = db_query($sql);
$aid = mysql_fetch_row($result);
mysql_free_result($result);
$link = "<a href=\"thumbnails.php?album=$aid[0]\">{$subcat['name']}</a>";
}
else
{
$link = "<a href=\"index.php?cat={$subcat['cid']}\">{$subcat['name']}</a>";
}
This comes from the user "BMWHeaven" from this discussion thread.

This functionality can also be obtained by allowing BBCode in category titles as per this discussion, but the BBCode method isn't nearly as elegant since there are a few problems with it.
Last edited by jasonb on Sat Aug 06, 2005 11:36 pm, edited 1 time in total.
User avatar
jasonb
Site Administrator
Posts: 105
Joined: Tue Apr 22, 2003 1:54 pm
Location: Toronto, Canada
Contact:

Post by jasonb »

If running Coppermine 1.4.1 beta, the code to alter begins at line 189, and "db_query($sql)" should be replaced with "cpg_db_query($sql)":

Code: Select all

$link = "<a href=\"index.php?cat={$subcat['cid']}\">{$subcat['name']}</a>";
with:

Code: Select all

if ($album_count==1)
{
$sql = "SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = {$subcat['cid']} LIMIT 0,1";
$result = cpg_db_query($sql);
$aid = mysql_fetch_row($result);
mysql_free_result($result);
$link = "<a href=\"thumbnails.php?album=$aid[0]\">{$subcat['name']}</a>";
}
else
{
$link = "<a href=\"index.php?cat={$subcat['cid']}\">{$subcat['name']}</a>";
}
Post Reply