函数打印POST元数据不起作用

时间:2012-09-23 作者:grappler

我从2011年的主题中修改了这段代码,但它不起作用,我也不明白为什么。

if ( ! function_exists( \'theme_post_meta_data\' ) ) :
/**
 * This function prints post meta data.
 *
 * Adopted from Twenty Eleven
 */
function theme_post_meta_data() {
    printf( __( \'%1$sPosted on %2$s by %3$s\', \'theme\' ),
        esc_attr( \'<span class="posted">\'),
        sprintf( \'</span><a href="%1$s" title="%2$s" rel="bookmark"><span class="timestamp" "%3$s">%4$s</span></a><span class="byline">\',           
            esc_url( get_permalink() ),
            esc_attr( get_the_time() ),
            esc_attr( get_the_date( \'c\' ) ),
            esc_attr( get_the_date() ),
        ),
        esc_attr( sprintf(\'<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span></span>\' ,
            esc_url( get_author_posts_url( get_the_author_meta( \'ID\' ) ) ),
            esc_attr( sprintf( __( \'View all posts by %s\', \'theme\' ), get_the_author() ) ),
            get_the_author() , ),
        ),
    );
}
endif;
我得到一个HTTP错误500。

谢谢

2 个回复
最合适的回答,由SO网友:grappler 整理而成

我用这个代码解决了这个问题。

if ( ! function_exists( \'theme_post_meta_data\' ) ) :
/**
* This function prints post meta data.
*/
function theme_post_meta_data() {
printf( __( \'<span class="%1$s">Posted on </span>%2$s<span class="%3$s"> by </span>%4$s\', \'theme\' ),
\'meta-prep meta-prep-author posted\', 
sprintf( \'<a href="%1$s" title="%2$s" rel="bookmark"><span class="timestamp">%3$s</span></a>\',
    get_permalink(),
    esc_attr( get_the_time() ),
    get_the_date()
),
\'byline\',
sprintf( \'<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>\',
    get_author_posts_url( get_the_author_meta( \'ID\' ) ),
    sprintf( esc_attr__( \'View all posts by %s\', \'theme\' ), get_the_author() ),
    get_the_author()
    )
);
}
endif;

SO网友:Jamie

您将函数拼写错误。您有thme\\u post\\u meta\\u data(),而不是theme\\u post\\u meta\\u data。因此,您的函数不存在

结束

相关推荐