Event category can't be found when loaded in header

Home Forums Calendar Products Events Calendar PRO Event category can't be found when loaded in header

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #1326121
    Nick Hadsund
    Participant

    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! 🙂

    #1327238
    Cliff
    Member

    Hi, 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?

    #1327804
    Nick Hadsund
    Participant

    Hi 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.

    #1328558
    Cliff
    Member

    get_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.

    #1328559
    Cliff
    Member

    Oh, 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.

    #1329439
    Nick Hadsund
    Participant

    For 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.
    #1330502
    Cliff
    Member

    get_the_title() will get it, but it won’t echo it.

    Just change get_the_title() to the_title()

    #1330865
    Nick Hadsund
    Participant

    The 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.
    #1331078
    Cliff
    Member

    At 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

    #1331297
    Nick Hadsund
    Participant

    Ok, 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.

    #1331934
    Cliff
    Member

    Thanks 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.

Viewing 11 posts - 1 through 11 (of 11 total)
  • The topic ‘Event category can't be found when loaded in header’ is closed to new replies.