What theme are you using? Where did you download it from?
esmi,
It’s an in-house buit theme, I think it was based on 2010, but there’s been a lot of hacking on it since. It’s part of a block for generating an in-line list of posts of a specific category via a shortcode.
Here’s the larger piece of code.. it works fine, I just need to figure out how to formate the date…
if($atts['displaydate'] == 'true')
{
$returnHtml .= '<span class="date">'.$post->post_date.'</span>';
}
Why can’t you use something like:
if($atts['displaydate'] == 'true') $returnHtml .= sprintf( '<span class="date">%1$s</span>>', esc_html( get_the_date() ) );
Hmm.. that is pulling the posting date of the page it’s on, not of the post being referenced.
Here’s the entire code block so you can see what is going on overall.
function inline_category_list_function($atts)
{
$returnHtml = "";
$args = array(
'category_name' => $atts['category'],
'posts_per_page' => '5'
);
$posts_arr = get_posts($args);
if(!empty($posts_arr))
{
$returnHtml = '<div class="'.$atts['style'].'">'.
'<ul>';
foreach ($posts_arr as $post) {
$permalink = get_permalink( $post->ID );
$returnHtml .= '<li><a href="'.$permalink.'">'.$post->post_title.'</a>';
if($atts['displaydate'] == 'true')
{
$returnHtml .= '<span class="date">'.$post->post_date.'</span>';
}
if($atts['displayexcerpt'] == 'true')
{
$returnHtml .= '<p>'.$post->post_excerpt.'</p>';
}
$returnHtml .= '</li>';
}
$returnHtml .= '</ul></div>';
}
return $returnHtml;
}
add_shortcode('inlineCategoryList','inline_category_list_function');
?>
What this is doing is pulling the list of posts in a certain category, and displaying their post date and abstract if flagged in the shortcode.
I wanted this so I could display a list of posts inline in the contents of a page, without it having to be hardcoded at the top or bottom of page, and without requiring yet another custom page template.
that is pulling the posting date of the page it’s on, not of the post being referenced.
In my defence, I only had a code snippet to go on. 🙂 If you added setup_postdata( $post ); immediately after your foreach, you would be able to access all of the post data far more easily. See http://codex.wordpress.org/Template_Tags/get_posts#Access_all_post_data
🙂 I was try to not post too much code.. 😀
Thanks, I’ll do some reading there and see if it makes sense to me (and if not, hope the dev will be back from sick leave soon.. 😛