【问题标题】:WP Shortcode to show post date and categoriesWP简码显示发布日期和类别
【发布时间】:2016-02-23 21:40:25
【问题描述】:

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

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

【问题讨论】:

  • get_the_date('echo $date_style;', FALSE); 那是你的问题,提供$date_style 是一个定义的变量,正确的方法是get_the_date($date_style, FALSE);

标签: php wordpress shortcode


【解决方案1】:

你的标记有点错误,你缺少一个结束标签。

正确的格式应该是:

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");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-29
    • 1970-01-01
    • 1970-01-01
    • 2017-10-18
    • 1970-01-01
    相关资源
    最近更新 更多