Support

Home Forums Event Espresso Premium Upcoming events aren't pulled into sidebar after page 6 in blog

Upcoming events aren't pulled into sidebar after page 6 in blog

Posted: June 10, 2015 at 1:31 pm

Viewing 9 reply threads


HindmanSanchez

June 10, 2015 at 1:31 pm

I am building a new site here http://hindsanchez.seequsdev.com/blog/ and we are using EE4. We are pulling upcoming events into our blog pages sidebar usign:
<?php echo do_shortcode('[ESPRESSO_EVENTS show_expired="false" limit="3" order_by="start_date"]'); ?>

It is working great on the main blog page and pages http://hindsanchez.seequsdev.com/blog/page/2/ through http://hindsanchez.seequsdev.com/blog/page/5/. On http://hindsanchez.seequsdev.com/blog/page/6/ it now only shows 2 events instead of the 3 it is set at. And from page7 http://hindsanchez.seequsdev.com/blog/page/7/ on it doesn’t pull in any events.

Any idea why this is happening and how we can fix it?

Also, it seems that every page shows 3 different events. Is this a setting that I can change?

Thanks!


Josh

  • Support Staff

June 10, 2015 at 3:30 pm

Hi Melinda,

The issues you’re seeing are from using the EE shortcode outside the main loop. It turns out the EE event list shortcode is intended to be placed within content that’s contained within the main loop (usually a WP page).

What’s happening is the event list is catching the pagination request variables for the blog loop. So on each blog page, it’s paging through events too, until it runs out events!

You can fix this by removing the call for do_shortcode() and instead, add a simple query to your sidebar template. The following code will follow everything you have set with the shortcode parameters, and allow for customizing the HTML output too:

https://gist.github.com/joshfeck/6e33532c37a123bbf532


HindmanSanchez

June 10, 2015 at 4:11 pm

@Josh

Awesome! Thank you so much! One other question. How do I get the tag links to show up under the 3 posts? The other code was pulling in tag links for each event like:
<span class="tags-links"><a href="http://hindsanchez.seequsdev.com/blog/event-category/manager-forum/" rel="tag">Manager Forum</a>, <a href="http://hindsanchez.seequsdev.com/blog/event-category/managers/" rel="tag">Managers</a></span>

Thanks!


Josh

  • Support Staff

June 10, 2015 at 4:39 pm

Hi Melinda,

Are you sure that it wasn’t the theme’s code adding those? The reason I ask is because the [ESPRESSO_EVENTS] shortcode doesn’t normally output tags. More than likely it was being appended by either (a) a custom event template in your theme or (b) from the theme itself.

A lot of themes will add a post meta section where it will display tags, which you can copy that code over to the new function or even re-use a template tag from the theme. For example the WordPress Twenty Fifteen theme has the twentyfifteen_entry_meta() template tag.


HindmanSanchez

June 10, 2015 at 4:57 pm

I am pretty sure it was only the do shortcode pulling it in. I added the do shortcode version to my sidebar below the one using your code. The only code aside from the html structure is the do shortcode I showed you above
<?php echo do_shortcode('[ESPRESSO_EVENTS show_expired="false" limit="3" order_by="start_date"]'); ?>

Thanks!


Josh

  • Support Staff

June 11, 2015 at 7:25 am

Hi Melinda,

Have you looked at the code for the [ESPRESSO_EVENTS] shortcode and compared it with your theme? There is no code within the EE shortcode that lists out the tags. What’s happening is when the [ESPRESSO_EVENTS] shortcode is parsed, it starts a new WP loop, and your theme adds what it normally adds to a regular WP loop. Which includes the list of tags, and the pagination, which caused the issue you first reported. What you’ll need to do is look in your WP theme for how it lists out the tags. It may be a template tag or function that you’ll copy over to your sidebar template within the custom event list loop.


HindmanSanchez

June 11, 2015 at 8:47 am

I did look and found this code in the content-espresso_events.php file:
<span class="tags-links"><?php espresso_event_categories( $post->ID, TRUE, TRUE ); ?></span>
I placed it inside your code where I wanted it to appear like so:

<?php
// set up show expired = false
$where = array(
   'Datetime.DTT_EVT_end' => array( '>=', current_time( 'mysql' )),
   'status' => 'publish',
);
// run the query
if ( class_exists( 'EE_Registry' ) ) :
$events = EE_Registry::instance()->load_model( 'Event' )->get_all( array(
   $where,
   'limit' => 3,
   'order_by' => 'Datetime.DTT_EVT_start',
   'order' => 'ASC',
   'group_by' => 'EVT_ID'
));
// the loop
if ( ! empty( $events )) {
   foreach ( $events as $event ) {
      if ( $event instanceof EE_Event && ( !is_single() || $post->ID != $event->ID() ) ) {
         echo '<article class="espresso_events">';
            echo '<div class="espresso-event-header-dv">';
               echo '<header class="event-header">';
                  echo '<h2 class="entry-title"><a href="' . get_permalink( $event->ID() ) . '">' . $event->name() . '</a></h2>';
               echo '</header>';
            echo '<span class="tags-links">' . espresso_event_categories( $post->ID, TRUE, TRUE ) . '</span>';
          echo '</div><!-- end espresso-event-header-dv -->';
        echo '</article>';
      }
   }
 } 
 endif; ?>

But it doesn’t pull in the tags for the posts.

Can you see anything wrong in my code?


Josh

  • Support Staff

June 11, 2015 at 9:41 am

Yes, where you have espresso_event_categories( $post->ID, TRUE, TRUE ), that should be changed to espresso_event_categories( $event->ID(), TRUE, TRUE ).


HindmanSanchez

June 11, 2015 at 9:51 am

That fixed it!!!!

Thank you so much for your help! You are a lifesaver!


Josh

  • Support Staff

June 11, 2015 at 11:27 am

You’re welcome.

Viewing 9 reply threads

The support post ‘Upcoming events aren't pulled into sidebar after page 6 in blog’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso