Home › Forums › Calendar Products › Events Calendar PRO › Creating a custom loop to display events by category in certain WP pages
- This topic has 3 replies, 2 voices, and was last updated 9 years, 5 months ago by Brian.
-
AuthorPosts
-
October 28, 2014 at 1:25 pm #844714Christian ThomsonParticipant
Hello guys, I have a question that I hope is easy for you to figure out.
So, I’m trying to create a custom loop with query_posts, that has a different category parameter for each page ID.
What I got so far:if (is_page(413) || (tribe_events_has_tickets()) ) { query_posts(array( 'post_type' => 'tribe_events' , 'tribe_events_cat' => 'occupational-first-aid-level-1' ) ) ; include('courses-loop.php'); } else { include('courses-noavailable.php'); } if (is_page(422) || (tribe_events_has_tickets()) ) { query_posts(array( 'post_type' => 'tribe_events' , 'tribe_events_cat' => 'occupational-first-aid-level-2' ) ) ; include('courses-loop.php'); } else { include('courses-noavailable.php'); } if (is_page(424) || (tribe_events_has_tickets()) ) { query_posts(array( 'post_type' => 'tribe_events' , 'tribe_events_cat' => 'occupational-first-aid-level-3' ) ) ; include('courses-loop.php'); } else { include('courses-noavailable.php'); }
However, this code outputs the “courses-noavailable.php” file for each of the if statements.
The courses-loop.php contains “while (have_posts()) : the_post(); endwhile; wp_reset_query();” I Tried pasting it here but the code wasn’t displaying properly.
You can download the page-courses.php file with the two PHP includes from the URL: * removed by admin (Please don’t share with public).
Can you please have a look and try to propose a better solution if this isn’t the right way?
Thanks!
CintiaOctober 29, 2014 at 10:31 am #847107BrianKeymasterHello,
I can try to help you out here with some information on your customization.
This functions looks to be where you want to change the coding.
tribe_events_has_tickets()
So that will not return true if on the current event it still has tickets.
So if you use on on another page that is not an event it will always return false.
You can pass a event id (post id) to the function and it will return true or false based off that id.
Here is a good list of conditionals that might help instead of using that function:
https://gist.github.com/jo-snips/2415009
Let me know if that helps.
Thanks
PS I removed the link to that zip file as it was public.
October 30, 2014 at 9:24 am #849950Christian ThomsonParticipantHi Brian,
Thanks for the reply. I was able to figure out what to do.
I left out the tribe_events_has_tickets(), in exchange for the if (have_posts()) … else: … in the loop. This is how I have it:
if (is_page(413) ) {
query_posts(array( 'post_type' => 'tribe_events' , 'tribe_events_cat' => 'catname', 'posts_per_page' => -1 ) ) ;
include('courses-loop.php'); }
And the loop file has this content:
if (have_posts()) :
while (have_posts()) : the_post();
...
endwhile;
else:
No posts available
endif;
And it worked! I hope this helps others, and thanks for the help!October 30, 2014 at 10:35 am #850062BrianKeymasterGreat, glad it is working, I am going to go ahead and close this ticket, but if you need any other on something else please post a new ticket.
Thanks!
-
AuthorPosts
- The topic ‘Creating a custom loop to display events by category in certain WP pages’ is closed to new replies.