Home › Forums › Calendar Products › Events Calendar PRO › tribe_events_cat query and tribe_events_list_the_date_headers()
- This topic has 3 replies, 2 voices, and was last updated 11 years ago by
Brian.
-
AuthorPosts
-
June 9, 2015 at 6:58 pm #968335
simonlandin
ParticipantHi
I’m having a lot of fun with your plugin and have gone a very long way without any help due to good support forums and quite a lot of documentation on the web…
Taking some time all the same.
This may be beyond your remit as I’m doing some fairly extensive theming of the events calendar but I’m hoping you could at least point me in the right direction with an area that doesn’t have much documentation at all…
I’ve written a query using tribe_events_cat to return all events in a category slug called club_event where the category id =23. I’ve succesfully tapped into parts of your code from list/content.php and list/loop.php to return a list of events. I’m outputting different queries on different tabs of my events page using the month and list view quite successfully.
The page is at:
http://trial.pow-london.com/?post_type=tribe_events
and outputs all events using the month view but events by catyegory slug using list view.This all seems to be working fine except that when tribe_events_list_the_date_headers() is called it returns the month and year header for each event listing rather than as a divider between months.
I’m wondering if I need an extra field in my array for tribe_events_cat (perhaps _EventStartDate) for tribe_events_list_the_date_headers() to properly process the month dividers.
In other words What fields within the events calendar’s standard queries does tribe_events_list_the_date_headers() require to operate correctly?
Am I on the right track here? The code for the ‘club tab’ is shown below
Many thanks in advance for any help you may be able to give or even pointers in the right direction.
I’m not a hardcore php coder
Simon Landin
<?php
// example args
$args_club = array (
‘paged’ => 1,
‘posts_per_page’ => ‘-1’,
‘offset’ => 0,
‘post_status’ => ‘publish’,
‘ignore_sticky_posts’ => 0,
‘orderby’ => ‘date’,
‘order’ => ‘ASC’,
‘tax_query’ =>
array (
0 =>
array (
‘taxonomy’ => ‘tribe_events_cat’,
‘field’ => ‘id’,
‘terms’ =>
array (
0 => 23,
),
‘operator’ => ‘IN’,
‘include_children’ => false,
),
),
‘post_type’ =>
array (
‘tribe_events’ => ‘tribe_events’,
),
);?><?php
// the query
$the_club_query = new WP_Query( $args_club );
if ( $the_club_query->have_posts() ) : ?>
<?php do_action( ‘tribe_events_before_loop’ ); ?><!– start of the loop –>
<?php while ( $the_club_query->have_posts() ) : $the_club_query->the_post(); ?><?php do_action( ‘tribe_events_inside_before_loop’ ); ?>
<!– Month / Year Headers –>
<?php tribe_events_list_the_date_headers(); ?><!– Event –>
<div id=”post-<?php the_ID() ?>” class=”<?php tribe_events_event_classes() ?>”>
<?php tribe_get_template_part( ‘list/single’, ‘event’ ) ?>
</div><!– .hentry .vevent –><?php do_action( ‘tribe_events_inside_after_loop’ ); ?>
<?php endwhile; ?><!– end of the loop –><?php do_action( ‘tribe_events_after_loop’ ); ?>
<!– put pagination functions here –>
<?php wp_reset_postdata(); ?><?php else: ?>
<p><?php _e( ‘Sorry, there are no club event listings at present.’ ); ?></p>
<?php endif; ?>
June 10, 2015 at 8:48 am #968471Brian
MemberHi,
Thanks for using our plugins. I can try to help out here.
You look like you have gotten pretty far already, which is good to see.
So this function: tribe_events_list_the_date_headers()
Is always returning the Month and Year because it only checks the main query if the month has changed.
You can find that function on this file:
the-events-calendar\public\template-tags\loop.php
To use it as you are using you most likely would have to use that as a base and create a similar function, but instead of the query check you could use a global variable. Using that global you could check each time if the title is the same as the last time it was used and if the same do nothing. If it changed you could then echo the title.
Let me know if you have any follow up questions.
Thanks
June 13, 2015 at 4:18 am #969247simonlandin
ParticipantYup that worked – thanks for the advice.
Here’s the code I wrote (adapted from yours if anyone else can use it…
function club_tribe_events_list_the_date_headers() {/* Month and year separators (on every month and year change) */
$show_headers = apply_filters( 'tribe_events_list_show_date_headers', true );
$html = '';
if ( $show_headers ) {global $club_month, $post, $wp_query;
$event_year = tribe_get_start_date( $post, false, 'Y' );
$event_month = tribe_get_start_date( $post, false, 'm' );
$month_year_format = tribe_get_option( 'monthAndYearFormat', 'F Y' );
//echo $event_month; echo $event_year;
//echo "mymonth="; echo $club_month;
if ($event_month > $club_month) {
//echo "greater print the header";
$html .= sprintf( "<span class='tribe-events-list-separator-month'><span>%s</span></span>", tribe_get_start_date( $post, false, $month_year_format ) );
echo apply_filters( 'tribe_events_list_the_date_headers', $html, $event_month, $event_year );
$club_month = $event_month;
}elseif ($event_month == $club_month) {
//echo "no header";
$club_month = $event_month;
}
else {
//echo "lesser print the header";
$html .= sprintf( "<span class='tribe-events-list-separator-month'><span>%s</span></span>", tribe_get_start_date( $post, false, $month_year_format ) );
echo apply_filters( 'tribe_events_list_the_date_headers', $html, $event_month, $event_year );
$club_month = $event_month;
}}
}June 15, 2015 at 7:39 am #969423Brian
MemberGreat glad it helps and thanks for sharing your solution.
I am going to close this ticket, but if you need anything else related to this topic or another please post a new topic on the forum and we can help you out.
Thanks
-
AuthorPosts
- The topic ‘tribe_events_cat query and tribe_events_list_the_date_headers()’ is closed to new replies.
