Pages

Thursday, October 11, 2012

How to do Events as calendar in post/page wordpress?

To make an event Need to follow below steps..

1. Install plugin from http://www.harriswebsolutions.co.uk/event-organiser/.
2. To display events as a calendar use the below short code..
   [eo_fullcalendar]

3. If there is a requirement to display event as content go to below code...
<?php
                       
                        //eo_get_events($args);
                        $events = eo_get_events(array('numberposts'=>3,'tax_query'=>array( array(
                          'taxonomy'=>'event-category',
                          'operator' => 'NOT IN',
                          'field'=>'slug',
                          'terms'=>array('comedy')
                          ))));
                            if($events):
                                      $return= '';
                           
                                      foreach ($events as $event):
                                           //Check if all day, set format accordingly
                                           if( eo_is_all_day($event->ID) ){
                                                $format = get_option('date_format');
                           
                                           }else{
                                                $format = get_option('date_format').' '.get_option('time_format');
                                           }
                                           $return .= snippet($event->post_content, 400)."<br>";
                                           $return.='<a class="moretag" href="'. get_permalink($event->ID) . '"> More...</a><br>';
                                           $return.="<span style='color:#FE8E1E'>".eo_format_date($event->StartDate.' '.$event->StartTime, $format)."</span>";                                          
                                      endforeach;
                           
                                     
                           
                                      echo $return;
                             endif;
                         ?>
we can copy this where ever want to display. And add below code in functions.php file, because it will limit the content which is going to be displayed...
function snippet($text,$length=300,$tail="...") {
    $text = trim($text);
    $txtl = strlen($text);
    if($txtl > $length) {
        for($i=1;$text[$length-$i]!=" ";$i++) {
            if($i == $length) {
                return substr($text,0,$length) . $tail;
            }
        }
        $text = substr($text,0,$length-$i+1) . $tail;
    }
    return $text;
}

2 comments:

  1. blog great for me, its so beautiful tips given to me,
    Wordpress Development

    ReplyDelete
    Replies
    1. Hi James,

      Thank you for your reply, it is given me boost to do my research more and helps you more.

      Delete