Page 1 of 1

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

Posted: Sat Nov 20, 2004 12:32 pm
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.

Posted: Mon Jul 11, 2005 9:56 pm
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>";
}