Hi Guys, me again. My better half would like specific pages showing in the accordion menu. I figured that I could restrict it to display just a range of page id's. I have the code: Code: {foreach from=$templatepages item="entry"} <li><a class="page" href="{$smarty.const.URL}/pages.php?pg={$entry.pURI}">{$entry.pPageTitle}</a></li> {/foreach} Which I understand as fetching an array of all the pages. I tried wrapping this in an IF statement but can't get it to work properly. I can get it to recognise the array (with the IF), but are having trouble being able to identify the page ID's. Here's what I had as a test: Code: {if is_array($templatepages.pageID) == "17"} {foreach from=$templatepages item="entry"} <li><a class="page" href="{$smarty.const.URL}/pages.php?pg={$entry.pURI}">{$entry.pPageTitle}</a></li> {/foreach} {/if} If you can stop laughing, I was taking a stab in the dark about how to reference the page ID, and only show the page that has the ID of "17". I actually want pages 17-23 inclusive, but was just trying to get it to work correctly first. Am I even close? Glenn
Just to add, I know I could "hard code" the pages I want in, but i'm trying to get a better understanding of smarty and make the code cleaner. Glenn
I think you need to do it this way: Code: {foreach from=$templatepages item="entry"} {if $entry.pageID==17} <li><a class="page" href="{$smarty.const.URL}/pages.php?pg={$entry.pURI}">{$entry.pPageTitle}</a></li> {/if} {/foreach} or Code: {foreach from=$templatepages item="entry"} {if $entry.pageID==17 || $entry.pageID==18 || $entry.pageID==19} <li><a class="page" href="{$smarty.const.URL}/pages.php?pg={$entry.pURI}">{$entry.pPageTitle}</a></li> {/if} {/foreach}
Thanks Eric, that worked great. I was sooo close. I thought that once the FOREACH statement had already called the array (and so built it), it couldn't be restricted after that. Thanks for the lesson…and being so quick at responding. Glenn