全部在单个中。php文件位于Genesis子主题中。
我有一个echo
属于divs
在这两者之间,我在anchors
我正在尝试通过variable
, 像这样:
function my_function() {
$author = get_the_author_meta( $post->post_author );
$author_link = get_author_posts_url($author);
$author_avatar = get_avatar_url(get_the_author_meta( $post->post_author ));
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), \'full\' );
//..
echo \'<div>
// ..
<div class="">
By <a href="\'.$author_link.\'">Author</a>
</div>\'
</div>
}
genesis();
我尝试过:
the_author_posts_url();
,
get_the_author_meta(\'user_url\');
,
get_author_posts_url();
,
get_author_posts_url( get_the_author_meta( \'ID\' ) );
每次链接为空或生成
http://localhost/author
不输出特定作者。
单件的完整代码。php在这里:
函数custom\\u entry\\u content(){$author=get\\u the\\u author\\u meta($post->post\\u author);
$author_link = get_author_posts_url($author);
$author_avatar = get_avatar_url(get_the_author_meta( $post->post_author ));
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), \'full\' );
echo \'<div style="margin-bottom: 50px;position: relative; text-align:center; width:100%;background-image: url(\'.$featured_image[0].\');
height: 502px; background-size: cover;
background-repeat: no-repeat;">
<div class="post-title-box">
<h1 class="the-title">
\'. get_the_title(). \'</h1>
</div>
<div class="post-auth-info">
<div class="vertical-middle" style="display:inline-block">
<div class="">
By <a href="\'.$author_link.\'">Author</a>
</div>
<time class="mk-publish-date" datetime="2017-11-01">
<a href="#">Published \' . time_elapsed_string(get_the_date()). \'</a>
</time>
</div>
<div style="display:inline-block">
<a href="\'.$author_link.\'">
<div>
<img alt="" src="\'.$author_avatar.\'" class="img-circle avatar avatar-55 " height="55" width="55" style="height:55px;width:55px">
</div>
</a>
</div>
</div>
</div>\';
}
// Removes Published by and time data from before the post content area
remove_action( \'genesis_entry_header\', \'genesis_post_info\', 12);
add_filter( \'genesis_attr_site-inner\', \'remove_top_padding\');
function remove_top_padding( $attributes ) {
$attributes[\'class\'] = \'container box nopadding\';
return $attributes;
}
// Adds left padding to content
add_filter( \'genesis_attr_content\', \'padding_left\');
function padding_left( $attributes ) {
if ( \'full-width-content\' === genesis_site_layout() )
$attributes[\'class\'] = \'\';
else
$attributes[\'class\'] = \'col-md-8 single-post-entry\';
return $attributes;
}
genesis();
非常感谢!
最合适的回答,由SO网友:Scott Agirs 整理而成
感谢所有帮助过我的人,看来主要问题是我没有global $post
在函数内声明。
此外,在调整author\\u id声明后,一切都开始工作,下面是最终代码:
function single_post_entry() {
global $post;
$author_id = $post->post_author;
$author_link = get_author_posts_url( $author_id );
$author_avatar = get_avatar_url( $author_id );
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), \'full\' );
// ..
echo \'<div>
By <a href="\' . esc_url( $author_link ) . \'">Author</a>
</div>\';
}