在自定义RSS提要中显示作者

时间:2017-03-31 作者:Sdesign

我正在使用yoast的代码https://yoast.com/tag/rss/ 并对其进行了一些修改,以显示其正在执行的功能图像。我现在想知道如何向作者展示

我尝试添加int,但不起作用。我错过了什么来展示这个?

<?php
/*
Template Name: Custom Feed
*/

$numposts = 10;

function acustom_rss_date( $timestamp = null ) {
$timestamp = ($timestamp==null) ? time() : $timestamp;
echo date(DATE_RSS, $timestamp);
}

function acustom_rss_text_limit($string, $length, $replacer = \'...\') { 
$string = strip_tags($string);
if(strlen($string) > $length) 
return (preg_match(\'/^(.*)\\W.*$/\', substr($string, 0, $length+1), $matches)  ? $matches[1] : substr($string, 0, $length)) . $replacer;   
return $string; 
}

$posts = query_posts(\'showposts=\'.$numposts);

$lastpost = $numposts - 1;

header("Content-Type: application/rss+xml; charset=UTF-8");
echo \'<?xml version="1.0"?>\';
?><rss version="2.0" xmlns:media="http://search.yahoo.com/mrss">
<channel>
<title>Test E-mail Update</title>
<link>http://www.test.com/</link>
<description>The latest posts from test.com</description>
<language>en-us</language>
<pubDate><?php acustom_rss_date( strtotime($ps[$lastpost]->post_date_gmt) ); ?></pubDate>
<lastBuildDate><?php acustom_rss_date( strtotime($ps[$lastpost]- >post_date_gmt) ); ?></lastBuildDate>
<?php foreach ($posts as $post) { ?>
<item>
<title><?php echo get_the_title($post->ID); ?></title>
<link><?php echo get_permalink($post->ID); ?></link>
 <?php if(get_the_post_thumbnail()): ?>
<media:content url="<?php $image =   wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), \'thumbnail\'); echo  $image[0]; ?>" medium="image" />
<?php endif; ?>

<description>


<?php echo \'<![CDATA[\'.acustom_rss_text_limit($post->post_content, 500).\'<br/><br/><a href="\'.get_permalink($post->ID).\'"> Continue Reading. </a>\'.\']]>\';  ?>



</description>


<dc:creator><?php echo get_the_author_meta( \'display_name\', $post->post_author ); ?>

<pubDate><?php acustom_rss_date( strtotime($post->post_date_gmt) ); ?></pubDate>
<guid><?php echo get_permalink($post->ID); ?></guid>
</item>
<?php } ?>
</channel>
</rss>

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

试试看:

<?php echo get_the_author_meta( \'display_name\', $post->post_author ); ?>
您可以使用the_author wordpress标准循环中的函数,而不是foreach。要设置全局作者信息,应使用the_post 作用但在foreach中,您可以使用get_the_author_meta 而不是the_author 传递作者id$post->post_author.