WordPress.org

Ready to get started?Download WordPress

Forums

Latest Custom Post Type Updates
[resolved] Add date? (7 posts)

  1. hahvensa
    Member
    Posted 2 years ago #

    Is it possible to add date to the latest custom post types widget. Now it only shows the post title if I'm correct.

    I guess it should be added somewhere here in the index.php

    // Get the posts!
            $posts = get_posts($params);
            // Print 'em out!
            if($posts)
                foreach($posts as $post)
                    echo '<li><a href="'.get_permalink($post->ID).'" title="'.$post->post_title.'">'.$post->post_title.'</a></li>';
            else {
                if($instance['empty_display'])
                echo '<li>'.$instance['empty_display'].'</li>';
            }
            // Always remember your closing tags!
            echo '</ul>'.$after_widget;
        }

    http://wordpress.org/extend/plugins/latest-custom-post-type-updates/

  2. Eric McNiece
    Member
    Posted 2 years ago #

    A modified version might look like so:

    // Get the posts!
            $posts = get_posts($params);
            // Print 'em out!
            if($posts)
                foreach($posts as $post)
                    echo '<li>
                        <a href="'.get_permalink($post->ID).'" title="'.$post->post_title.'">'.$post->post_title.'</a><br />
                        <span class="date">'.get_the_date().'</span>
                    </li>';
            else {
                if($instance['empty_display'])
                echo '<li>'.$instance['empty_display'].'</li>';
            }
            // Always remember your closing tags!
            echo '</ul>'.$after_widget;
        }

    Alternatively, you might swap get_the_date() with get_the_modified_date() if you want the most recent edit date instead of the post publish date.

  3. hahvensa
    Member
    Posted 2 years ago #

    OK, great! Just what I was looking for.

  4. hahvensa
    Member
    Posted 2 years ago #

    Hi!
    Another question. I was wondering if it's possible to display only today's posts instead of the latest post? This plugin seems nice and simple and I thought maybe it's easilly modified for that purpose :)

  5. Eric McNiece
    Member
    Posted 2 years ago #

    It's possible, but maybe not with this plugin. LCPTU uses the get_posts() command, and it looks like you can only do date queries with query_posts() (though I have not tested this).

    Try searching for "get today's posts" and you'll see what I mean!

  6. hahvensa
    Member
    Posted 2 years ago #

    Thanks for your answer! Yeah that seems to be the problem. Maybe I find a way to do it with Query Posts plugin. But anyways, you have a great plugin! I just have a complex need.

  7. David Wood
    Member
    Plugin Author

    Posted 1 year ago #

    The plugin has been updated and now uses the WP_Query class to query posts. As such the ability to show the published date or the modified date in the widget now exists.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic