nested shortcode
WordPress Event Management, Calendars & Registration › Forums › General Question › nested shortcode
This topic contains 14 replies, has 2 voices, and was last updated by Stephen Harris 11 years ago.
-
AuthorPosts
-
January 29, 2014 at 6:06 pm #9275
We are looking for a way to nest shortcode within shortcode. Specifically, we need to insert shortcode into the “no_events” attribute. We are thinking that it can be done with the do_shortcode wrapper within wordpress. If anyone can help with this scenario, please let us know.
Bryan Rohling
January 29, 2014 at 7:53 pm #9279The best way to do this is to use the event shortcode template:
shortcode-event-list.php
and calldo_shortcode()
there. You can’t then use the ‘template tags’, (e.g.%start_date%
), but you can simply edit the template and use the API (e.g.echo eo_get_the_start( 'jS F Y' );
).Stephen Harris
January 29, 2014 at 8:39 pm #9282[eo_events ondate=”+30 minutes now” no_events=”[eo_events event_category=”heimstudio” numberposts=”5″]” “event_category=”heimstudio” numberposts=”1″]
If this the shortcode on our page, should the modification below display the nested shortcode? Passing the event category is needed, because we only want events for individual rooms.
When testing, anything that is added with quotes or square brackets in the no_events parameter is removed when displayed.
<?php elseif( ! empty($eo_event_loop_args[‘no_events’]) ): ?>
<ul id="<?php echo esc_attr($id);?>" class="<?php echo esc_attr($classes);?>" > <li class="eo-no-events" > <?php echo do_shortcode ($eo_event_loop_args['no_events'];) ?>
<?php endif; ?>
Bryan Rohling
January 29, 2014 at 8:47 pm #9284I wouldn’t try to pass a shortcode within a shortcode attribute, it will be confuse WordPress. It would be best in your case to remove the no_events attribute and simply replace the ‘no events’ message in the template with
do_shortcode( '[eo_events event_category="heimstudio" numberposts="5"]' );
But if you are doing that, I’d recommend against calling
[eo_events]
. If the first shortcode finds no events, and the above also finds no events, you’ll end up in an infinite loop. Probably best to skip thedo_shortcode(...)
and implement something manually (e.g. see examples here: http://codex.wp-event-organiser.com/function-eo_get_events.html).Stephen Harris
January 30, 2014 at 9:09 pm #9317Do you have a suggestion for passing the event_category? Since the template is used for all calls to eo_events list. Therefore the event category could not be hard coded on the template page. So if [eo_events ondate=”+30 minutes now” no_events=”heimstudio” “event_category=”heimstudio” numberposts=”1″] is used at the page level could something like the following be used at the template level in the no_events section <?php elseif( ! empty($eo_event_loop_args[‘no_events’]) ): ?>
<ul id=”<?php echo esc_attr($id);?>” class=”<?php echo esc_attr($classes);?>” >
<li class=”eo-no-events” >
<?php
$events = eo_get_events(array(
‘numberposts’=>5, ‘event_start_after’=>’today’, ‘event_category’=>$eo_event_loop_args[‘no_events’], ‘showpastevents’=>false,//Will be deprecated, but set it to true to play it safe. )); if($events): echo ‘<ul> '; foreach ($events as $event): //Check if all day, set format accordingly $format = ( eo_is_all_day($event->ID) ? get_option('date_format') : get_option('date_format').' '.get_option('time_format') ); printf( '<li> <a href="%s"> %s </a> on %s </li>', get_permalink($event->ID), get_the_title($event->ID), eo_get_the_start($format, $event->ID,null,$event->occurrence_id) ); endforeach; echo ' </ul>'; endif; ?>
<?php endif; ?> I am just trying to understand if we are headed down the right path. We are looking for a fall back listing basically. However it is individualize to each rooms events so a single template has to have the variable passed in somehow. Also we placed the the shortcode-event-list.php in our theme folder. However, no changes to it seem to be changing the results, when rendered on a page. Should these template files be in the root of the theme folder or nested in the structure somewhere? Thanks for your time and consideration on our issue.
Bryan Rohling
January 31, 2014 at 1:19 am #9321I see, so the shortcode displays a certain category for events starting on the date 30 minutes from now. In the event there isn’t any events, you want to retrieve events from that category.
In that case I would use the shortcode:
[eo_events ondate="+30 minutes now" event_category="heimstudio" numberposts="1"]
And then if there are no events, in the template files using he following:
<?php $events = eo_get_events(array( 'numberposts'=>5, 'event_start_after' => 'today', 'event_category' => $eo_event_loop->get('event-category') )); if( $events ): echo '<ul>'; foreach ($events as $event): //Check if all day, set format accordingly $format = ( eo_is_all_day($event->ID) ? get_option('date_format') : get_option('date_format').' '.get_option('time_format') ); printf( '<li><a href="%s"> %s </a> on %s</li>', get_permalink( $event->ID ), get_the_title( $event->ID ), eo_get_the_start($format, $event->ID, null, $event->occurrence_id ) ); endforeach; echo '</ul>'; endif; ?>
-
This reply was modified 11 years, 1 month ago by
Stephen Harris.
Stephen Harris
February 20, 2014 at 7:04 pm #9675Thanks for all of your help! We have discovered that none of the changes that we are making to the plugin template files are being recognized. We made copies of the template files to the theme directory and edited them there, but no changes were seen on the site. I am not able to figure out how to identify which template file is being used, so I went ahead and removed the copies in the theme directory and made the edits to the templates in the plugin directory.
I can confirm that they are the only template files for event organiser that exist on the server. But when I go to the plugins page and then click on Edit, it shows the template files as “Inactive” in the title bar, as such:
Edit Plugins
Editing event-organiser/templates/shortcode-event-list.php (inactive)I have restarted the server and deactivated the plugin and the inactive state still persists. How do we force the plugin to use the template files or can we identify what template files it thinks it is using?
Thanks again!
Bryan Rohling
February 24, 2014 at 10:26 am #9702Hi Bryan,
‘Inactive’ here is something WordPress adds to indicate that the plug-in itself is not active. This is a bug in WordPress and so if the plug-in is ‘active’ in your plug-in’s directory you can just ignore it.
Just to double check: that template is used only for the event list shortcode (not the widget) and it will not be used in you are using the shortcode with the tags (e.g.
%start_date%
).Stephen Harris
February 24, 2014 at 6:47 pm #9704Well, we are still not seeing any changes to the output of our ‘no_events’ shortcode after changing the template. In fact, even if I just tell the template to echo the word “test” for ‘no_events’, it does not display. I have deleted the entire plugin and installed new, then I edited the code, and then I activated the plugin. I deleted all other copies of the templates and I am editing the original in the plugin folder.
Here is the html on the page itself:
[eo_events ondate=”+30 minutes now” event_category=”burkholderauditorium” numberofposts=”1″]
%start{jS M Y}%
<strong style=”font-size: medium;”>%event_title%
Scheduled %start{g:ia}{}% to %end{g:ia}{}%
[/eo_events]
Here is my code in shortcode-event-list.php:
<?php elseif( ! empty($eo_event_loop_args[‘no_events’]) ): ?>
<?php
$events = eo_get_events(array(
‘numberposts’=>5,
‘event_start_after’ => ‘today’,
‘event_category’ => $eo_event_loop->get(‘event-category’)
));if( $events ): echo '<ul>'; foreach ($events as $event): //Check if all day, set format accordingly $format = ( eo_is_all_day($event->ID) ? get_option('date_format') : get_option('date_format').' '.get_option('time_format') ); printf( '<li><a href="%s"> %s </a> on %s</li>', get_permalink( $event->ID ), get_the_title( $event->ID ), eo_get_the_start($format, $event->ID, null, $event->occurrence_id ) ); endforeach; echo '</ul>'; endif;
?>
<?php endif; ?>
Bryan Rohling
February 24, 2014 at 7:59 pm #9705Hi Bryan,
(The forums use markdown – to display blocks of code simply leave a blank line and indent by four spaces (or just highlight the code and click the curly braces icon. When writing code, don’t convert less/more than signs into html entities.)
To clarify – the templates are ignored when using the tags such as
%event_title%
. If you want to use the default/custom template for the shortcode you need to just use the shortcode on its own without%start{jS M Y}% %event_title% Scheduled %start{g:ia}{}% to %end{g:ia}{}%
This can instead be put inside the template as:
printf( '%s %s Scheduled %s to %s', eo_the_start('jS M Y'), get_the_title(), eo_get_the_start( 'g:ia' ), eo_get_the_end( 'g:ia' ) );
Stephen Harris
February 24, 2014 at 10:32 pm #9707Thanks for all of your help! I know you said we could not use the tags within the shortcode, but we didn’t realize our existing tags were within the shortcode. The good news is, we have it working as expected now. We had to make on additional change to make the event list show up when no events were found. We had to add no_events=”filler” to the shortcode statement. If we omitted the no_events property, it would not show anything and if we just left the property blank, it wouldn’t show either.
Bryan Rohling
February 26, 2014 at 4:49 pm #9758I spoke too soon! We are not seeing events from the specified category from the code we added to the no_events section. We are seeing all events for all categories. Here is the snippet of code:
$events = eo_get_events(array( 'numberposts'=>5, 'event_start_after' => 'now', 'event_category' => $eo_event_loop->get('event-category')
Another problem is that we are seeing events in the list that have started before ‘now’. I would expect that we would only see events that have a start time after ‘now’ with the above date format. But we are seeing all events that are currently active regardless of the start time.
Bryan Rohling
February 27, 2014 at 3:51 pm #9775Hi Bryan,
Would you like me to take a look at your site? I think it might easier to see what’s going on with everything in context. Feel free to send an e-mail via this form with details. What’ you’ve posted seems fine.
I’m aware you trying to get a second list to show in the event that the first does not return any events – just so I’m clear, which list are you experiencing problems with – the first, second or both?
Stephen Harris
February 27, 2014 at 6:32 pm #9782We have it working now. We had to replace the underscore with a hyphen in the event-category property and we had to add the showpastevents property so it wouldn’t show events that had already started.
<?php $events = eo_get_events(array( 'numberposts'=>5, 'showpastevents' => 'false', 'event_start_after' => 'now', 'event-category' => $eo_event_loop->get('event-category') ));
Bryan Rohling
February 28, 2014 at 4:22 pm #9793I completely missed that. Shortcodes don’t allow hyphens to be used in attribute names which is why an underscore is used. Everywhere else it is hyphens.
Regarding the ‘showpastevents’ argument – that shouldn’t be necessary (although it is included in a lot of examples), so I’ll take a look and see how to resolve that.
Stephen Harris
-
This reply was modified 11 years, 1 month ago by
-
AuthorPosts