ExpressionEngine template and PHP parsing order -


i'm trying automate listings , in doing need run php, php used detect category same as current page's url title outputs id of category same url title.

i want apply id list of products outputs relevent items (like categories giving flexibility of using structure).

however i'm guessing because i'm defining variable on same page isn't working reason, ideas? php parsing in template set "output".

         {exp:channel:entries}            {categories}{if category_url_title == "{last_segment}"}<?php $category = '{category_id}'; ?>{/if}{/categories}         {/exp:channel:entries}          {exp:channel:entries category="<?php echo $category; ?>" dynamic="no" channel="products"}           <h2>{title}</h2>         {/exp:channel:entries} 

don't bother! keep simple:

low's seg2cat

using {last_segment_category_id} replace code above for:

{exp:channel:entries category="{last_segment_category_id}" dynamic="no" channel="products"}     <h2>{title}</h2> {/exp:channel:entries} 

the reason code won't ever work because want first part run ee first, php save variable, want php continue , set second part, want ee kick in again , use php variable. it's 1 followed other, not jumping between 2 i'm afraid.

another way around utilising embeds:

1st template:

{exp:channel:entries}     {categories}{if category_url_title == "{last_segment}"}{embed="my-templates/2nd-template" category="{category_id}"}{/if}{/categories} {/exp:channel:entries} 

2nd template:

{exp:channel:entries category="{embed:category}" dynamic="no" channel="products"}     <h2>{title}</h2> {/exp:channel:entries} 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -