[英]Get Wordpress post image attachment source into custom XML template
I am trying to load the image attachment source into a custom XML file, however it comes up with a Missing Attachment error, as shown here 我想在图片附件源加载到一个自定义的XML文件,但是它缺少的附件错误出现,如图所示这里
Here is the code I am using: 这是我正在使用的代码:
<?php
/**
* Template Name: Custom XML Template - Csutom Feed
*/
$postCount = 5; // The number of posts to show in the feed
$posts = query_posts('showposts=' . $postCount);
header('Content-Type: '.feed_content_type('rss-http').'; charset='.get_option('blog_charset'), true);
echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>';
?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
<?php do_action('rss2_ns'); ?>>
<channel>
<title><?php bloginfo_rss('name'); ?> - Feed</title>
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
<link><?php bloginfo_rss('url') ?></link>
<description><?php bloginfo_rss('description') ?></description>
<lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
<language><?php echo get_option('rss_language'); ?></language>
<sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod>
<sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', '1' ); ?></sy:updateFrequency>
<?php do_action('rss2_head'); ?>
<?php while(have_posts()) : the_post(); ?>
<item>
<title><?php the_title_rss(); ?></title>
<link><?php the_permalink_rss(); ?></link>
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
<dc:creator><?php the_author(); ?></dc:creator>
<guid isPermaLink="false"><?php the_guid(); ?></guid>
<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
//------------LINE IN QUESTION--------------//
<image><?php the_attachment_link() ?></image>
<content><?php the_content_rss() ?></content>
<?php rss_enclosure(); ?>
<?php do_action('rss2_item'); ?>
</item>
<?php endwhile; ?>
</channel>
</rss>
Any ideas on where I am going wrong? 关于我要去哪里的任何想法?
We need to provide the attachment ID for the_attachment_link($attach_id)
, so this is not the function you're looking for. 我们需要提供
the_attachment_link($attach_id)
的附件ID ,因此这不是您要查找的功能。 To get the Featured Image of a post we use the_post_thumbnail()
. 要获取帖子的精选图片 ,请使用
the_post_thumbnail()
。
If the post doesn't have a FI, we use get_childen()
to get any image attached to a specific post and select one from there. 如果帖子没有FI,我们可以使用
get_childen()
获取附加到特定帖子的任何图像,然后从中选择一个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.