I’m working on a plugin that will create a custom post type for press releases. The objective is to give the user the ability to easily create a press release in the standard press release format. An example would be:
FOR IMMEDIATE RELEASE
Title Here
City, State (Month Year) – Paragraph 1
Paragraph 2
So on…
Contact:
PR Rep Name
Title
Company
Phone: #
Fax: ## # #
The plugin has custom fields for the contact info, automatically prepends the “FOR IMMEDIATE RELEASE”, etc. The whole idea is that you just write the content for the release and everything else is taken care of for you.
I am trying to create a custom RSS feed for this post type which will use these custom fields and display everything correctly. I have it basically working except for one bug I’m noticing.
If multiple press releases were published on the same day, only the most recent will show the date. The rest are blank where the date should appear. Here is my code for the feed: (modified version of /wp-includes/feed-rss2.php)
<?php
header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
$more = 1;
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'); ?>
>
<channel>
<title><?php bloginfo_rss('name'); ?></title>
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
<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', 'hourly' ); ?></sy:updatePeriod>
<sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', '1' ); ?></sy:updateFrequency>
<?php do_action('rss2_head'); ?>
<?php
while( have_posts()) : the_post();
$pr_option = get_option('bacpr_option');
$pr_meta = get_post_custom();
$pr_date_format = ($pr_option["date_format"] != null && $pr_option["date_format"] != "") ? $pr_option["date_format"]:"F j, Y";
?>
<item>
<title><?php the_title_rss() ?></title>
<link><?php the_permalink_rss() ?></link>
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
<?php the_category_rss('rss2') ?>
<guid isPermaLink="false"><?php the_guid(); ?></guid>
<?php
$content = "<p><strong>FOR IMMEDIATE RELEASE</strong></p><h1>".the_title_rss()."</h1>";
if ($pr_meta["insert_summary"][0] == 1) {
$content .= "<p><em>".$pr_meta["summary"][0]."</em></p>";
}
ob_start();
the_content('rss2');
$original_content = ob_get_contents();
ob_end_clean();
$startpos = strpos($original_content, "<p");
$endpos = strpos($original_content, ">", $startpos);
$new_content = substr($original_content, 0, $endpos+1);
$new_content .= "<strong>".$pr_meta['location'][0]." ".the_date($pr_date_format, '(', ')', false)." -</strong> ";
$new_content .= substr($original_content, $endpos+1);
$content .= $new_content;
$content .= "<p>Contact:<br/>";
$content .= ($pr_meta["signature1"][0] != null || $pr_meta["signature1"][0] != "") ? $pr_meta["signature1"][0]."<br/>":"";
$content .= ($pr_meta["signature2"][0] != null || $pr_meta["signature2"][0] != "") ? $pr_meta["signature2"][0]."<br/>":"";
$content .= ($pr_meta["signature3"][0] != null || $pr_meta["signature3"][0] != "") ? $pr_meta["signature3"][0]."<br/>":"";
$content .= ($pr_meta["email"][0] != null || $pr_meta["email"][0] != "") ? "<a href='mailto:".$pr_meta["email"][0]."'>".$pr_meta["email"][0]."</a>"."<br/>":"";
$content .= ($pr_meta["address1"][0] != null || $pr_meta["address1"][0] != "") ? $pr_meta["address1"][0]."<br/>":"";
$content .= ($pr_meta["address2"][0] != null || $pr_meta["address2"][0] != "") ? $pr_meta["address2"][0]."<br/>":"";
$content .= ($pr_meta["address3"][0] != null || $pr_meta["address3"][0] != "") ? $pr_meta["address3"][0]."<br/>":"";
$content .= ($pr_meta["phone"][0] != null || $pr_meta["phone"][0] != "") ? "Phone: ".$pr_meta["phone"][0]."<br/>":"";
$content .= ($pr_meta["fax"][0] != null || $pr_meta["fax"][0] != "") ? "Fax: ".$pr_meta["fax"][0]."<br/>":"";
$content .= ($pr_meta["web"][0] != null || $pr_meta["web"][0] != "") ? "<a href='".$pr_meta["web"][0]."'>".$pr_meta["web"][0]."</a>"."<br/>":"";
$content .= "</p><p><strong>";
$content .= ($pr_option["ends_with"] == 2) ? "ENDS":"# # #";
$content .= "</strong></p>";
?>
<content:encoded><![CDATA[<?php echo $content; ?>]]></content:encoded>
<?php rss_enclosure(); ?>
<?php do_action('rss2_item'); ?>
</item>
<?php endwhile; ?>
</channel>
</rss>
Basically I’m at a loss and I thought I’d turn to you folks for help. Thanks in advance to anyone who helps me out here.
http://codex.wordpress.org/Function_Reference/the_date
What you want is this: