Topic: ListGlobal [snippet]  (Read 13146 times)

Pages: [1] 2  All   Go Down

#1: 12-Oct-2005, 07:24 PM

Coding Team

Dr. Scotty Delicious
Posts: 1,192

D.F.P.A.

WWW
If anyone has time, would you look at this "ListGlobal" snippet.  I have been a fan of this menu system since I used Etomite, but it displays the menu items that have "show in menu" unchecked.  Unfortunately, the EPG2 photo gallery snippet does not play well in an unpublished folder, so I would like to know what changes to the ListGlobal code need to be made for it to respect the option to not show in menu.

Code:
// ------------------------
// Snippet: ListGlobal
// ------------------------
// Version: 0.6e
// Date: 2005.07.01
// jaredc@honeydewdesign.com
//
// Snippet for listing global list of links or sections
// (Published pages who's parent is root). Highlight ability
// for current section.

// $node [ int ]
// Id of what you want to consider the "root" of the site or section.
// For instance, if you branch off several sections from the 0 root level
// based on languages, you might want to set the language home page as
// the root. Otherwise it will default to 0- which is the site root. It
// will also default to 0 when 0 is the literal root. Settable in snippet
// call with $LGlob_node:
// [[ListGlobal?LGlob_node=7]]
   $node = 0;
   
// STYLES
// .LGlob_list    ul element of list
// .LGlob_active  li of section you are in

// -----------------------
// END CONFIG
// -----------------------

// Override default node with snippet call if necessary
$node = (isset($LGlob_node))? $LGlob_node : $node;

// Determine correct node to consider parent
$tempPageInfo = $etomite->getPageInfo($etomite->documentIdentifier,0,'parent');
$thisParent = $tempPageInfo['parent'];

// Change root node if necessary
if ($node && !$thisParent){
  $node = 0;
}

$globalKids = $etomite->getActiveChildren($node);
$sectionId = $etomite->documentIdentifier;
while ( ($pageInfo = $etomite->getPageInfo($sectionId,0,'parent')) && ($pageInfo['parent'] != $node ) ) {
  $sectionId = $pageInfo['parent'];
}
$output = '<ul class="LGlob_list">';
$globalCount = 0;
foreach ($globalKids as $kid){
    $output .= '<li';
    $output .= ($kid['id']==$sectionId)? ' class="LGlob_active"' : '' ;
    $output .= '><a href="[~'.$kid['id'].'~]" ';
    $output .= 'title="'.$kid['pagetitle'].'">';
    $output .= $kid['pagetitle'].'</a></li>';
    $globalCount++;
}
$output .= '</ul>';
return $output;

Thank you for your time and your help

-sD-
scotty Delicious

#2: 12-Oct-2005, 07:56 PM

Coding Team

sottwell
Posts: 10,502

WWW
Line 34:
Code:
while ( ($pageInfo = $etomite->getPageInfo($sectionId,0,'parent,hidemenu')) && ($pageInfo['parent'] != $node ) && ($pageInfo['hidemenu'] == '0')) {
sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html

#3: 12-Oct-2005, 08:07 PM

Coding Team

Dr. Scotty Delicious
Posts: 1,192

D.F.P.A.

WWW
hmmm...
No joy.  I changed the code in the ListGlobal snippet with the code you provided, but if you look at

http://www.scottydelicious.com/modx/

the menu items 'Gallery Admin Page' and 'News Stories Go Here' have been unchecked to "show in menu".

By the way, thanks for the speedy reply!

-sD-
scottty Delicious

#4: 12-Oct-2005, 08:16 PM

Coding Team

sottwell
Posts: 10,502

WWW
Hm.  Put a bit of code like this right after that line so you can see what's going on:

Code:
echo "<pre>";
print_r($pageInfo);
echo "</pre>";
sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html

#5: 12-Oct-2005, 08:18 PM

Coding Team

sottwell
Posts: 10,502

WWW
No no no no...it's the line 42 we need to look at.  $globalKids.
sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html

#6: 12-Oct-2005, 08:24 PM

Coding Team

Dr. Scotty Delicious
Posts: 1,192

D.F.P.A.

WWW
Well Susan,

I wish I knew more about PHP.  I did paste the last bit of code you posted directly after the first bit of code you posted.  It looks like it should 'write' something on the screen (echo ?).  anyway.  I did implement the snippet and I am still stuck.  I am not able to see anything 'echoed' to the screen.  Maybe I am not supposed to?  The reason I like this snippet so much is the "ACTIVE" page's tab looks different.  I guess it is not that important, but I like style, and I like the way that Active menu tab makes a website look!

thanks again, and I appreciate all your effort!

-sD-
scotty Delicious

#7: 12-Oct-2005, 08:26 PM

Coding Team

sottwell
Posts: 10,502

WWW
Code:
getActiveChildren($id=0, $sort='menuindex', $dir='ASC', $fields='id, pagetitle, description, parent, alias, menutitle')
is the function definition. So you'll need to do this:
Code:
getActiveChildren($node, , , 'id, pagetitle, description, parent, alias, menutitle, hidemenu')

Then after line 49,
Code:
foreach ($globalKids as $kid){
put the whole inner foreach block in an if block:
Code:
if($kid['hidemenu'] == 0) {
    $output .= '<li';
    $output .= ($kid['id']==$sectionId)? ' class="LGlob_active"' : '' ;
    $output .= '><a href="[~'.$kid['id'].'~]" ';
    $output .= 'title="'.$kid['pagetitle'].'">';
    $output .= $kid['pagetitle'].'</a></li>';
    $globalCount++;
}

That should do the trick.
« Last Edit: 12-Oct-2005, 08:32 PM by sottwell »
sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html

#8: 12-Oct-2005, 08:30 PM

Coding Team

sottwell
Posts: 10,502

WWW
All the menu snippets have that "active" or "selected" or whatever you want to call it.  Some of them you have to specify what you want the class called when you call the snippet.  For example, ListMenuX goes like this:
Code:
[[ListMenuX?id=0&depth=2&divId=my-menu&activeLinkClass=selected]]
then you just style the .selected class in the CSS file.
sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html

#9: 12-Oct-2005, 08:43 PM

Coding Team

Dr. Scotty Delicious
Posts: 1,192

D.F.P.A.

WWW
You are getting sooooo close, I can almost see it.

The last revision still shows the unchecked show in menu pages, however.

Perhaps there is a better way for me to go about this.  Is there any MODx menu snippet that is capable of the "active" highlighting.  I see in the MenuBuilder code that there is a reference to the class "highLight", so i put a ".highLight" and a ".highLight a" class in my CSS, but there was no effect.  I will look into ListMenuX as you mentioned above

Kind regards

-sD-
scotty Delicious

#10: 12-Oct-2005, 09:12 PM

Coding Team

sottwell
Posts: 10,502

WWW
Did you clear your cache?  I just now styled the "a.selected" class for my latest use of MenuBuilder.

http://www.sottwell.com check out the "theo" template.
sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html

#11: 12-Oct-2005, 09:18 PM

Coding Team

sottwell
Posts: 10,502

WWW
Here's one that'll even sweep the floor, I think

* dropmenu.snippet.php.txt (10.35 KB - downloaded 682 times.)
sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html

#12: 12-Oct-2005, 09:21 PM

Emeritus
Mark
Posts: 3,250

Ditto Developer

WWW
Isn't that the replacement for the menubuilder snippet which will be included in TP3.3?  Grin

#13: 12-Oct-2005, 09:30 PM

Coding Team

sottwell
Posts: 10,502

WWW
Could be. I've got 38 snippet in my snippet collection now. My collections aren't too particular about where they get their content.  I haven't used it, I'm still comfortable with ListMenuX.
sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html

#14: 5-Jan-2006, 02:04 PM

Coding Team

jaredc
Posts: 300

0.9a Release
New(er) and improved!

OK, Dimmy arm twisted me (not really  Wink) in to mutilating this snippet to do some funky stuff. I reckon it's best to let others enjoy the fruits of my labor as well. For those who have been playing along and have been using the ol' Etomite version of ListGlobal, here is my changelog of what is new in version 0.9a (from the previous 0.6e and 0.6f versions):

Quote from: My changelog thingy
** 0.9a **
- Added classes so every section is now classed as one of 10 classes which
  indicate if it is active, before or after the active, the first or last item,
  or whether there are no active sections at all (such as in the case of a
  search results page)
- Also updated the version number to reflect matching compatibility with
  MODx
- Switched $etomite object references to $modx
- Accounted for MODx ability to hide options from the menu (hidemenu)
- Added ability to define what to use as the tooltip text
- Menu title uses "menutitle" if available or else defaults to "pagetitle"

* ListGlobal0_9_a.txt (5.26 KB - downloaded 810 times.)
« Last Edit: 5-Jan-2006, 02:08 PM by jaredc »
Standard Disclaimer
I could be totally wrong.

#15: 5-Jan-2006, 02:11 PM

Testers

Dimmy
Posts: 1,999

Я не говорю по-русски 私は日本語を話さない

WWW
Go Jared your the best Your the best!

Thank Jared for taking the time to change this script for my needs (and for the rest of the comunity) this gives MODx so mutch more potential for making funky menu items (If I want to I could have all the items a diff look YEAH)

Nice work!

Dimitri

#16: 25-Jan-2006, 03:51 AM

Moderators

aour
Posts: 835

Hi

I try to use it but it don't take car of my parameter :

Code:
[[ListGlobal?LGlob_node=45]]
   :   I see with node=0

I modified the value in the snippet code :

Code:
$node = 45;
    :   I see with node=0

The parent id of id45 is id0

Aour

#17: 27-Jan-2006, 07:22 AM

Coding Team

jaredc
Posts: 300

I am not sure which version you are using... but if you have this bit of code:

Code:
// Change root node if necessary
if ($node && !$thisParent){
  $node = 0;
}
Try removing it. As I look at it... I can't remember for the life of me why that's there and it looks like the bit that's causing the problem. I'll keep looking at it and report back if that is a vital bit.

[UPDATE]

Yeah that bit seems kinda useless. I think it's a carry over from earlier versions. I'll have to snip it out (nice pun eh?) when I get to it.
« Last Edit: 27-Jan-2006, 07:33 AM by jaredc »
Standard Disclaimer
I could be totally wrong.

#18: 29-Mar-2006, 01:44 AM

Testers

Dimmy
Posts: 1,999

Я не говорю по-русски 私は日本語を話さない

WWW
Jared could you merge this snippet with the listsection snippet? what I am realy asking is that the option for multiple nodes is implemented like this ones I atach it here.

I use [[UltimateParent]] now but this merg wil give more posibilities
Thanks a lot

* ListSections.txt (1.56 KB - downloaded 326 times.)
« Last Edit: 29-Mar-2006, 01:46 AM by Dimmy »

#19: 29-Mar-2006, 07:09 AM

Coding Team

jaredc
Posts: 300

Wow... where do you people find this stuff. I looked at that and saw my name on it and thought... "I wrote that?"  Cheesy 

Then I saw that date - a year ago. I won't go into how bad my memory is- but I will say there's a reason I include my name, date, and a typically generous amount of commenting in my code!  Wink

I don't think I'm still very clear on what is being asked Dimmy. Are you looking for a way to set arbitrary "global" folders?

Edit
Are you referring to the post about UltimateParent? And if so, Doesn't ListSections work for you if you specify the allowed sectionRoots? ... It's been a long time since I've looked at that code.
« Last Edit: 29-Mar-2006, 07:16 AM by jaredc »
Standard Disclaimer
I could be totally wrong.

#20: 29-Mar-2006, 08:04 AM

Testers

Dimmy
Posts: 1,999

Я не говорю по-русски 私は日本語を話さない

WWW
List sections is stiil eto and has not the functions that ListGlobal has like multiple styles and the in menu option
another option would be a seperate snippet that wil generate any of the nodes you give in the call if thats the one he finds first.
like this

if I have 3 folders in the root (1,2,3) and they all have 2 children (1 hase 4,5 2 hase 6,7 3 hase 8,9) those children all have a set of children by dem selfs.

What i like to set the snippet to give me one of the folloing id's depending on what page I curently am: 4,5,6,7,8,9

I hope this explains it.

Dimmy
Pages: [1] 2  All   Go Up
0 Members and 1 Guest are viewing this topic.