在WordPress Feeds 里加入特色图片

编辑你的Feed模板基本与编辑你的主题模板一样。然而,Feed模板不集成到WordPress主题系统;如果你希望你的订阅的不同版本,你需要创建额外的模板。

自定义Feed模板

feed 模板位于/wp-includes/feed-{type}.php文件, 包括rdf格式、rss、rss和atom。他们是由feed重写规则使用一系列的行动中定义wp-includes /功能。使用 add_action wp-includes / default-filters.php php和附加。

为了覆盖需要清楚自己的模板默认行为叫load_template然后采取适当的步骤。使用一个模板为默认的一个示例rss2 feed 位于模板目录为自定义文章类型:

remove_all_actions( 'do_feed_rss2' );
add_action( 'do_feed_rss2', 'itc_feed_rss2', 10, 1 );

function itc_feed_rss2( $for_comments ) {
	$rss_template = get_template_directory() . '/feeds/itc_feed_rss2.php';
	if(get_query_var( 'post_type' ) == 'post' && file_exists( $rss_template ) )
		load_template( $rss_template );
	else
		do_feed_rss2( $for_comments ); // Call default function
}

然后在你的主题里建立一个feeds 目录,新建一个rss2 文件叫: itc_feed_rss2.php

复制 /wp-includes/feed-rss2.php 里的代码到 itc_feed_rss2.php

然后在<item> 里面加一段代码来插入特色图片,例如

	<item>
		<title><?php the_title_rss() ?></title>
		<link><?php the_permalink_rss() ?></link>
		<?php 
		if ( has_post_thumbnail() ) {
			$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'full' ); 
			echo '<image>' . $large_image_url[0] . '</image>'; 
		}
		?> 
		<comments><?php comments_link_feed(); ?></comments>

 

2,277 thoughts on “在WordPress Feeds 里加入特色图片

  1. sa

    I appreciate you sharing this blog article. Much obliged.

  2. ankara nakliyat firması

    Ankara Nakliyat Firması olarak biliyoruzki Evden eve nakliyat zor ve profesyonellik gerektiren bir iştir. Yetiştirilmiş eleman kadrosu, kapalı kasa araçlar, sigortalı taşımacılık, özenle seçilmiş paketleme malzemeleri, ücretsiz expertiz hizmeti, eşyalarınızın demontaj ve montaj işlemleri, tam zamanlı çalışma ve müşteri, memnuniyetini en ön planda tutmak gibi bir çok birikime sahibiz. Biliyoruz ki işinizi en güzel şekilde yerine getirecek firma biziz. Uzman kadromuz ve egitimini almış personellerimiz ile evden eve nakliyat, büro – ofis taşımacılığı, kurumsal nakliyat hizmeti sunmaktayız.

  3. sa

    Thank you for your blog article.Really looking forward to read more. Will read on…

  4. sa

    Thank you for your blog article.Really looking forward to read more. Will read on…

  5. Sling TV

    Ahaa, its nice discussion on the topic of this paragraph at this place at this website, I have read all that, so now me also commenting
    at this place.

  6. lash extensions boston

    “Great web site. Lots of helpful info here. I’m sending it to several pals ans additionally sharing in delicious. And naturally, thank you on your effort!”

  7. sa

    Thank you for your blog article.Really looking forward to read more. Will read on…

  8. What Equipment is Needed for Sling TV

    Great article! That is the type of information that should be shared across the web.
    Disgrace on the search engines for not positioning
    this publish higher! Come on over and talk over with my web site .
    Thank you =)

  9. Quest Bars

    Hi! I just wanted to ask if you ever have any trouble with hackers?
    My last blog (wordpress) was hacked and I ended up losing many months of hard work due
    to no back up. Do you have any methods to stop hackers?

  10. Elroy Papadopoulos

    BecauseSinceAsFor the reason that the admin of this websiteweb sitesiteweb page is working, no doubthesitationuncertaintyquestion very soonrapidlyquicklyshortly it will be famouswell-knownrenowned, due to its qualityfeature contents.

Comments are closed.