Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Customs RSS template with related posts.
- *
- * Place this file in your theme's directory.
- *
- * @package sometheme
- * @subpackage theme
- */
- /**
- * Get related posts based on tags.
- *
- * THIS IS OPTIONAL!
- */
- function my_rss_related() {
- global $post;
- // Setup post data.
- //$pid = $post->ID;
- //$tags = wp_get_post_tags( $pid );
- //$tag_ids = array();
- // Loop through post tags.
- // foreach ( $tags as $individual_tag ) {
- // $tag_ids[] = $individual_tag->term_id;
- //}
- // Execute WP_Query.
- //$related_by_tag = new WP_Query( array(
- // 'tag__in' => $tag_ids,
- // 'post__not_in' => array( $pid ),
- // 'posts_per_page' => 3,
- // ) );
- // Loop through posts and build HTML.
- //if ( $related_by_tag->have_posts() ) :
- // echo 'Related:<br />';
- // while ( $related_by_tag->have_posts() ) : $related_by_tag->the_post();
- // echo '<a href="' . get_permalink() . '">' . get_the_title() . '</a><br />';
- // endwhile;
- // else :
- // echo '';
- //endif;
- // wp_reset_postdata();
- }
- /**
- * Feed defaults.
- */
- header( 'Content-Type: ' . feed_content_type( 'rss-http' ) . '; charset=' . get_option( 'blog_charset' ), true );
- $frequency = 1; // Default '1'. The frequency of RSS updates within the update period.
- $duration = 'hourly'; // Default 'hourly'. Accepts 'hourly', 'daily', 'weekly', 'monthly', 'yearly'.
- //$postlink = '<br /><a href="' . get_permalink() . '">See the rest of the story at mysite.com</a><br /><br />';
- $email = get_the_author_meta( 'email');
- $author = get_the_author();
- // Check for post image. If none, fallback to a default.
- //$postimage = ( $postimages ) ? $postimages[0] : get_stylesheet_directory_uri() . '/images/sb_small.jpg';
- /**
- * Start RSS feed.
- */
- 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' ); ?>
- >
- <!-- RSS feed defaults -->
- <channel>
- <title> SparkleBox Teaching Resources </title>
- <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 bloginfo_rss( 'language' ); ?></language>
- <sy:updatePeriod><?php echo apply_filters( 'rss_update_period', $duration ); ?></sy:updatePeriod>
- <sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', $frequency ); ?></sy:updateFrequency>
- <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
- <!-- Feed Logo (optional) -->
- <!-- <image>
- <url><?php // get_stylesheet_directory_uri() . '/images/sb_small.jpg'; ?></url>
- <title>
- <?php // bloginfo_rss( 'description' ) ?>
- </title>
- <link><?php // bloginfo_rss( 'url' ) ?></link>
- </image>
- -->
- <?php do_action( 'rss2_head' ); ?>
- <!-- Start loop -->
- <?php
- $args = array(
- 'post_status' => 'publish',
- 'post_type' => array( 'post', 'sb_photo'),
- 'posts_per_page' => 20,
- 'meta_key' => 'orderNumber',
- 'orderby' => 'meta_value_num',
- );
- $query = new WP_Query( $args);
- while ( $query->have_posts() ) : $query->the_post();
- $postimages = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID));
- $postimage = $postimages[0];
- $media = get_posts(array(
- 'post_parent' => $post->ID,
- 'post_type' => 'attachment',
- 'post_mime_type' => 'image',
- 'orderby' => 'title',
- 'order' => 'ASC',
- 'posts_per_page' => 1
- ));
- foreach ($media as $eachmedia) {
- $images["URL"] = $eachmedia->guid;
- $images["ID"] = $eachmedia->ID;
- $a++;
- }
- $orderNumber = get_post_meta ($post->ID, 'orderNumber', true);
- $thumbLabel = get_post_meta($post->ID, 'newcontent', true);
- if ($thumbLabel == "updated")
- {
- $labeltoShow = "UPDATED";
- } else {
- $labeltoShow = "NEW";
- }
- $theTitle = get_the_title();
- $theTitle = substr(strstr("$theTitle"," "), 1);
- $theTitle = $labeltoShow . " " . $theTitle;
- ?>
- <item>
- <title><?php echo $theTitle; ?></title>
- <link><?php the_permalink_rss(); ?></link>
- <guid isPermaLink="false"><?php the_guid(); ?></guid>
- <author><?php echo $email ?><?php echo ' (' . $author . ')' ?></author>
- <description>
- <![CDATA[
- <img align="left" hspace="8" src="<?php echo $images["URL"]; ?>"/><br />
- ]]>
- </description>
- <media:content url="<?php echo $images["URL"]; ?>" medium="image">
- </media:content>
- <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate>
- <!-- Echo content and related posts -->
- <content:encoded>
- <![CDATA[
- <?php echo the_excerpt_rss(); echo $postlink; echo my_rss_related(); ?>]]>
- </content:encoded>
- </item>
- <?php
- endwhile; ?>
- <!-- End loop -->
- </channel>
- </rss>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement