We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: Structure Entries - Add-on for Structure module

Development and Programming

Peter Lewis's avatar
Peter Lewis
280 posts
about 16 years ago
Peter Lewis's avatar Peter Lewis

Structure Entries v1.0.11 (16th June 2010) attached to this post.

For support please post here: Get Satisfaction. Please don’t send issues to Travis/BuildWithStructure.

Extends the excellent Structure module with a tag pair allowing you to output your Structure managed pages with your own html markup (for a menu, summary page, bullet points, whatever), with control on the depth of parent/child and doesn’t need to sit inside {exp:weblog:entries} tag pair. It also supports categories.

Obviously you’ll need Structure installed!

Change Log: v1.0.8 Fix for status, default if no status specified is != ‘closed’ Fix for EE update (v1.6.9) - page URI Added new variable {current_parent} which is set to true if parent of current page v1.0.9 Fix for current_parent variable not working! Tsk! v1.0.10 Bug fix for limiting depth and close markup not closing parents with deeper children. Also updated examples. v1.0.11 License change

Code:

{exp:structure_entries depth="2" parent="10" category_id="7" limit="4"}
...
Your html markup and EE Fields.
...
{/exp:structure_entries}

It’s a tag pair, so always needs the closing tag. All parameters are optional, defaults are shown below.

Parameters:

depth - to restrict how deep the output is (defaults to 0 - all) parent - to only show the children beneath the specified parent (including grand-children, etc). This can be either the entry_id of the parent or the path to the parent. category_id - the category ID that you want shown - only entries (including children) assigned to the specified category will be shown. limit - restricts the output so only the amount of pages you specify will be shown (handy for summary pages, where you might only want to show a few of the child pages). Default is unlimited. status - limit output to a specific status (can only handle one status), by default outputs all status except “closed”.

Variables:

Additional variables available (beyond the standard EE fields and custom fields) include: {page_uri} = Is the entry URL value {page_url} = Is the URL to the entry as returned by Structure {current_page} = returns 1 (true) if the current page matches the page output by the entries loop {depth} = Displays the current level of pages deep this page is (how many parents it has) {parent_id} = Entry ID for the parent of the current page, if it’s top level, it returns 0 {count} = running counter for all entries that match the supplied parameters {total_children} or {children_total} = Total entries that match the supplied parameters (depth, parent & category) {last_child} or {last_sibling} = Returns true or false boolean to indicate if the entry is the last sibling in the current group and level of entries {sibling_count} = running counter of siblings working through the current group at the same level {total_siblings} or {sibling_total} = total siblings for the current group at this level

As of v1.0.7 a tag pair: {close_markup}{/close_markup} = Parsed once the entries loop reaches the last entry it it’s current branch, then repeats the pair through all parents, allowing you to close the markup.

Examples:

Example 1 (very basic):

{exp:structure_entries}
  {title}
{/exp:structure_entries}

Which will list all structure entries (any depth/level) and any fieldname/variable specified within the template tags will be shown. FF Matrix is supported with a very minor amend to the FieldFrame code.

Example 2:

{exp:structure_entries parent="10" depth="1"}
   <li {if {current_page}}class="current"{/if}>
       <a href="http://{page_uri}">{theme-url}/images/{page_url}.gif</a>
   </li>
{/exp:structure_entries}

Displays the children (1 level) of a specific parent, using images and custom fields as an alternative to {title}.

Example 3:

{exp:structure_entries category_id="6" depth="1"}
    <li {if {current_page}}class="current"{/if}>
        <a href="http://{page_uri}">{if "{alternative-title}" != ""}{alternative-title}{if:else}{title}{/if}</a>
    </li>
{/exp:structure_entries}

Example 4:

<ul>
{exp:structure_entries}
{if {depth} == 1}{!-- Top Level --}
    <li>
        <a href="http://{page_uri}">{title} Depth={depth} Parent={parent_id}</a>
  {if {children_total} == 0}{!-- No Children - so close markup --}
    </li>
  {/if}

{if:else}{!-- Children (not top level) --}
  {if {sibling_count} == 1}{!-- First child - so open markup --}
        <ul class="level{depth}">
  {/if}
            <li>
                <a href="http://{page_uri}">{title} Depth={depth} Parent={parent_id}</a>
    {close_markup}
       {if {total_children} == 0 || {depth} == {restricted_depth}}
            </li>
       {/if}
       {if {last_sibling} && {sibling_count} == {sibling_total}}
         </ul><!-- End of level{depth} closing tags -->
      </li>
        {/if}
    {/close_markup}
{/if}
{/exp:structure_entries}
</ul>

This will output any level of page depth with correct opening and closing of the list markup.

For support, help & comments please post here: Get Satisfaction

       
Peter Lewis's avatar
Peter Lewis
280 posts
about 16 years ago
Peter Lewis's avatar Peter Lewis

To get it to display FieldFrame fields, including FF Matrix, you need to do the following hack (sorry!)…

The 2 tweaks to FieldFrame are the following to the ext.fieldframe.php file (based on v1.3.5):

line 2177 from:

function _parse_tagdata(&$tagdata, $fields)

To:

function _parse_tagdata(&$tagdata, $fields, $call_hook=TRUE)

line 2232 from:

$new_tagdata = call_user_func_array(array(&$field['ftype'], $tag_func), array($params, $field_tagdata, $field['data'], $field['settings']));

To:

$new_tagdata = call_user_func_array(array(&$field['ftype'], $tag_func), array($params, $field_tagdata, $field['data'], $field['settings'], $call_hook));

EDIT: Because of the PHP errors reported under PHP v5.0.3, this functionality isn’t enabled by default, so please download the version attached to this post. To avoid getting the PHP error message, you’ll need to add the following to your PHP.ini (may need to search for it as it will probably already exist but set to false or off): allow_call_time_pass_reference=true

All the above isn’t a fantastic solution, but as I’m tapping into the existing code of FieldFrame, it’s the only way currently. I’m working on a better method without any hacking, which should be available soon.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
about 16 years ago
Mark Bowen's avatar Mark Bowen

Hiya,

Not sure what all this means but I just tried using the plugin by simply plonking it into an existing template used within Structure and I got this error message :

Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of [runtime function name](). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. in /usr/local/psa/home/vhosts/*******.com/httpdocs/admin/plugins/pi.structure_entries.php on line 349

Best wishes,

Mark

       
Peter Lewis's avatar
Peter Lewis
280 posts
about 16 years ago
Peter Lewis's avatar Peter Lewis

Hmmm, I had so much grief from that one line - it relates to the call to the FieldFrame class, so I have disabled FieldFrame support on the plugin and re-uploaded. I can only assume that your version of PHP doesn’t like the “&” (which sends the variable by reference).

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
about 16 years ago
Mark Bowen's avatar Mark Bowen
Hmmm, I had so much grief from that one line - it relates to the call to the FieldFrame class, so I have disabled FieldFrame support on the plugin and re-uploaded. I can only assume that your version of PHP doesn’t like the “&” (which sends the variable by reference).

Is the new version uploaded yet as I’m still getting that same error I’m afraid :-(

Just tried downloading from the link above again but still the same I’m afraid.

Best wishes,

Mark

       
Peter Lewis's avatar
Peter Lewis
280 posts
about 16 years ago
Peter Lewis's avatar Peter Lewis

Yep, I had re-uploaded, but I expect it was a browser cache issue, as it had the same filename. Actually Mark I had emailed it directly to you after I read your first comment.

I’ve now commented out the entire offending function and re-uploaded with a different filename, so fingers crossed!

Out of interest, do you know what PHP version you’re testing on?

Thanks.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
about 16 years ago
Mark Bowen's avatar Mark Bowen

Hiya,

The new link at the top of this thread now gets rid of the error but the one you sent across in the e-mail didn’t. Saying that I’m not entirely certain what the plugin should be doing as I have the version which is at the top of this thread installed and I tried with the basic example that you showed above :

{exp:structure_entries}
  {title}
{/exp:structure_entries}

If I place this into a new template or an existing template used by Structure then I just get my normal page template output, nothing extra showing anywhere.

Not sure what I’m doing wrong?

Best wishes,

Mark

P.S. PHP Version is 5.2.3

       
Peter Lewis's avatar
Peter Lewis
280 posts
about 16 years ago
Peter Lewis's avatar Peter Lewis

Hmmm, my PHP is v5.2.5, so doubtful that’s the issue. Leave that for another day…

The one emailed to you only had the call commented, the one on this thread now has the whole function commented out.

Just tested this on it’s own template:

<ul>
{exp:structure_entries}
    <li><a href="/{page_url}">{title}</a></li>
{/exp:structure_entries}
</ul>

Here’s the results.

What version of Structure are you using? If you don’t mind helping debug this issue, can you email me please?

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
about 16 years ago
Mark Bowen's avatar Mark Bowen

Hiya,

Hmmm, my PHP is v5.2.5, so doubtful that’s the issue. Leave that for another day… The one emailed to you only had the call commented, the one on this thread now has the whole function commented out. Just tested this on it’s own template:
{exp:structure_entries}
    <li><a href="/{page_url}">{title}</a></li>
{/exp:structure_entries}
Here’s the results. What version of Structure are you using? If you don’t mind helping debug this issue, can you email me please?

Hmm very very strange. I just tried the code that you’ve posted that I’ve quoted and that seems to be working!

I have absolutely no idea why it didn’t work previously though. I thought it might have been a copy paste error from the forums but I re-typed it in myself and it still didn’t work. Really not sure why it just suddenly started working though, very very strange.

Off to have a play with this now.

Best wishes,

Mark

       
Brian Litzinger's avatar
Brian Litzinger
704 posts
about 16 years ago
Brian Litzinger's avatar Brian Litzinger

This looks really nice. The Structure nav markup is already pretty nice, but this will come in handy for those crazy navigation menus some designers cook up.

       
onemanarmy's avatar
onemanarmy
23 posts
about 16 years ago
onemanarmy's avatar onemanarmy

Hi,

I need to get only the first (root) level for use in a main navigation, but depth=”1” seems to go down one level and 0 displays all levels. Is there any way to get only the first one?

The reason I’m not using Structure’s native nav_main function is that I have to show the second level for only one of them. So I need an if statement inside the tag pair, which isn’t possible with Structure on its own as it only uses single tags.

Any clever solution to my problem..?

       
Peter Lewis's avatar
Peter Lewis
280 posts
about 16 years ago
Peter Lewis's avatar Peter Lewis

depth=”1” should work fine, as that’s what I’m using on the northstar example above - it only shows the top level. If it doesn’t let me know what version of Structure you’re using.

But, because you want to show 1 of the menus with it’s children, you should set it to depth=”2”, then have an IF looking for the relevant parent id.

<ul>
{exp:structure:entries depth="2"}
  {if {depth} == 1 || {parent_id} == xx}{!-- Top Level or specific parent for 2nd level --}
  <li><a href="http://{page_uri}">{title}</a></li>
  {/if}
{/exp:structure:entries}
</ul>

Replace the “xx” for the entry_id of the page that has the dropdown list of children (assume it is a parent inside Structure).

The above assumes you want all top level pages displayed, you can use a category to restrict this display if need be.

       
Peter Lewis's avatar
Peter Lewis
280 posts
about 16 years ago
Peter Lewis's avatar Peter Lewis

Actually, you should also be able to do this via a category without the if statement, and have only the sub-pages (level 2) you want shown set to the category, so if the children aren’t set to that category, they won’t be shown. This is also a way of showing some of the children, not all.

       
onemanarmy's avatar
onemanarmy
23 posts
about 16 years ago
onemanarmy's avatar onemanarmy

Thanks for your reply. But I dont get the depth attribute to work. I have two levels of pages set up in Structure and using

{exp:structure_entries depth="1"}

But it just spits out a linear list with both levels in it.

I’m using Structure and 2.0.6 and downloaded your plugin today.

       
stinhambo's avatar
stinhambo
1,268 posts
about 16 years ago
stinhambo's avatar stinhambo

Fantastic! I was disappointed that I couldn’t do this on a current project only yesterday so this is unbelievably timely!

       
1 2 3 Last

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.