Reputation: 299
I am using shortcode to display blogroll on my main static page.
It displays title and up to N characters of the excerpt.
However, I have no idea how can I get post date to show up next to the title.
Is get_the_date function the correct one to use? How to implement it? http://codex.wordpress.org/Function_Reference/get_the_date
<?php
function getblogposts($atts, $content = null) {
extract(shortcode_atts(array(
'posts' => 1,
), $atts));
$return_string = '<h3>'.$content.'</h3>';
$return_string .= '<ul>';
query_posts(array('orderby' => 'date', 'order' => 'DESC' , 'showposts' => $posts));
if (have_posts()) :
while (have_posts()) : the_post();
$return_string .= '<li><a href="'.get_permalink().'">'.get_the_title().'</a>';
$return_string .= '<div class="excerpt">' . get_the_excerpt() . '</div></li>';
endwhile;
endif;
$return_string .= '</ul>';
wp_reset_query();
return $return_string;
}
function new_excerpt_more( $more ) {
return ' <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">Continue reading</a>';
}
add_filter( 'excerpt_more', 'new_excerpt_more' );
function custom_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 100 );
?>
Upvotes: 1
Views: 12744
Reputation: 5520
Yes. You could use get_the_date()
. The important thing is use it within the loop (between while(have_posts()
and endwhile;
.
You could use
echo get_the_date();
OR
the_date(); //without echo
Another thing that you really really should consider is to NOT use query_posts(). Why? It's not easy to answer (it basically could mess up other queries), but take a look at https://wordpress.stackexchange.com/questions/50761/when-to-use-wp-query-query-posts-and-pre-get-posts.
Upvotes: 4