【发布时间】:2014-11-16 12:27:38
【问题描述】:
想知道是否有人可以提供帮助;对我来说似乎有点复杂;
基本上我已经在我的wordpress网站中添加了这个功能,所以人们可以更改作者的名字;
add_filter( 'the_author', 'guest_author_name' );
add_filter( 'get_the_author_display_name', 'guest_author_name' );
function guest_author_name( $name ) {
global $post;
$author = get_post_meta( $post->ID, 'author_name', true );
if ( $author )
$name = $author;
return $name;
}
但是现在我想添加一些代码来显示当前帖子作者的帖子列表,但它返回的是原始作者而不是顶部函数将其更改为的作者;下面是我用来做这个的函数,这可以改变吗?
function get_related_author_posts() {
global $authordata, $post;
$authors_posts = get_posts( array( 'author' => $author_name->ID, 'post__not_in' => array( $post->ID ), 'posts_per_page' => 3 ) );
$output = '<div class="morepost"><h3>More posts from this author</h3>';
foreach ( $authors_posts as $authors_post ) {
$output .= '<li><a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a></li>';
}
$output .= '</ul></div>';
return $output;
}
然后这个;
<?php echo get_related_author_posts(); ?>
知道它有点复杂,如果有人能帮忙就太好了
D
这是我到目前为止想出的,但有人可以告诉我这段代码哪里出了问题
<?php $author = get_post_meta( $post->ID, 'author_name', true ); $args
= array(
'meta_query' => array (
array(
'key' => 'author_name',
'value' => $author
)
), 'post__not_in' => array( $post->ID ), 'posts_per_page' => 3 ); ?> <?php if ( $wp_query->have_posts() ) : ?> <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?> DO something
<?php endwhile; ?> NOT POSTS <?php endif; ?>
【问题讨论】: