WordPress.org

Ready to get started?Download WordPress

Forums

WP Calendar
[resolved] php problems for alternate text if there are no events (6 posts)

  1. daDirtyD
    Member
    Posted 3 years ago #

    Hi there,

    On my static 'Home'-page I'm showing a list of the next upcomimg 3 events in one category.

    <?php fse_print_events(
    	array( 'number'   => 3,
    	'categories' => '5'
    	)
    	);?>

    all fine so far.

    But now i want to have a alternative text when there are no events in the list.

    I tried this:

    <?php
    if( is_array(fse_get_events(array('categories' => '4'))));
    {
    fse_print_events( array( 'number' => 3,'categories' => '4'));
    }
    else {
    echo "sorry no events";
    }
    ?>

    It doesn't work and I'm little stuck here.
    You got help for me?

    Thanks in advance.

    http://wordpress.org/extend/plugins/wp-calendar/

  2. faebu
    Member
    Plugin Author

    Posted 3 years ago #

    fse_get_events allways returns an array! you have to check, if it's empty:

    <?php
    if( count(fse_get_events(array('categories' => '4'))) > 0);
    {
    fse_print_events( array( 'number' => 3,'categories' => '4'));
    }
    else {
    echo "sorry no events";
    }
    ?>
  3. daDirtyD
    Member
    Posted 3 years ago #

    Thanks faebu.
    unfortunately I get an error on the " else "

    Parse error: syntax error, unexpected T_ELSE

    Can't see whats wrong here.

    your snippet is inside the:

    '
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    ...
    <?php
    if( count(fse_get_events(array('categories' => '4'))) > 0);
    {
    fse_print_events( array( 'number' => 3,'categories' => '4'));
    }
    else {
    echo "sorry no events";
    }
    ?>
    ...
    <?php endwhile; ?>
    '

  4. faebu
    Member
    Plugin Author

    Posted 3 years ago #

    problem is the ; in the first row. try this code again

    <?php
    if(count(fse_get_events(array('categories' => '4'))) > 0)
    {
      fse_print_events( array( 'number' => 3,'categories' => '4'));
    } else {
      echo "sorry no events";
    }
    ?>
  5. daDirtyD
    Member
    Posted 3 years ago #

    Thanks a lot.
    It's working perfectly

  6. faebu
    Member
    Plugin Author

    Posted 3 years ago #

    nice to hear!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic