Home › Forums › Calendar Products › Events Calendar PRO › [Customization – Event Calendar PRO] Multiple Templates for List Events Widget
- This topic has 5 replies, 2 voices, and was last updated 9 years, 6 months ago by Barry.
-
AuthorPosts
-
October 24, 2014 at 11:45 am #833002kauffmanincParticipant
Hi there,
I’ve customized the default list-events widget per the online guides, and they’re working great (thanks for building in a method to do that, by the way).
The issue I’m running into now is that I’d like to use the same widget on a different page, but I want the tweaks to *that* instance of the widget to be a bit different than the one I already have. So if I tweak the template/theme to work on the new page, I mess up the old page. Does that make sense?
Is there a way to choose which template/theme the widgets use on a per-instance basis? Or is there perhaps a way to register a new widget that is identical in function, but which uses a different template file?
Thanks in advance!
October 24, 2014 at 3:47 pm #833580BarryMemberHi kauffmaninc,
There is indeed a means of doing this.
One is to set up a filter on the widget_display_callback hook provided by WordPress: this provides access to three parameters – the instance array, the widget object itself and the arguments array.
Through one or more of those you can identify a specific instance of a widget and – by recording this in your code somewhere – conditionally load an alternative template (or conditionally include/exclude blocks of code in an existing template).
Does that help at all?
October 24, 2014 at 4:15 pm #833667kauffmanincParticipantI hope so! I’ll give it a try at work next week and report back.
Thanks!
October 27, 2014 at 9:04 am #840884BarryMemberHappy to help – and good luck!
October 29, 2014 at 10:01 am #847038kauffmanincParticipantHi Barry,
The widget_display_callback hook did, indeed, give me the answer I needed. For the sake of anyone else looking for a similar solution, I additionally used information on this page: http://wordpress.stackexchange.com/questions/57546/determining-a-widget-instance-and-sidebar-location
With that, I was able to determine which piece of information was going to be the most useful to me. I ended up using the $args[‘id’] value, and was able to include additional HTML in my list-widget template file based on that.
I did not need to keep the hook installed in my functions.php file in order for the IF statement in the template to keep working; I only needed it to find out what was in the various arrays.
Thanks again!
October 29, 2014 at 10:08 am #847052BarryMemberAwesome – glad that worked and thanks for referencing the WP Stack Exchange post – definitely could be useful for others out there 🙂
Since it sounds like you’re all good I will go ahead and close this thread, but please don’t hesitate to create new threads if we can help with anything else.
Also, if you have a moment to spare, we’d love to hear your thoughts on The Events Calendar over on our plugin review page – thanks again!
-
AuthorPosts
- The topic ‘[Customization – Event Calendar PRO] Multiple Templates for List Events Widget’ is closed to new replies.