Home › Forums › Calendar Products › Events Calendar PRO › Event category can't be found when loaded in header
- This topic has 11 replies, 3 voices, and was last updated 6 years, 7 months ago by Cliff.
-
AuthorPosts
-
July 25, 2017 at 5:13 pm #1326121Nick HadsundParticipant
Hi.
I want to find the category of my events in the header as I want to change make changes based on this. I have tried using even though I’m on an event-page, it returns nothing (on normal pages, it will still echo the title based on the code below).
To test I have tried to echo get_the_title(), but this shows nothing as well.
`echo get_the_title($post);
echo get_the_terms(get_post($post), ‘tribe_events_cat’)[0]->name;’I have tested this in a foursixteen theme as well, but the code will first work if inserted AFTER the loop (and I need it before).
Hope you can help me out! 🙂
July 27, 2017 at 7:37 pm #1327238CliffMemberHi, Nick.
I’m unclear exactly what you’re wanting. Are you saying you want to run some special code when on a specific Event Category archive view, e.g. how to detect if you’re on the “Conferences” category?
July 28, 2017 at 9:34 pm #1327804Nick HadsundParticipantHi Cliff, sorry that I’m unclear.
Yes, I want exactly what you are describing.
When I’m running
echo get_the_title($post);
on standard posts (before the loop) it shows the title, but on events it shows nothing.July 31, 2017 at 6:28 pm #1328558CliffMemberget_the_title() should be working just fine. Maybe your $post variable isn’t set correctly, or maybe it’s not running in the correct context / at the correct time. I’d need to know where you’re putting that code.
Also note that you could just use the_title() instead.
July 31, 2017 at 6:34 pm #1328559CliffMemberOh, if you’re trying to get the title for the entire Event Category, not a single event, you should instead be using tribe_events_title() or single_term_title(), depending on your desired implementation.
Please let me know if you have any follow-up questions on this topic.
August 2, 2017 at 7:56 am #1329439Nick HadsundParticipantFor this example, I’m using Twenty Fourteen, and the only thing I’m modding is the header.php in the header-tag and no other plugin beside the Event Calendar is active. This is just an abstract example, that shows that get_the_title() do not return any thing on the event-pages before the loop. The added picture shows the differences between a normal page and an event page with the upper code modded in the header.php
<header id="masthead" class="site-header" role="banner"> <div class="header-main"> <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1> <div class="search-toggle"> <a href="#search-container" class="screen-reader-text" aria-expanded="false" aria-controls="search-container"><?php _e( 'Search', 'twentyfourteen' ); ?></a> </div> <strong><?php get_the_title(); ?></strong> <nav id="primary-navigation" class="site-navigation primary-navigation" role="navigation"> <button class="menu-toggle"><?php _e( 'Primary Menu', 'twentyfourteen' ); ?></button> <a class="screen-reader-text skip-link" href="#content"><?php _e( 'Skip to content', 'twentyfourteen' ); ?></a> <?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu', 'menu_id' => 'primary-menu' ) ); ?> </nav> </div> <div id="search-container" class="search-box-wrapper hide"> <div class="search-box"> <?php get_search_form(); ?> </div> </div> </header><!-- #masthead -->
The purpose is to get the title, and add functionality based on this. the_title() did not work either.
- This reply was modified 6 years, 8 months ago by Nick Hadsund.
August 3, 2017 at 7:48 pm #1330502CliffMemberget_the_title() will get it, but it won’t echo it.
Just change get_the_title() to the_title()
August 4, 2017 at 10:34 am #1330865Nick HadsundParticipantThe missing echo was a mistake in my copy of the code. I have recreated my issue in a clean version of wordpress. Please take a look at the following two pages:
http://udvikling.dystopia.dk/hello-world/
http://udvikling.dystopia.dk/event/test-event/In the first, you can see the title of the post being in the left side of the page, in the second you cannot.
In this example I used the_title() in the end of header.php;- This reply was modified 6 years, 7 months ago by Nick Hadsund.
August 4, 2017 at 7:04 pm #1331078CliffMemberAt the time of my previous reply, I tested with header.php of the Twenty Sixteen theme. Could you try that theme, just in case there’s something funky with Twenty Fourteen?
Also, I’d suggest testing any effect of changing wp-admin > Events > Settings > Display tab > template
August 5, 2017 at 3:02 pm #1331297Nick HadsundParticipantOk, I’ve tested what you asked me to:
When the template setting are set to “Default Page Template”, it can’t find the post, page or event before the loop.
When the template setting are set to “Default Events Template”, it work just as if it was a page or post.I’ve set the thread to “resolved”, but I must say, that it is counter-intuitive that the event-page does not behave lige a page on the “Default Page Template”.
Thanks for the help.
August 7, 2017 at 10:27 pm #1331934CliffMemberThanks for your thorough reply.
I have seen this working better with some themes than with others. Sorry this didn’t work intuitively for your situation.
-
AuthorPosts
- The topic ‘Event category can't be found when loaded in header’ is closed to new replies.