Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 5.21 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 mysite.com</a><br /><br />';
  49. $email      = get_the_author_meta( 'email');
  50. $author     = get_the_author();
  51.  
  52. // Check for post image. If none, fallback to a default.
  53. //$postimage = ( $postimages ) ? $postimages[0] : get_stylesheet_directory_uri() . '/images/sb_small.jpg';
  54.  
  55.  
  56. /**
  57.  * Start RSS feed.
  58.  */
  59. echo '<?xml version="1.0" encoding="' . get_option( 'blog_charset' ) . '"?' . '>'; ?>
  60.  
  61. <rss version="2.0"
  62.     xmlns:content="http://purl.org/rss/1.0/modules/content/"
  63.     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  64.     xmlns:dc="http://purl.org/dc/elements/1.1/"
  65.     xmlns:atom="http://www.w3.org/2005/Atom"
  66.     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
  67.     xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  68.     <?php do_action( 'rss2_ns' ); ?>
  69. >
  70.  
  71.     <!-- RSS feed defaults -->
  72.     <channel>
  73.         <title> SparkleBox Teaching Resources </title>
  74.         <link><?php bloginfo_rss( 'url' ) ?></link>
  75.         <description><?php bloginfo_rss( 'description' ) ?></description>
  76.         <lastBuildDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_lastpostmodified( 'GMT' ), false ); ?></lastBuildDate>
  77.         <language><?php bloginfo_rss( 'language' ); ?></language>
  78.         <sy:updatePeriod><?php echo apply_filters( 'rss_update_period', $duration ); ?></sy:updatePeriod>
  79.         <sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', $frequency ); ?></sy:updateFrequency>
  80.         <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
  81.  
  82.         <!-- Feed Logo (optional) -->
  83.     <!--    <image>
  84.             <url><?php // get_stylesheet_directory_uri() . '/images/sb_small.jpg'; ?></url>
  85.             <title>
  86.                 <?php // bloginfo_rss( 'description' ) ?>
  87.             </title>
  88.             <link><?php // bloginfo_rss( 'url' ) ?></link>
  89.         </image>
  90. -->
  91.         <?php do_action( 'rss2_head' ); ?>
  92.  
  93.        
  94.        
  95.        
  96.         <!-- Start loop -->
  97.         <?php
  98. $args = array(
  99. 'post_status' => 'publish',
  100. 'post_type' =>   array( 'post', 'sb_photo'),
  101.     'posts_per_page' => 20,
  102.        'meta_key' => 'orderNumber',
  103.                     'orderby' => 'meta_value_num',
  104. );
  105.  
  106. $query = new WP_Query( $args);
  107.  
  108.  
  109.  
  110.  while ( $query->have_posts() ) : $query->the_post();
  111.  $postimages = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID));
  112. $postimage = $postimages[0];
  113.  
  114. $media = get_posts(array(
  115.     'post_parent' => $post->ID,
  116.     'post_type' => 'attachment',
  117.     'post_mime_type' => 'image',
  118.     'orderby' => 'title',
  119.     'order' => 'ASC',
  120.     'posts_per_page' => 1
  121. ));
  122.  
  123. foreach ($media as $eachmedia) {   
  124. $images["URL"] = $eachmedia->guid;
  125. $images["ID"] = $eachmedia->ID;
  126. $a++;
  127. }
  128.  
  129.  
  130.  $orderNumber = get_post_meta ($post->ID, 'orderNumber', true);
  131.    $thumbLabel = get_post_meta($post->ID, 'newcontent', true);
  132.    if ($thumbLabel == "updated")
  133.    {
  134.        $labeltoShow = "UPDATED";
  135.    } else {
  136.        $labeltoShow = "NEW";
  137.    }
  138.  
  139.   $theTitle = get_the_title();
  140.  
  141.    $theTitle = substr(strstr("$theTitle"," "), 1);
  142.    
  143.    $theTitle = $labeltoShow . " " . $theTitle;
  144.  
  145.  ?>
  146.  
  147.             <item>
  148.        
  149.                 <title><?php echo $theTitle; ?></title>
  150.                 <link><?php the_permalink_rss(); ?></link>
  151.  
  152.                 <guid isPermaLink="false"><?php the_guid(); ?></guid>
  153.                 <author><?php echo $email ?><?php echo ' (' . $author . ')' ?></author>
  154.  
  155. <description>
  156.    
  157. <![CDATA[  
  158.  
  159. <img align="left" hspace="8" src="<?php echo $images["URL"]; ?>"/><br />
  160.  
  161.    
  162. ]]>
  163.  
  164.  
  165. </description>
  166.  
  167. <media:content url="<?php echo $images["URL"]; ?>" medium="image">
  168. </media:content>
  169.  
  170.                 <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate>
  171.  
  172.                 <!-- Echo content and related posts -->
  173.                 <content:encoded>
  174.                
  175.                     <![CDATA[
  176.                    
  177.  
  178.                     <?php echo the_excerpt_rss(); echo $postlink; echo my_rss_related(); ?>]]>
  179.                 </content:encoded>
  180.             </item>
  181.  
  182.         <?php
  183.  
  184.        
  185.        
  186.         endwhile; ?>
  187.         <!-- End loop -->
  188.     </channel>
  189. </rss>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement