项目作者: annason

项目描述 :
Custom class generating list of related events for Wordpress Tribe Events Calendar plugin
高级语言: PHP
项目地址: git://github.com/annason/TEC_custom_related_class.git
创建时间: 2018-12-03T20:58:29Z
项目社区:https://github.com/annason/TEC_custom_related_class

开源协议:

下载


Class for related events in Tribe Events Calendar

My custom class for generating list of related events for tribe_events custom post type.

How to use

First of all you need to create an instance of Gdzieciak_related_events class, providing at least the id of tribe_event for which you want to create a list of related events.

  1. $related = new Gdzieciak_related_events($event_id);

Class instance parameters

  1. new Gdzieciak_related_events($event_id, $number_of_related, $price_range_percents)

$event_id (int) - required / ID of main event (tribe_events post type)

$number_of_related (int) - optional / default: 3 / Number of related posts to show

$price_range_percents (array) - optional / default: [5,30] / Array with number that would be used as a percent for creating price range for comparison.
First one is percent for cost ranges (i.e. $10-25), thus by default comparison range would be created based on small +/- 5% differance. The second one is a percent for creating comparison range prices that are numbers. Any other type of price will be ignored.

Use show_related() method in place where you want to display your related events.

  1. echo $related->show_related();

Static methods

You can use static cost_int($cost) method to discard non-numerical values and return an array or an int,
generate_cost_range($cost, $range_percents_array) enables you to generate price range withouth creating an object from class, if you would need it for other purposes.

HTML structure

You can find structure ourput in show_related() method, as $html variable:

  1. $html = '
  2. <div class="realted-item data-case-related="'.$case.'" data-price-range="'.$data_range.'">
  3. <div class="post-image">
  4. <img alt=" '.get_the_title($id).'" src="
  5. '.get_the_post_thumbnail_url($id).' ">
  6. </div>
  7. <div class="post-title">
  8. <a href="'.get_permalink($id).'">'.get_the_title($id).'</a>
  9. </div>
  10. </div>';

You can change it as you like.

$case is a number of relation level case,

$data_range is a final price range for comparison, saved as data value for debugging purposes (it would be blank if event doesn’t have any price)

$id is a post id of related event; you can use it with standard wordpress functions.

Relation level cases

  1. // case 1: price & all tags & all cats
  2. /// case 2: price & any tag & any event cat
  3. //// case 3: price & all tags
  4. ///// case 4: price & any tag
  5. ////// case 5: price & all cats
  6. /////// case 6: price & any event cat
  7. //////// case 7: all tags & all cats
  8. ///////// case 8: any tag & any event cat
  9. ////////// posts are in the same series of recurring
  10. /////////// case 9: all tags
  11. //////////// case 10: any tag
  12. ///////////// case 11: all cats
  13. ////////////// case 12: any event cat

Example class usage

  1. <?php $related = new Gdzieciak_related_events(get_the_ID()); ?>
  2. <?php if($related->any_pre_related() > 2):?>
  3. <h1>Related</h1>
  4. <div id="related_events">
  5. <?php echo $related->show_related(); ?>
  6. </div>
  7. <?php endif; ?>