Page 1 of 1
{CATNUM} Displays category number
Posted: Sat 15. Jan 2005, 16:50
by DavidNetk
Hello everyone. I've been lurking for a while but finally registered.
I'm not so good with PHP yet, still studying. I've been trying to make a replacement tag to get the category number of the current page but as you may had guessed already, I've had no luck.
I wonder if one of you has already done so or could help me out to do one. I want it so that I can display a different image on the left navigation space depending on which category the person is. That way I won't have to make a template per category just to get this done. So it'd be something like
<img src="{CATNUM}.jpg" alt="{PAGETITLE}">
Thank you.
Never mind, I just had to try harder
Posted: Sat 15. Jan 2005, 17:58
by DavidNetk
Never mind, I just had to try harder
I got it! Here it is:
Code: Select all
// Display current category number - by David Quint
// include in include/inc_front/content.func.inc.php
if( ! (strpos($content["all"],'{CATNUM}')===false)) {
$content["all"] = str_replace('{CATNUM}', $content["cat_id"], $content["all"]);
}
//--------------------------------------------------------------
The tag is:
{CATNUM}
And it will give a number
Re: Never mind, I just had to try harder
Posted: Sat 15. Jan 2005, 18:23
by Pappnase
DavidNetk wrote:Never mind, I just had to try harder
I got it! Here it is:
Code: Select all
// Display current category number - by David Quint
// include in include/inc_front/content.func.inc.php
if( ! (strpos($content["all"],'{CATNUM}')===false)) {
$content["all"] = str_replace('{CATNUM}', $content["cat_id"], $content["all"]);
}
//--------------------------------------------------------------
The tag is:
{CATNUM}
And it will give a number
hello
maybe edit the code that i will be work in the frontent_render folder. so the people need not edit the source.
Posted: Sat 15. Jan 2005, 18:29
by DavidNetk
I'm sorry, I quite didn't understand
. And most likely I don't know how to do that... yet.
Posted: Tue 18. Jan 2005, 07:14
by ionrock
I think you can also get the structure level from the session variables. you can take a look at all that kind of stuff by creating a file or having in a php block :
Code: Select all
echo "<pre>";
print_r($GLOBALS);
echo "</pre>";
That might help you so you don't even have to make replacement tag.
Re: {CATNUM} Displays category number
Posted: Tue 18. Jan 2005, 10:22
by erwanpia
DavidNetk wrote:I wonder if one of you has already done so or could help me out to do one. I want it so that I can display a different image on the left navigation space depending on which category the person is. That way I won't have to make a template per category just to get this done.
hi dude, I posted a message about that a while ago in the "proud of your web site forum"
http://www.phpwcms.de/forum/viewtopic.p ... highlight=
everything explained about how I implemented a different image logo for each structure / category
Posted: Tue 18. Jan 2005, 10:27
by cyrano
fine i use a script by Jan212 for random images, but show images by level is also very nice.
Would it be possible to add a file format?
especially flash?
or does this no work with this code snippet?
Posted: Tue 18. Jan 2005, 10:56
by brans
I guess the replacement tag should then look like this:
Code: Select all
$content["all"] = preg_replace('/\{CATNUM:(.*?)\}/ie', '$content["cat_id"].".$1"', $content["all"]);
usage: {CATNUM:jpg} => 0.jpg
{CATNUM:extemsion}
didn't test it but I hope it will work for you.
Re: {CATNUM} Displays category number
Posted: Tue 18. Jan 2005, 15:38
by DavidNetk
erwanpia wrote:DavidNetk wrote:I wonder if one of you has already done so or could help me out to do one. I want it so that I can display a different image on the left navigation space depending on which category the person is. That way I won't have to make a template per category just to get this done.
hi dude, I posted a message about that a while ago in the "proud of your web site forum"
http://www.phpwcms.de/forum/viewtopic.p ... highlight=
everything explained about how I implemented a different image logo for each structure / category
This one is great! Does the same thing mine does but without having to edit the source.
I did it that way because my knowledge of PHP is limited and just had to find something that worked. I didn't want to add ".jpg" to the tag because I thought it would limit its use. If I just leave it to category number the same tag can be used to display a ".swf",".gif",".png" or whatever
Thank you for the replies and examples everyone! It is greatly appreciated!
Posted: Wed 19. Jan 2005, 10:17
by brans
hmm david have a look at my code... simply create a file:
replacementtags.php in your frontent render folder and
add my code in there then you ill be able to include your
images with whatever extension you like by simply adding
the extension in the replacement tag... as I told you above..
AND YOU ABSOLUTELY DONT HAVE TO EDIT THE SOURCE CODE WHENEVER YOU USE THE FRONTEND_ RENDER / INIT FOLDER!
{CATNUM:EXTENSION}
Examples:
{CATNUM:jpg}
{CATNUM:txt}
{CATNUM:swf}
{CATNUM:gif}
{CATNUM:doc}
{CATNUM:pdf}
{CATNUM:png}
and so on...
You can define new functions in any file in your frontend_init folder and call them in any replacementtag or whatever code in any file in the frontend_render folder. In Both of these folders you can use predefined phpwcms functions (by including the proper files) and variables (without inclding any file)
Posted: Wed 19. Jan 2005, 14:31
by DavidNetk
brans wrote:hmm david have a look at my code... simply create a file:
replacementtags.php in your frontent render folder and
add my code in there then you ill be able to include your
images with whatever extension you like by simply adding
the extension in the replacement tag... as I told you above..
AND YOU ABSOLUTELY DONT HAVE TO EDIT THE SOURCE CODE WHENEVER YOU USE THE FRONTEND_ RENDER / INIT FOLDER!
{CATNUM:EXTENSION}
Examples:
{CATNUM:jpg}
{CATNUM:txt}
{CATNUM:swf}
{CATNUM:gif}
{CATNUM:doc}
{CATNUM:pdf}
{CATNUM:png}
and so on...
You can define new functions in any file in your frontend_init folder and call them in any replacementtag or whatever code in any file in the frontend_render folder. In Both of these folders you can use predefined phpwcms functions (by including the proper files) and variables (without inclding any file)
Oh that's awesome! Now I understand. Sorry for taking so long!
Yeah I'll do that, thank you again!