How do I access the structure tree?

Discuss phpwcms here, please do not post support requests, bug reports, or feature requests! Non-phpwcms questions, discussion goes in General Chat!
Post Reply
olleolleolle
Posts: 24
Joined: Mon 18. Apr 2005, 21:35
Location: Copenhagen, Denmark
Contact:

How do I access the structure tree?

Post 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.
Olle Jonsson
olleolleolle
pepe
Posts: 3954
Joined: Mon 19. Jan 2004, 13:46

Post 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

?>
olleolleolle
Posts: 24
Joined: Mon 18. Apr 2005, 21:35
Location: Copenhagen, Denmark
Contact:

Thanks!

Post 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?
Olle Jonsson
olleolleolle
pepe
Posts: 3954
Joined: Mon 19. Jan 2004, 13:46

Post by pepe »

:D :D :D

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";	

}
?>
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

Post 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"]);
}
?>
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

Post 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 ;)
kubens
Posts: 168
Joined: Sat 6. Nov 2004, 15:29
Location: Duesseldorf near Cologne ;-)

Post 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']);
  }
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

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