Help Adding Category To List View With Custom Anchor Text

Home Forums Calendar Products Events Calendar PRO Help Adding Category To List View With Custom Anchor Text

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1193767
    Shaun
    Participant

    Hi,

    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.

    #1194414
    Nico
    Member

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

    #1194469
    Shaun
    Participant

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

    #1195738
    Nico
    Member

    Hey 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,
    Nico

    #1195964
    Shaun
    Participant

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

    #1196945
    Nico
    Member

    Thanks 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,
    Nico

    #1197125
    Shaun
    Participant

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

    #1197337
    Nico
    Member

    Stocked 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

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Help Adding Category To List View With Custom Anchor Text’ is closed to new replies.