WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Event Calendar Add default paragraph IF no event data found (3 posts)

  1. sigsol
    Member
    Posted 7 years ago #

    The logic of what I would like to achieve is IF no event found Then print (default para) else show normal schedule data at top of post.

    If Alex or Darrell is reading this, I know i asked on the mailing list, but as is it is an additional feature, I'm really asking if any PHP gurus out there can help me acheive something I'm being put under quite a bit of pressure for.

    I *think* the section that does this is as below

    /** Read the schedule table for the posts, and add an ec3_schedule array
    * to each post. */
    function ec3_filter_the_posts($posts)
    {
    if('array'!=gettype($posts) || 0==count($posts))
    return $posts;
    $post_ids=array();
    // Can't use foreach, because it gets *copies* (in PHP<5)
    for($i=0; $i<count($posts); $i++)
    {
    $post_ids[]=intval($posts[$i]->ID);
    $posts[$i]->ec3_schedule=array();
    }
    global $ec3,$wp_query,$wpdb;
    $schedule=$wpdb->get_results(
    "SELECT post_id,start,end,allday,rpt,IF(end>='$ec3->today',1,0) AS active
    FROM $ec3->schedule
    WHERE post_id IN (".implode(',',$post_ids).")
    ORDER BY start"
    );
    // Flip $post_ids so that it maps post ID to position in the $posts array.
    $post_ids=array_flip($post_ids);
    if($post_ids && $schedule)
    foreach($schedule as $s)
    {
    $i=$post_ids[$s->post_id];
    $posts[$i]->ec3_schedule[]=$s;
    }
    return $posts;
    }

    Any ideas how to mod it for what I need?
    Thanks Guys

  2. sigsol
    Member
    Posted 7 years ago #

    Had the wrong code fragment anyway.
    I need a check in this logical format IF no event data AND post is in event category then return "default paragraph"

    `/** Formats the schedule for the current post.
    * Returns the HTML fragment as a string. */
    function ec3_get_schedule(
    $format_single =EC3_DEFAULT_FORMAT_SINGLE,
    $format_range =EC3_DEFAULT_FORMAT_RANGE,
    $format_wrapper=EC3_DEFAULT_FORMAT_WRAPPER
    )
    {
    global $ec3,$post;
    // Should have been set by ec3_filter_the_posts()
    if(!$post || !$post->ec3_schedule)
    return '';//this is the section where the decision need to go
    $result='';
    $date_format=get_settings('date_format');
    $time_format=get_settings('time_format');
    $current=false;
    foreach($post->ec3_schedule as $s)
    {
    $date_start=mysql2date($date_format,$s->start);
    $date_end =mysql2date($date_format,$s->end);
    $time_start=mysql2date($time_format,$s->start);
    $time_end =mysql2date($time_format,$s->end);

    if($s->allday)
    {
    if($date_start!=$date_end)
    {
    $result.=sprintf($format_range,$date_start,$date_end,__('to','ec3'));
    }
    elseif($date_start!=$current)
    {
    $current=$date_start;
    $result.=sprintf($format_single,$date_start);
    }
    }
    else
    {
    if($date_start!=$date_end)
    {
    $current=$date_start;
    $result.=sprintf($format_range,
    "$date_start $time_start","$date_end $time_end",__('to','ec3'));
    }
    else
    {
    if($date_start!=$current)
    {
    $current=$date_start;
    $result.=sprintf($format_single,$date_start);
    }
    if($time_start==$time_end)
    $result.=sprintf($format_single,$time_start);
    else
    $result.=sprintf($format_range,$time_start,$time_end,__('to','ec3'));
    }
    }
    }
    return sprintf($format_wrapper,$result);
    }

    /** Echos the schedule for the current post. */
    function ec3_the_schedule(
    $format_single =EC3_DEFAULT_FORMAT_SINGLE,
    $format_range =EC3_DEFAULT_FORMAT_RANGE,
    $format_wrapper=EC3_DEFAULT_FORMAT_WRAPPER
    )
    {
    echo ec3_get_schedule($format_single,$format_range,$format_wrapper);
    }

    ?>

  3. sigsol
    Member
    Posted 7 years ago #

    Ok sorted it,
    First I had to put all events into their own category, and NOT the events category as required by event calendar, because some of these events do not have a programmed date.

    During the call for posts in the loop, i checked to see what category the post was in, and if in this category it printed "My text"

    <?php if (in_category(32)) { ?>
    My text
    <? } ?>

    And, during the call for the event calendar schedule, I added html elememts to the wrapper to print "Next Dates" above the date range

    define('EC3_DEFAULT_FORMAT_WRAPPER','<div class="nexdate"><h2>Next Date(s)</h2></div><table class="ec3_schedule">%s</table>');

    I'm sure that this could be done MUCH neater, but, it works for me.

Topic Closed

This topic has been closed to new replies.

About this Topic