Home › Forums › Calendar Products › Community Events › Conditional to display add event button in sidebar
- This topic has 4 replies, 2 voices, and was last updated 11 years, 3 months ago by
Barry.
-
AuthorPosts
-
January 14, 2015 at 4:36 pm #933000
jewschool
ParticipantHi,
I’m trying to create a conditional to display a button in my sidebar linking to the community event submission form.
I’m using the following code to invoke the button, but it doesn’t seem to be working. Am I missing something? Am I using the wrong conditionals?
if is_page('events') || tribe_is_event() { echo '<center><a class="button-st button-with-icon button-with-icon-16 ico-st ico-plus button-custom-color" href="/events/community/add" target="_parent" style="background-color: #16a085;"><span>Submit an Event</span></a></center>'; };January 15, 2015 at 8:09 am #933290Barry
MemberHi Benjamin,
You generally ought to wrap the conditional in parentheses:
if ( is_page('events') || tribe_is_event() ) { /*...*/ }Please also note that event views are not actually pages in the traditional WordPress sense (they are not editable posts stored in the database) so if that first test – is_page(‘events’) – is trying to detect requests for the main events page it won’t work (though if you happen to have an actual WordPress page called events and that is one of the things you are looking for then of course it’s completely fine).
I hope that helps 🙂
January 15, 2015 at 11:29 am #933388jewschool
ParticipantDuh, I can’t believe I forgot the parens.
That said: Is there another conditional I can se to check if it’s the main calendar page?
January 15, 2015 at 1:11 pm #933415Barry
MemberNone built in that specifically do just that, but you could potentially use a custom function like this one (modify to suit your needs!):
/** * Returns true if the current page is the main events page, else returns * false. * * Criteria for the "main events page" here means: * * - We're on an events page * - It is the same view as the default events view * - No particular date has been specified * * @return bool */ function is_main_events_page() { global $wp_query; // We needn't worry about non-event requests if ( ! tribe_is_event_query() ) return false; // Get the default view and currently requested view $default = TribeEvents::instance()->default_view(); $current = $wp_query->get( 'eventDisplay' ); // Was a date specifically set? If so, it isn't truly the "main" events page $date_set = $wp_query->get( 'eventDate' ) . isset( $_REQUEST['tribe-bar-date'] ) ? 1 : 0; // Compare and contrast! return ( $default === $current && ! $date_set ); }January 29, 2015 at 6:56 am #938792Barry
MemberHi! It’s been a while so I’m going to go ahead and close this thread. If we can help with anything else, though, please don’t hesitate to create new threads as needed. Thanks!
-
AuthorPosts
- The topic ‘Conditional to display add event button in sidebar’ is closed to new replies.
