Thread

Array problems when running raw php

October 12, 2011 12:36pm

Subscribe [1]
  • #1 / Oct 12, 2011 12:36pm

    triplicate

    4 posts

    I’m having trouble running raw php within my one of my templates. I’m trying to create a page that takes entries and groups them first by date, then by parent category, and finally by category.

    So I loop through my entries building an array in php, before adding it to the relevant position in my final sorted array based on its date, parent and child.

    {exp:channel:entries channel="updates" paginate="bottom"}
     <?php 
     $entry = array(
      'title' => "{title}",
      'file' => "{update_file}"
     );
    
     $date = '{entry_date format="%M %Y"}';
     $parent = '{categories}{if parent_id == "0"}{category_name}{/if}{/categories}'; 
     $child = '{categories}{if parent_id != "0"}{category_name}{/if}{/categories}';
     
     $entries[$date][$parent][$child][] = $entry; 
     ?> 
    {/exp:channel:entries}

    For sum reason this duplicates my parent category for each child entry. I disabled php on the template, copied the php into a plain file and ran it on the same server as the expression engine site and it works fine!

    So the problem must be how expression is executing php.

    I have created an example page here that demonstrates the problem.

    Any help would be appreciated, thanks.

    [Mod Edit: Moved to the Development & Programming forum]

ExpressionEngine News

#eecms, #events, #releases