{CATNUM} Displays category number

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
DavidNetk
Posts: 19
Joined: Thu 13. Jan 2005, 21:52
Contact:

{CATNUM} Displays category number

Post 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.
Last edited by DavidNetk on Sat 15. Jan 2005, 20:05, edited 3 times in total.
DavidNetk
Posts: 19
Joined: Thu 13. Jan 2005, 21:52
Contact:

Never mind, I just had to try harder

Post by DavidNetk »

Never mind, I just had to try harder :D

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 :D
Pappnase

Re: Never mind, I just had to try harder

Post by Pappnase »

DavidNetk wrote:Never mind, I just had to try harder :D

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 :D
hello

maybe edit the code that i will be work in the frontent_render folder. so the people need not edit the source. :wink:
DavidNetk
Posts: 19
Joined: Thu 13. Jan 2005, 21:52
Contact:

Post by DavidNetk »

I'm sorry, I quite didn't understand :?. And most likely I don't know how to do that... yet.
:wink:
ionrock
Posts: 279
Joined: Fri 20. Feb 2004, 17:04

Post 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.
erwanpia
Posts: 39
Joined: Wed 21. Apr 2004, 10:28
Location: Breizh - Europa
Contact:

Re: {CATNUM} Displays category number

Post 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
cyrano
Posts: 1598
Joined: Sat 31. Jan 2004, 18:33
Location: Stuttgart
Contact:

Post 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?
Gruß/ regards cyrano
--------------------------------------------------------
templates -> http://www.128.weitzelmedia.de
planepix -> http://www.planepix.de
XING -> https://www.xing.com/profile/Thomas_Weitzel3
brans

Post 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.
DavidNetk
Posts: 19
Joined: Thu 13. Jan 2005, 21:52
Contact:

Re: {CATNUM} Displays category number

Post 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 :D

Thank you for the replies and examples everyone! It is greatly appreciated!
brans

Post 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)
DavidNetk
Posts: 19
Joined: Thu 13. Jan 2005, 21:52
Contact:

Post 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! :D
Yeah I'll do that, thank you again! :!: :mrgreen:
Post Reply