Tagged: groups, reverse array
- This topic has 3 replies, 2 voices, and was last updated 7 years, 3 months ago by
Jason.
-
AuthorPosts
-
-
October 20, 2014 at 2:28 pm #2594
slatebMemberI have a field group called updates that I am trying to display in reverse order so that the last item I add displays as the most recent update. I’ve tried to use
array_reversebut that doesn’t seem to work.$updates = get_post_meta($post->ID, 'all_program_updates', true);
piklist(get_stylesheet_directory() . '/partials/program-updates', array('data' => $updates, 'loop' => 'data'));Is there a way to do this with the piklist function? To loop the data in reverse?
Thanks for the help!! -
October 20, 2014 at 2:54 pm #2595
JasonKeymasterHopefully Steve or someone who uses the Piklist template features will chime in, but I don’t personally use them.. the reason is the one that you’re experiencing now. I just want Piklist to store and retrieve the data for me, and I’ll determine how best to handle/manipulate it from there.
If it’s a group, then I use my PiklistHelper::parse_array function to put it in an easier structure.
I just use a foreach, parse through the content, and build the content. For example:
$boxes = get_post_meta($post->ID, 'boxes_example', true); $boxes = array_reverse(PiklistHelper::parse_array($boxes)); $list = ''; foreach($boxes as $box) $list .= "<h2>{$box['caption']}</h2><p>{$box['content']}</p>"; echo $list;Something like that, anyway. Now you can manipulate the array of data as you would any other array in php. No framework limitations. Hope this helps! 🙂
-
October 20, 2014 at 3:01 pm #2597
slatebMemberYeah Jason I found your helper function after I posted that and just finished up the code. Works great!!
Thanks so much. -
October 20, 2014 at 3:26 pm #2598
JasonKeymasterGlad to help! If you have any issues feel free to add an Issue on github or make a pull request to add anything! I’m hoping folks will start adding to that more once they use Piklist regularly and have an idea of what would be useful. 🙂
-
-
AuthorPosts
- The topic ‘Reverse Display Order for Groups’ is closed to new replies.