- This topic has 7 replies, 2 voices, and was last updated 11 years, 4 months ago by Michelle.
Author | Posts |
---|---|
June 29, 2013 at 2:03 am #3253 | |
Michelle
Post count: 11
|
Hi, not sure if this is a question or suggestion but is there a ‘code recipe’ for accessing field sets not associated with a post/page/type – ie Site Field Sets? That would be very helpful. In particular, I’m trying to loop through a multi-item field set in the Site Field Sets. I think the loop is working correctly, but it’s returning two blank records instead of the images: This code is in my footer.php file: http://pastebin.com/yjX6z4Vk My Site Field Set is set up like htis: Thanks for your help! |
June 29, 2013 at 4:14 am #3255 | |
Michelle
Post count: 11
|
Okay, I’ve made a bit of progress. Using this code within the foreach loop, I can get an img tag to spit out: echo $wf->site->field(“footer_icons.logo_image”); BUT, the path to the image is incorrect – it doesn’t account for me working on a Windows localhost/WAMP installation and uses backslashes instead of forward slashes for the latter half of the URL: http://localhost/webber/wp/wp-content/mp/uploads%5Csite%5Cimages%5Clogo-ut-austin.v1.gif Any ideas? Thank you! (PS I have updated to the latest beta to see if that fixed it but nothing changed.)
|
June 29, 2013 at 4:50 pm #3259 | |
traversal
Post count: 207
|
You’re quite right about the site code, that’s exactly how you do it 🙂 Sorry about the image path thing – will check this in Windows again, and let you know when a fix is available. |
June 29, 2013 at 4:51 pm #3260 | |
traversal
Post count: 207
|
Actually, you don’t have to call “field” strictly in your code. Can also do: $wf->site->footer_icons->logo_image |
July 3, 2013 at 2:18 am #3263 | |
Michelle
Post count: 11
|
Cool, thanks! I’ll look for the update – it’s making developing the site pretty tough not to have that working. 🙂 |
July 3, 2013 at 2:33 am #3264 | |
Michelle
Post count: 11
|
Oh – and sorry – I’m still not getting how this should work, even if the paths were correct. See this pastebin for my updated code: When I use this, it doesn’t loop correctly; it just outputs the first submitted entry multiple times. I tried using the code from example #4 on this page: https://www.masterpressplugin.com/docs/developer/recipes/field-sets-and-fields (see my original Pastebin above) but that didn’t work either. What am I missing? Thanks! Michelle |
July 3, 2013 at 5:26 pm #3268 | |
traversal
Post count: 207
|
Hey Michelle, The code for the loop is slightly wrong. By reaccessing $wf->site->footer_logos, you’re actually accessing only the first item in that set each time. This is by design – we decided that if you access a field in a multi-item set like that, it would access the field from the first record in the set, which can be handy at times. You need to use the $footer_logo loop variable each time, so your code should look something like this: Hope that helps. I still haven’t had a chance to check the Windows issue, but will look at it soon. Sorry! |
July 4, 2013 at 4:16 am #3269 | |
Michelle
Post count: 11
|
Thanks so much Travis! That (+ the WAMP path fix) works great. Whew! 🙂 |
You must be logged in to reply to this topic.