feed-rss2.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * RSS2 Feed Template for displaying RSS2 Posts feed.
  4. *
  5. * @package WordPress
  6. */
  7. header( 'Content-Type: ' . feed_content_type( 'rss2' ) . '; charset=' . get_option( 'blog_charset' ), true );
  8. $more = 1;
  9. echo '<?xml version="1.0" encoding="' . get_option( 'blog_charset' ) . '"?' . '>';
  10. /**
  11. * Fires between the xml and rss tags in a feed.
  12. *
  13. * @since 4.0.0
  14. *
  15. * @param string $context Type of feed. Possible values include 'rss2', 'rss2-comments',
  16. * 'rdf', 'atom', and 'atom-comments'.
  17. */
  18. do_action( 'rss_tag_pre', 'rss2' );
  19. ?>
  20. <rss version="2.0"
  21. xmlns:content="http://purl.org/rss/1.0/modules/content/"
  22. xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  23. xmlns:dc="http://purl.org/dc/elements/1.1/"
  24. xmlns:atom="http://www.w3.org/2005/Atom"
  25. xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
  26. xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  27. <?php
  28. /**
  29. * Fires at the end of the RSS root to add namespaces.
  30. *
  31. * @since 2.0.0
  32. */
  33. do_action( 'rss2_ns' );
  34. ?>
  35. >
  36. <channel>
  37. <title><?php wp_title_rss(); ?></title>
  38. <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
  39. <link><?php bloginfo_rss( 'url' ); ?></link>
  40. <description><?php bloginfo_rss( 'description' ); ?></description>
  41. <lastBuildDate><?php echo get_feed_build_date( 'r' ); ?></lastBuildDate>
  42. <language><?php bloginfo_rss( 'language' ); ?></language>
  43. <sy:updatePeriod>
  44. <?php
  45. $duration = 'hourly';
  46. /**
  47. * Filters how often to update the RSS feed.
  48. *
  49. * @since 2.1.0
  50. *
  51. * @param string $duration The update period. Accepts 'hourly', 'daily', 'weekly', 'monthly',
  52. * 'yearly'. Default 'hourly'.
  53. */
  54. echo apply_filters( 'rss_update_period', $duration );
  55. ?>
  56. </sy:updatePeriod>
  57. <sy:updateFrequency>
  58. <?php
  59. $frequency = '1';
  60. /**
  61. * Filters the RSS update frequency.
  62. *
  63. * @since 2.1.0
  64. *
  65. * @param string $frequency An integer passed as a string representing the frequency
  66. * of RSS updates within the update period. Default '1'.
  67. */
  68. echo apply_filters( 'rss_update_frequency', $frequency );
  69. ?>
  70. </sy:updateFrequency>
  71. <?php
  72. /**
  73. * Fires at the end of the RSS2 Feed Header.
  74. *
  75. * @since 2.0.0
  76. */
  77. do_action( 'rss2_head' );
  78. while ( have_posts() ) :
  79. the_post();
  80. ?>
  81. <item>
  82. <title><?php the_title_rss(); ?></title>
  83. <link><?php the_permalink_rss(); ?></link>
  84. <?php if ( get_comments_number() || comments_open() ) : ?>
  85. <comments><?php comments_link_feed(); ?></comments>
  86. <?php endif; ?>
  87. <dc:creator><![CDATA[<?php the_author(); ?>]]></dc:creator>
  88. <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate>
  89. <?php the_category_rss( 'rss2' ); ?>
  90. <guid isPermaLink="false"><?php the_guid(); ?></guid>
  91. <?php if ( get_option( 'rss_use_excerpt' ) ) : ?>
  92. <description><![CDATA[<?php the_excerpt_rss(); ?>]]></description>
  93. <?php else : ?>
  94. <description><![CDATA[<?php the_excerpt_rss(); ?>]]></description>
  95. <?php $content = get_the_content_feed( 'rss2' ); ?>
  96. <?php if ( strlen( $content ) > 0 ) : ?>
  97. <content:encoded><![CDATA[<?php echo $content; ?>]]></content:encoded>
  98. <?php else : ?>
  99. <content:encoded><![CDATA[<?php the_excerpt_rss(); ?>]]></content:encoded>
  100. <?php endif; ?>
  101. <?php endif; ?>
  102. <?php if ( get_comments_number() || comments_open() ) : ?>
  103. <wfw:commentRss><?php echo esc_url( get_post_comments_feed_link( null, 'rss2' ) ); ?></wfw:commentRss>
  104. <slash:comments><?php echo get_comments_number(); ?></slash:comments>
  105. <?php endif; ?>
  106. <?php rss_enclosure(); ?>
  107. <?php
  108. /**
  109. * Fires at the end of each RSS2 feed item.
  110. *
  111. * @since 2.0.0
  112. */
  113. do_action( 'rss2_item' );
  114. ?>
  115. </item>
  116. <?php endwhile; ?>
  117. </channel>
  118. </rss>