[Solved]: Category Name (Title) in Theme.php [Solved]: Category Name (Title) in Theme.php
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

[Solved]: Category Name (Title) in Theme.php

Started by freesouljah, July 12, 2009, 12:55:03 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

freesouljah

hi there...I have said it before, and will say it again...I think coppermine is AWESOME!!! so thanks for all your hard work on making it so...    :o

now onto my question...

I am trying to figure out how to access the category name of a current image being displayed...I am not a php pro, I would consider myself somewhat better than a novice...I searched and searched, but can't find how you guys pull the category title out...

I am hoping to be able to define it as a variable on theme.php as such:

$categoryTitle = $CURRENT_CATEGORY_DATA['title'];

I know that it doesn't exist, but what can I use to get that result?


thank you mucho!!   ;D ;D


freesouljah

Quote from: Joachim Müller on July 12, 2009, 09:50:08 AM
http://forum.coppermine-gallery.net/index.php/topic,55415.msg270616.html#msg270616

okay...sorry about that...  ;)


http://www.picsandass.com/pics/displayimage.php?pos=-9040  - and there is some adult content in the gallery, not this image but in the gallery...

I want to add the category name in the left corner of my filmstrip...where I have added 'Related Photos:'


8)

Joachim Müller

Upgrade! Running cpg1.4.10 is not an option, with the most recent stable release currently being cpg1.4.25

freesouljah

yeah I guess it has been a while since I have upgraded it...but I didn't realize its been that long...

let me get on that...  :P

in the meantime, can you explain how to extract the category title/name...I know $cat gets the category number...do I use $cat_data?

thanks!

Joachim Müller

Quote from: freesouljah on July 13, 2009, 04:16:15 AM
yeah I guess it has been a while since I have upgraded it...but I didn't realize its been that long...
cpg1.4.10 has been released on 2006-10-29...

Quote from: freesouljah on July 13, 2009, 04:16:15 AM
in the meantime, can you explain how to extract the category title/name...I know $cat gets the category number...do I use $cat_data?
I don't remember out of the back of my head, but I'm pretty sure that the category name doesn't get populated globally in theme.php. It get's populated if needed, i.e. on index pages. It doesn't get populated on displayimage pages. Your best bet is the breadcrumb. Alternatively, run the additional queries (as categories can be nested indefinitely at least in theory, the loop will need to be recursive) in a custom function. To get an idea how to accomplish this code-wise, take a look at the code in catmgr.php - find function get_subcat_data($parent, $ident = '') and simplify as you see fit.

freesouljah



Quote from: Joachim Müller on July 13, 2009, 07:30:25 AM
cpg1.4.10 has been released on 2006-10-29...

man...what a long strange trip its been...  8)


Quote from: Joachim Müller on July 13, 2009, 07:30:25 AM
I don't remember out of the back of my head, but I'm pretty sure that the category name doesn't get populated globally in theme.php. It get's populated if needed, i.e. on index pages. It doesn't get populated on displayimage pages. Your best bet is the breadcrumb. Alternatively, run the additional queries (as categories can be nested indefinitely at least in theory, the loop will need to be recursive) in a custom function. To get an idea how to accomplish this code-wise, take a look at the code in catmgr.php - find function get_subcat_data($parent, $ident = '') and simplify as you see fit.

after trying to get this figured out (the best I could do was get the last category created or the last category alphabetically to be called)...frustrated, but not defeated, I remembered that you noted that it gets populated on the index pages...which led me to search for where it gets populated...which led me to search for the term "CURRENT"...and lo-and-behold, there is actually a "$CURRENT_CAT_NAME" which does exactly what I am looking to do...heheheheheeee....  :o


thanks for the help...it is much appreciated...and thanks for the long past due update reminder...



for those of you looking at this post for the answer...what I did was add "$CURRENT_CAT_NAME" to the global definitions of the function:

function theme_display_image($nav_menu, $picture, $votes, $pic_info, $comments, $film_strip)
{
    global $CONFIG,$CURRENT_ALBUM_DATA,$CURRENT_PIC_DATA,$CURRENT_CAT_NAME;


and then I was able to use where I saw fit:




print "Related Photos:<br><span class=\"alblink\"><a href=\"thumbnails.php?album=search&amp;search=$CURRENT_CAT_NAME\">$CURRENT_CAT_NAME</a></span><br><br>";



enjoy life!!!

peace

Joachim Müller

Thanks for resolving your thread. Actually, $CURRENT_CAT_NAME gets populated within the breadcrumb function definition in include/functions.inc.php - the corresponding code snippet is        $category_array = array();

        // first we build the category path: names and id
        if ($cat != 0)
        { //Categories other than 0 need to be selected
                if ($cat >= FIRST_USER_CAT)
                {
                    $user_name = get_username($cat - FIRST_USER_CAT);
                    if (!$user_name) $user_name = 'Mr. X';

                    $category_array[] = array($cat, $user_name);
                    $CURRENT_CAT_NAME = sprintf($lang_list_categories['xx_s_gallery'], $user_name);
                    $row['parent'] = 1;
                }
                else
                {
                    $result = cpg_db_query("SELECT name, parent FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '$cat'");
                    if (mysql_num_rows($result) == 0)
                        cpg_die(CRITICAL_ERROR, $lang_errors['non_exist_cat'], __FILE__, __LINE__);
                    $row = mysql_fetch_array($result);

                    $category_array[] = array($cat, $row['name']);
                    $CURRENT_CAT_NAME = $row['name'];
                    mysql_free_result($result);
                }

                while($row['parent'] != 0)
                {
                    $result = cpg_db_query("SELECT cid, name, parent FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '{$row['parent']}'");
                    if (mysql_num_rows($result) == 0)
                        cpg_die(CRITICAL_ERROR, $lang_errors['orphan_cat'], __FILE__, __LINE__);
                    $row = mysql_fetch_array($result);

                    $category_array[] = array($row['cid'], $row['name']);
                    mysql_free_result($result);
                } // while

                $category_array = array_reverse($category_array);
        }

freesouljah

 ;)

thanks...

now I know where it gets populated...but I certainly have a long way to go before I will fully understand how it gets populated....I couldn't seem to isolate it in function get_subcat_data...

Joachim Müller

Does that matter? To use it within your custom function, just make it global and you're fine.

freesouljah

Quote from: Joachim Müller on July 13, 2009, 11:28:32 AM
Does that matter?

hehe....not really...but it would be nice...I would like to understand cpg and php more...but there will be more problems that arise which will require digging and investigating, and maybe it will click in my mind at that point...


until that day...thank you kindly for your insight and patience...


peace