Page 1 of 1
How do I access the structure tree?
Posted: Thu 1. Sep 2005, 16:12
by olleolleolle
I am try to make the CMS to spit out a string, conditionally, based on what part of the website we are in.
To do that I want to know if I am in category 4 or 5 at the moment.
My Question: How do I access the structure tree?
I want to know in what part of my tree I am right now -- my goal is to know if I am in the English (ID:5) or the Danish (ID:4) category.
[PHP] tags are your friends.
Posted: Thu 1. Sep 2005, 16:31
by pepe
Take the following phpscript, to proove the top cat-id:
Code: Select all
<?php
// save this php-script as: .../scripts/top_cat_id.php
// call it inside your template or html-Contentpart: {PHP:scripts/top_cat_id.php}
$check_id = $GLOBALS['content']['cat_id'];
while( $GLOBALS['content']['struct'][$check_id]['acat_struct'] > 0 ) {
$check_id = $GLOBALS['content']['struct'][$check_id]['acat_struct'];
}
echo $check_id; // give back CAT-ID of the first level
?>
Thanks!
Posted: Thu 1. Sep 2005, 16:43
by olleolleolle
Oh, thanks.
Got more than I bargained for, the {PHP:scripts/myscript.php} thing I had never seen that before. Great!
Am going to tinker a bit with it, now, and see what I can come up with.
(The top category is not what I am in interested in, but this is a great start. Wait a minute, that depends on what you mean by Top Category. This will be interesting.)
Update: Oh, dear! That was exactly what I needed. Anything I can do for you?
Posted: Thu 1. Sep 2005, 17:02
by pepe
Another possibility.......
Code: Select all
<?php
// save this php-script as: .../scripts/top_cat_id.php
// call it inside your template or html-Contentpart: {PHP:scripts/top_cat_id.php}
$check_id = $GLOBALS['content']['cat_id'];
while( $GLOBALS['content']['struct'][$check_id]['acat_struct'] > 0 ) {
$check_id = $GLOBALS['content']['struct'][$check_id]['acat_struct'];
}
switch($check_id) {
case 4: echo "danish part"';break;
case 5: echo "english part";break;
default: echo "non of them";
}
?>
Posted: Thu 1. Sep 2005, 17:33
by pSouper
thanks pepe, usefull code
As a replacement tag the code looks like this..
Code: Select all
<?php
// save this php-script as: ./phpwcms_template/inc_script/frontend_render/top_cat_id.php
if( ! ( strpos($content["all"],'{TOPCAT}')===false ) ) {
// call it inside your template or html-Contentpart: {PHP:scripts/top_cat_id.php}
$check_id = $GLOBALS['content']['cat_id'];
while( $GLOBALS['content']['struct'][$check_id]['acat_struct'] > 0 ) {
$check_id = $GLOBALS['content']['struct'][$check_id]['acat_struct'];
}
$content["all"] = str_replace("{TOPCAT}", $check_id, $content["all"]);
}
?>
Posted: Thu 1. Sep 2005, 17:38
by pSouper
would you know a way to get just the parent catid?
my reasons for this are to incude a fake list item for my navigation,. I am really looking for a version of NAV_TABLE_COLUMN:id that also shows the parent category too
either fix would be good

Posted: Thu 1. Sep 2005, 20:26
by kubens
try this:
Code: Select all
$article_id = $GLOBALS["content"]["article_id"];
$article_cid = $GLOBALS['content']['articles'][$article_id]['article_cid'];
if ($GLOBALS['content']['struct'][$article_cid]['acat_topcount'] < count($GLOBALS['content']['articles'])) {
$GLOBALS['wak_articles_per_page'] = $GLOBALS['content']['struct'][$article_cid]['acat_topcount'];
}
else {
$GLOBALS['wak_articles_per_page'] = count($GLOBALS['content']['articles']);
}
Posted: Sun 4. Sep 2005, 13:48
by pSouper
thanks - I am on holiday right now and am just loggin in to use up my last few euros in the the machine - after 2hours of work
I will play with this when i get back next week
