add html above calendar for a specific a category.

Home Forums Calendar Products Events Calendar PRO add html above calendar for a specific a category.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #110312
    Sean
    Participant

    i am looking for a way to add an image / html above a calendar for a specific category, for example we have a category for Easter events and would like to put an image above the calendar with an Easter theme but not have this image show for any other category.

    #110620
    Julie Kuehl
    Participant

    Hey seancon1,

    Help me understand more about what you’re trying to do here. I’m going to assume we’re talking about a single event page and not something like the monthly view. Would the event have it’s own featured image, and you want to display a second image related to the category? Would every category that you use have an associated image or just a few special ones, like Easter? Your requirements may be crossing over into the area of customization, which we can’t really provide support for, but I’d like to be clear about what you’re trying to do first.

    – Julie

    #110642
    Sean
    Participant

    well i thought html above a calendar for a specific category pretty much said it. but to clarify, we would like to add html above any view for a category, IE Month, List, week, day, map, photo or a specific event in the easter category. as long as what is displayed in the easter category, the html is above the Month, List, week, day, map, photo views or a specific event. the html would always be the same.

    #111043
    Sean
    Participant

    is this something that could be accomplished with tribe_events_before_html() wrapped in a conditional?

    #112386
    Barry
    Member

    Hi Sean, you certainly could do something along those lines: that function also has a filter hook of the same name – tribe_events_before_html – so you could certainly set up a filter and add (or not add) additional text or imagery based on the context of the request. Please do check out the following resources:

    Does that clarify things at all?

    #112493
    Sean
    Participant

    not really, i am not able to find anything other than the tribe_events_before_html function is located in general.php in the links above. can you be a little more specific on where to find information on the tribe_events_before_html filter hook, or documentation on how to use filter hooks in general?

    #113008
    Barry
    Member

    Sure: we don’t have much of our own documentation on hooks and filters at a general level because this is something WordPress provides and is fairly well covered in their own documentation:

    http://codex.wordpress.org/Plugin_API/Hooks

    The general form for something like this though would be:

    add_filter( 'tribe_events_before_html', 'add_text_before_events' );
    
    function add_text_before_events( $html ) {
    	// Change the conditional criteria to something meaningful if you only want
    	// to add text/HTML under certain circumstances
    	$condition = true;
    
    	// You could prepend, append or replace entirely the HTML that displays
    	if ( $condition ) $html = '<p> My HTML </p>' . $html;
    	return $html;
    }

    I hope that helps!

    #115963
    Sean
    Participant

    i will give this a try and report back,

    it looks like i was not completely clear on filters and hooks. looking through the docs and there are 2 different links i have found,
    https://theeventscalendar.com/support/documentation/
    and the one you gave me http://docs.tri.be/
    the first link only makes reference to 3 filter/hooks and the 2nd looks more like code reference with out much info on what can be used at least for my question about tribe_events_before_html
    i had an email conversation with Rob and it looks like this is under revamp.

    Sean

    #116002
    Sean
    Participant

    here is what i came up with… feel free to comment on how to improve. it may be better to query the slug but i have not found a reference in the doc’s yet.


    add_filter( 'tribe_events_before_html', 'add_text_before_events' );
    function add_text_before_events( $html ) {
    if ( tribe_meta_event_category_name() == "CATEGORY NAME" ) $html = '<p> HTML </p>' . $html;
    return $html;
    }

    #116232
    Sean
    Participant

    i was thinking i could remove the last $html variable and it would overwrite anything in tribe_events_before_html but this seems to break the page. should i include a closing tag or something rather than just deleting the variable?

    if ( tribe_meta_event_category_name() == "CATEGORY NAME" ) $html = '<p> HTML </p>' . $html;

    #116327
    Barry
    Member

    Hi Sean:

    it looks like i was not completely clear on filters and hooks. looking through the docs and there are 2 different links i have found,
    https://theeventscalendar.com/support/documentation/
    and the one you gave me http://docs.tri.be/

    Right, so the current and up-to-date technical docs are to be found at the second of those links. The first relates to our earlier 2.0.x releases and was left online for those users who still build or maintain sites using that branch. We definitely are still working to flesh out our current documentation, as it sounds like Rob suggested.

    <p style=”text-align: left;”>i was thinking i could remove the last $html variable and it would overwrite anything in tribe_events_before_html but this seems to break the page. should i include a closing tag or something rather than just deleting the variable?</p>

    So it looks like you don’t have a return statement in your second revision of that snippet: generally speaking filter functions need to return a variable.

    If the first version worked for you there’s no particular reason you shouldn’t just run with it: our own event categories are simply a regular WordPress custom taxonomy and so there is plenty of documentation in the Codex you can refer to if you want to investigate a different strategy like referencing the slug or ID – but really that’s beyond what we can help with as it’s very much custom development territory.

    It does look like you’re on track though which is great and so I’ll go ahead and close this thread.

    Good luck 🙂

Viewing 11 posts - 1 through 11 (of 11 total)
  • The topic ‘add html above calendar for a specific a category.’ is closed to new replies.