How do I access the structure tree?
-
- Posts: 24
- Joined: Mon 18. Apr 2005, 21:35
- Location: Copenhagen, Denmark
- Contact:
How do I access the structure tree?
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.
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.
Olle Jonsson
olleolleolle
olleolleolle
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
?>
-
- Posts: 24
- Joined: Mon 18. Apr 2005, 21:35
- Location: Copenhagen, Denmark
- Contact:
Thanks!
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?
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?
Olle Jonsson
olleolleolle
olleolleolle
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";
}
?>
thanks pepe, usefull code
As a replacement tag the code looks like this..
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"]);
}
?>
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']);
}