Home › Forums › Calendar Products › Events Calendar PRO › Help Adding Category To List View With Custom Anchor Text
- This topic has 8 replies, 3 voices, and was last updated 9 years, 5 months ago by
Shaun.
-
AuthorPosts
-
November 17, 2016 at 4:03 am #1193767
Shaun
ParticipantHi,
A few months ago Cliff very kindly helped me to add a link from the Calendar ‘Tooltip’ to the events category page but with custom anchor text. In my case ‘More Info’ so I could style it as a button.
He did it by writing this snippet:
<?php // Adapted from https://theeventscalendar.com/support/forums/topic/help-adding-category-to-tooltip-but-with/#post-1079625 // Demo: http://cl.ly/1p1V0n3o3q3s $day = tribe_events_get_current_month_day(); $event_id = "{$post->ID}-{$day['daynum']}"; $link = tribe_get_event_link( $post ); $title = get_the_title( $post ); $additional_data = array(); $category_ids = tribe_get_event_cat_ids( $event_id ); $more_info_first_cat = ''; if ( ! empty( $category_ids ) && is_array( $category_ids ) ) { if ( null != $category_ids[0] ) { $more_info_first_cat = sprintf( '<a class="shaun-more-info-first-category" href="%s">More Info</a>', get_term_link( $category_ids[0] ) ); } } $additional_data['categories'] = $more_info_first_cat; ?>Which allowed me to then use
<p class="tribe-event-categories">[[=raw categories]]</p>In tooltip.php which generated a link to the category with ‘More Info’ as the anchor text. examples can be seen here: https://thorntonandlowe.com/training/month/
I now need to do with same with the events lists on location view. I.e I’d like a ‘More Info’ button next to the price and ‘Book Now’ button here: https://thorntonandlowe.com/venue/london/ that links to the category.
I’m sure the code that Cliff wrote is already doing most of the hard work but I just need some help figuring how to add the data to the template file. In this case single-event.php as it isn’t a javascript template like tooltip.php is.
Essentially what I’m asking is how to I take the contents of Cliff’s code above but output as PHP rather than [[=raw categories]].
Thanks in advance for your help.
November 18, 2016 at 6:11 am #1194414Nico
MemberHi there Shaun,
Thanks for getting in touch with us! I’ll help you on this ๐
Before I craft the snippet I just want to know if you need this exclusively for ‘venue pages’ or for events lists in general (view list of calendar).
Please let me know about it and I’ll prepare a script for this,
Best,
NicoNovember 18, 2016 at 8:12 am #1194469Shaun
ParticipantHi Nico,
Thanks for your reply.
Just the venue pages will be fine thank you. We don’t use the list view of month/calendar anywhere.
Thanks for your help.
November 22, 2016 at 6:03 am #1195738Nico
MemberHey Shaun,
I just finished writing a code snippet for this, but I realized it won’t be the best way to achieve what you are looking for. I mean it will show the ‘More Info’ link but not in the place yo need it. I inspected the code of your list view and it seems to be customized already to add the ‘Book Now’ button. Do you know how that was added? Does this file exists in you theme folder: ‘theme-folder/tribe_events/list/single-event.php’?
Knowing this will help me place the more info button next to the ‘Book now’ one.
Please let me know about it,
Best,
NicoNovember 22, 2016 at 9:22 am #1195964Shaun
ParticipantHi Nico,
Thanks for your continued help.
The ‘Book Now’ button is just an anchor in list/single-event.php
<a href="<?php echo esc_url( tribe_get_event_link() ); ?>" class="tribe-events-read-more" rel="bookmark"><?php esc_html_e( 'Book Now', 'the-events-calendar' ) ?></a>I added it myself but not sure exactly how I came up with it. It’ll either have just been hacking an existing template or from searching these forums/online.
Hope that helps.
November 24, 2016 at 4:12 am #1196945Nico
MemberThanks for following up Shaun!
Just paste this code in ‘list/single-event.php’ as well:
More Info', get_term_link( $category_ids[0] ) );
}
}
?>
That should do the trick!
Please let me know if it works as intended,
Best,
NicoNovember 24, 2016 at 10:00 am #1197125Shaun
ParticipantHi Nico,
It’s perfect, thank you!
Well, after I’d worked out characters that had been changed to HTML entities anyway. The opening and closing < and > were obvious but it took me a while to spot the && in the middle. Once I did it works great.
I don’t have time to style it right now but will add a CSS class and style it the same as the Book Now button tomorrow.
Thanks again for your help.
November 25, 2016 at 6:12 am #1197337Nico
MemberStocked to hear this works for you Shaun! Also, great work spotting the ‘encoded’ chars in the code (I just updated my previous reply) ๐
Iโll go ahead and close out this thread, but if you need help with anything else please donโt hesitate to create a new one and we will be happy to assist you.
Have a great weekend,
Nico -
AuthorPosts
- The topic ‘Help Adding Category To List View With Custom Anchor Text’ is closed to new replies.
