WP Shortcode显示发布日期和类别

时间:2016-02-23 21:40:26

标签: php wordpress shortcode

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

以下是示例页面的链接: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");

1 个答案:

答案 0 :(得分:0)

你的标记有点不对,你错过了结束标记。

正确的格式应为:

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");
相关问题