WP简码显示发布日期和类别


WP Shortcode to show post date and categories

我正在尝试创建一个短代码来显示帖子的日期和类别。我已经把它拼凑在一起,我可以让类别正确显示,但不能显示日期。我做错了什么?

以下是示例页面的链接:http://testdoug.com/phr-test/test-post-1/

//[categories-list]
function insertcats( $atts, $content = null ) {
    global $post;
    $categories = get_the_category_list( ', ', '', $post->ID );
    $my_date = get_the_date('echo $date_style;', FALSE);
    return '<div class="vcex-blog-entry-date"' . $my_date . '<div class="blog-category">' . $categories . '</div></div>';
}
add_shortcode("insertcats", "insertcats");

您的标记有点错误,并且缺少结束标记。

正确的格式应该是:

function insertcats( $atts, $content = null ) {
    global $post;
    $date_style = 'd M Y';//Your Format;
    $categories = get_the_category_list( ', ', '', $post->ID );
    $my_date = get_the_date($date_style, FALSE);
    return '<div class="vcex-blog-entry-date">' . $my_date . '<div class="blog-category">' . $categories . '</div></div>';
}
add_shortcode("insertcats", "insertcats");