Advertisement
Guest User

Untitled

a guest
May 21st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.83 KB | None | 0 0
  1. <?php
  2. /**
  3. * Customs RSS template with related posts.
  4. *
  5. * Place this file in your theme's directory.
  6. *
  7. * @package sometheme
  8. * @subpackage theme
  9. */
  10. /**
  11. * Get related posts based on tags.
  12. *
  13. * THIS IS OPTIONAL!
  14. */
  15. function my_rss_related() {
  16. global $post;
  17. // Setup post data.
  18. $pid = $post->ID;
  19. $tags = wp_get_post_tags( $pid );
  20. $tag_ids = array();
  21. // Loop through post tags.
  22. foreach ( $tags as $individual_tag ) {
  23. $tag_ids[] = $individual_tag->term_id;
  24. }
  25. // Execute WP_Query.
  26. $related_by_tag = new WP_Query( array(
  27. 'tag__in' => $tag_ids,
  28. 'post__not_in' => array( $pid ),
  29. 'posts_per_page' => 3,
  30. ) );
  31. // Loop through posts and build HTML.
  32. if ( $related_by_tag->have_posts() ) :
  33. echo 'Related:<br />';
  34. while ( $related_by_tag->have_posts() ) : $related_by_tag->the_post();
  35. echo '<a href="' . get_permalink() . '">' . get_the_title() . '</a><br />';
  36. endwhile;
  37. else :
  38. echo '';
  39. endif;
  40. wp_reset_postdata();
  41. }
  42. /**
  43. * Feed defaults.
  44. */
  45. header( 'Content-Type: ' . feed_content_type( 'rss-http' ) . '; charset=' . get_option( 'blog_charset' ), true );
  46. $frequency = 1; // Default '1'. The frequency of RSS updates within the update period.
  47. $duration = 'hourly'; // Default 'hourly'. Accepts 'hourly', 'daily', 'weekly', 'monthly', 'yearly'.
  48. $postlink = '<br /><a href="' . get_permalink() . '">See the rest of the story at joshwrye.com</a><br /><br />';
  49. $email = get_the_author_meta( 'email');
  50. $author = get_the_author();
  51. $postimages = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'large' );
  52. // Check for post image. If none, fallback to a default.
  53. $postimage = ( $postimages ) ? $postimages[0] : get_stylesheet_directory_uri() . '/images/default.jpg';
  54. /**
  55. * Start RSS feed.
  56. */
  57. echo '<?xml version="1.0" encoding="' . get_option( 'blog_charset' ) . '"?' . '>'; ?>
  58.  
  59. <rss version="2.0"
  60. xmlns:content="http://purl.org/rss/1.0/modules/content/"
  61. xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  62. xmlns:dc="http://purl.org/dc/elements/1.1/"
  63. xmlns:atom="http://www.w3.org/2005/Atom"
  64. xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
  65. xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  66. xmlns:property="https://joshwrye.com/ns/property/"
  67. <?php do_action( 'rss2_ns' ); ?>
  68. >
  69.  
  70. <!-- RSS feed defaults -->
  71. <channel>
  72. <title><?php bloginfo_rss( 'name' ); wp_title_rss(); ?></title>
  73. <link><?php bloginfo_rss( 'url' ) ?></link>
  74. <description><?php bloginfo_rss( 'description' ) ?></description>
  75. <lastBuildDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_lastpostmodified( 'GMT' ), false ); ?></lastBuildDate>
  76. <language><?php bloginfo_rss( 'language' ); ?></language>
  77. <sy:updatePeriod><?php echo apply_filters( 'rss_update_period', $duration ); ?></sy:updatePeriod>
  78. <sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', $frequency ); ?></sy:updateFrequency>
  79. <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
  80.  
  81. <!-- Feed Logo (optional) -->
  82. <image>
  83. <url>http://mysite.com/somelogo.png</url>
  84. <title>
  85. <?php bloginfo_rss( 'description' ) ?>
  86. </title>
  87. <link><?php bloginfo_rss( 'url' ) ?></link>
  88. </image>
  89.  
  90. <?php do_action( 'rss2_head' ); ?>
  91.  
  92. <!-- Start loop -->
  93. <?php while( have_posts() ) : the_post();
  94.  
  95. $rssPropertyArray = array(
  96. "propImage" => get_field('property_image'),
  97. "propAddress" => get_field('street_address'),
  98. "soldPrice" => get_field('sold_price'),
  99. "pricePerSqFt" => get_field('price_per_sqft'),
  100. "daysOnMarket" => get_field('days_on_market'),
  101. "beds" => get_field('beds'),
  102. "baths" => get_field('baths'),
  103. "squareFootage" => get_field('square_footage'),
  104. "additionalInfo" => get_field('additional_info'),
  105. "originalDate" => get_field('original_date'),
  106. "originalPrice" => get_field('original_price'),
  107. "appreciationValue" => get_field('appreciation_value'),
  108. "appreciationTime" => get_field('appreciation_time'),
  109. "trackerDate" => get_field('tracker_date'),
  110. "trackerSold" => get_field('tracker_homes_sold'),
  111. "trackerValue" => get_field('tracker_appreciation_value'),
  112. "trackerPercent" => get_field('tracker_appreciation_percent'),
  113. "trackerYear" => get_field('tracker_year')
  114. );
  115.  
  116. ?>
  117.  
  118. <item>
  119. <title><?php the_title_rss(); ?></title>
  120. <link><?php the_permalink_rss(); ?></link>
  121. <guid isPermaLink="false"><?php the_guid(); ?></guid>
  122. <author><?php echo $email ?><?php echo ' (' . $author . ')' ?></author>
  123. <image>
  124. <url><?php echo esc_url( $postimage ); ?>"/></url>
  125. </image>
  126. <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate>
  127.  
  128. <?
  129. if(!empty($rssPropertyArray)){
  130. foreach ($rssPropertyArray as $k => $v) {
  131. $output .= '<property:'.$k.'>'.$v.'</property:'.$k.'>';
  132. };
  133. };
  134. ?>
  135.  
  136. <!-- Echo content and related posts -->
  137. <content:encoded>
  138. <![CDATA[<?php echo the_excerpt_rss(); echo $postlink; echo my_rss_related(); ?>]]>
  139. </content:encoded>
  140. </item>
  141.  
  142. <?php endwhile; ?>
  143. <!-- End loop -->
  144. </channel>
  145. </rss>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement