WordPress.org

Ready to get started?Download WordPress

Forums

Get_the_title returning ID only? (7 posts)

  1. dav1dr0well2
    Member
    Posted 2 years ago #

    Noobie question I suppose. I've got a custom page template (using Thesis) that is trying to grab recent posts:

    foreach($lastposts as $post) : setup_postdata($post);
        $post_id = $post->ID;
        $post_date = get_the_date($post_id);
        $post_title = get_the_title($post_id);
        $post_url = get_permalink($post_id);
        $post_excerpt = get_n_char_excerpt($GLOBALS['blogright_excerpt_length'], $post->post_content);
        ?>
                <li><span class="storydate"><?php echo $post_date ?></span><span class="storytitle"><a title="<?php echo $post_title ?>" rel="nofollow" href="<?php echo $post_url ?>"><?php echo $post_title ?></a></span></li>
        <?php
        if ($current_article_num < $article_count)
            $current_article_num++ ;
    endforeach;

    The "$post_title = get_the_title($post_id);" is returning a number (a post ID?). I want to format the date as "Month Day, Year".

    I tried using "post_date = get_the_date($post_id);" and it returns a date with *everything* (e.g. 2011-09-22 15:02:15).

    Any ideas on how I can get what I want: "Day Date, Year" format?

    Thanks in advance,

    David

  2. dav1dr0well2
    Member
    Posted 2 years ago #

    Sorry... I contradicted myself at end of post... My goal for date of post format is Month Day, Year (e.g. "September 29, 2011")...

  3. Oleg Dudkin
    Member
    Posted 2 years ago #

    try
    get_the_date(); //without parameters
    and
    get_the_date('F j, Y');

  4. dav1dr0well2
    Member
    Posted 2 years ago #

    Oleg:

    THANK YOU...

  5. dav1dr0well2
    Member
    Posted 2 years ago #

    Formatting looks great Oleg. Now I've discovered one other nagging problem... all of my posts have the same date...

    I went digging around the WP codex and found info on the_date where it says:

    SPECIAL NOTE: When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use the Template Tag the_time() or get_the_date() (since 3.0) with a date-specific format string.

    But I'm using get_the_date... but I'm still only getting a single date back...

    Thanks!

  6. dav1dr0well2
    Member
    Posted 2 years ago #

    After doing some testing I've discovered that the date that's being returned is the date I created the static page where I'm using the code (if that helps)...

    David

  7. Oleg Dudkin
    Member
    Posted 2 years ago #

    hmm..
    Try this
    date('F j, Y', strtotime( $post->post_date ) )

Topic Closed

This topic has been closed to new replies.

About this Topic