WordPress.org

Ready to get started?Download WordPress

Forums

put the_date in ul with format in li's (7 posts)

  1. lokjah
    Member
    Posted 9 years ago #

    hi there, i'm trying to tweak the_date and wrap it in a ul but my script doesnt seem to work

    <?php
    //parse date to list
    $mydate = the_date("M.d.y");
    print("<ul class=\"datelist\">n");
    $tok = strtok($mydate, ".");

    $the_dateloopnum = 1;
    while ($tok) {

    if($the_dateloopnum==1){
    $dateclass = "month";
    }
    if($the_dateloopnum==2){
    $dateclass = "day";
    }
    if($the_dateloopnum==3){
    $dateclass = "year";
    }

    print("<li class=\"$dateclass\">$tok</li>n");
    //below closes date token
    $tok = strtok(".");
    $the_dateloopnum++;
    }
    print("</ul>n");
    ?>

    it outputs the date outside of the ul and doesnt print the li's either.... like:

    Apr.25.05<ul class="datelist">
    </ul>

    anyone see whats wrong?

    thanks alot....

  2. Kafkaesqui

    Posted 9 years ago #

    $mydate = the_date("M.d.y", "", "", FALSE);

    See the info on the echo parameter for the_date():

    http://codex.wordpress.org/Template_Tags/the_date#Parameters

  3. lokjah
    Member
    Posted 9 years ago #

    excellent kafkaesqui

    I was reading that page actually all nite and forgot to put that piece into the script...

    thanks a ton!

  4. lokjah
    Member
    Posted 9 years ago #

    rats... thought it was sussed...

    for some reason my script above doesnt work like the_date
    as it should- (only showing the date on the first post when there are multiple posts on one day)...

    on days with more than one entry my script writes an empty
    <ul class="datelist">
    </ul>

    which throws off the validation of my site.....

    is there something that needs to be added in my script so that it behaves as the_date by default on multiple posts?

  5. lokjah
    Member
    Posted 9 years ago #

    still havent been able to figure this one out, help much appreciated :)

  6. Kafkaesqui

    Posted 9 years ago #

    Again I direct you to the Codex page, this time the description section:

    http://codex.wordpress.org/Template_Tags/the_date#Description

    "When there are multiple posts published on the same date on a page, the tag will only display the date the first time it's called."

    So try this:

    $mydate = get_the_time("M.d.y");

    http://codex.wordpress.org/Template_Tags/get_the_time

  7. lokjah
    Member
    Posted 9 years ago #

    thanks kafka, i'm still a noob at php so it takes me a bit to get a hold of what to do,

    i know about the tag only the first time its called, thats what i was expecting my script above to do, but it wasnt doing that.

    this you posted works, it actually puts a date on every entry which is fine, I just wondered why the original the_date in my script wasnt working....

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags