Support » Fixing WordPress » Event Date as Custom field

  • Resolved jdest326

    (@jdest326)


    Hi-

    I have special events listed in a category called “events”

    I am displaying only that category.

    How can I add a custom field for event date? And additionally, how do I display the date as “Nov” in one field and “23” the date number in another for styling?

Viewing 10 replies - 1 through 10 (of 10 total)
  • http://codex.wordpress.org/Using_Custom_Fields

    Store the date in the format yyyy-mm-dd in the custom field. Then once it’s been retrieved, use PHP to break the date string down into year, month and day for display.

    Thread Starter jdest326

    (@jdest326)

    How do I do that? I don’t know enough about PHP to break apart the string.

    <?php
    //for this post, get custom field "event_date" which should be in yyyy-mm-dd format and display as to month, day
    //2011-02-22 will display as February 22
    $event_date = get_post_meta($post->ID, 'event_date', true);
    $event_date = '2011-02-22';
    if ($event_date) {
    echo 'The event date is '. date('F j', strtotime($event_date));
    }
    ?>

    For the date(‘F j’… options see Formatting_Date_and_Time.

    Thread Starter jdest326

    (@jdest326)

    Great! But how do I add css to each string element?

    echo '<span class="yourspanclass here">bThe event date is '. date('F j', strtotime($event_date)) . '</span>';

    Related:
    CSS

    Thread Starter jdest326

    (@jdest326)

    Yeah, but wont the entire date be styled the same? I want to style the ‘F’ differently than the ‘j’

    You’d have to use two instances of date.

    date('F', strtotime($event_date))
    date('j', strtotime($event_date))

    Thread Starter jdest326

    (@jdest326)

    ohhh, ok thank you!

    I had a similar issue and i was able to figure it out thanks to this post! I really appreciate it!

    I have a similar problem – I want the widget calendar to display a post on a given date not on the date that the post was created.

    Any clues?
    -rich

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Event Date as Custom field’ is closed to new replies.