WordPress remove namespace part from my tags in rss feed
-
I’m making a custom rss feed, with which outputs tags in particular namespaces. But when i output <pugpig:summary> for example, the pugpig part disappears and i’m left with <summary> in the output tag. How is wordpress doing this and how can i stop it.
Here is my custom feed logic
add_action(‘init’, ‘ns_add_custom_rss_feeds’);
function ns_add_custom_rss_feeds(){
ns_create_pugpig_feed();
ns_create_content_feed();
ns_create_issue_feed();
ns_create_google_currents_feed();
}/**
* Create the new pugpig feed
* add_feed params: feed name and callback funcion
*/
function ns_create_pugpig_feed(){
add_feed(‘pugpig’, ‘ns_get_pugpig_template’);
}/**
* Callback function to create the feed
* get_template_part link to a separate template file to keep the functionality separate to the layout.
* the file will be: /wp-content/themes/template/rss-pugpig.php
*/
function ns_get_pugpig_template(){
get_template_part(‘rss2’, ‘pugpig’);
}And here is where i output the tags
themes/mythemes/rss2-pugpig.php
<?php
/**
* RSS2 Feed Template for displaying pugpig feed.
*
* @package newscientist
*///URL: http://www.newscientist.com/feed/pugpig (for current issue)
//URL: http://www.newscientist.com/feed/pugpig?issue=1234 (for a given issue)$issue = get_query_var( ‘issue’ );
if(empty($issue)){
//if the parameter “issue” is not in the URL, we take the current issue
$issue = ns_get_current_issue_number();
}$issue_info = ns_get_issue_info($issue);
$volume = $issue_info -> field(‘volume’);$args = array(
‘post_type’ => ‘article’,
‘meta_query’ => array(
array(
‘key’ => ‘issue_number’,
‘value’ => $issue
),
array(
‘key’ => ‘pugpig’,
‘value’ => ‘1’
)
),
‘posts_per_page’=>-1
);
//query posts by type, issue_number and pugpig flag
$posts = query_posts( $args );echo ‘<?xml version=”1.0″ encoding=”‘.get_option(‘blog_charset’).'”?’.’>’;
<rss xmlns:content=”http://purl.org/rss/1.0/modules/content/” xmlns:rdf=”http://www.w3.org/1999/02/22-rdf-syntax-ns#” xmlns:media=”http://search.yahoo.com/mrss/” xmlns:pugpig=”http://schema.pugpig.com/rss/” xmlns:dc=”http://purl.org/dc/elements/1.1/” xmlns:taxo=”http://purl.org/rss/1.0/modules/taxonomy/” xmlns:php=”http://www.w3.org/1999/XSL/Transform” version=”2.0″>
<channel>
<title><?php bloginfo_rss(‘name’); ?> – Vol <?php echo $volume; ?> Issue <?php echo $issue; ?></title>
<?php echo(“<link>”); self_link(); echo(“</link>n”); ?>
<description>RSS feed for Volume <?php echo $volume; ?> Issue <?php echo $issue; ?></description>
<?php while(have_posts()) : the_post(); ?>
<?php
$page = get_post_meta( $post->ID, ‘page’, true );
$authors = get_post_meta( $post->ID, ‘authors’, true )
?>
<item>
<title><?php the_title_rss(); ?></title>
<author><?php the_author(); ?></author>
<?php
if ( ! empty ( $authors )) {
ns_print_authors( $post->ID, $authors );
}
?>
<?php
if (get_post_meta($post->ID,”standfirst_use_strap”,true)){
?>
<?php echo(“<pugpig:summary><p class=”strap”>”);echo strip_tags(the_excerpt_rss()); echo(“</p></pugpig:summary>n”);
} else {
echo(“<pugpig:summary><p class=”strap”>”);
echo get_post_meta($post->ID,”standfirst”,true);
echo (“</p></pugpig:summary>n”);
}
?>
<?php echo(“<pugpig:subtitle>”); ns_print_taxonomy( $post->ID, ‘article_type’);
echo (“</pugpig:subtitle>n”);
echo(“<green:issue>”); echo $issue; echo(“</green:issue>n”);
echo(“<pugpig:page>”); echo $page; echo(“</pugpig:page>n”);
$article_section = wp_get_object_terms($post->ID,’article_section’);
$article_types = wp_get_object_terms($post->ID, ‘article_subject’);
$istech = false;
$isnews = false;
foreach($article_section as $section){
if ($section->name == ‘News’){ $isnews = true;}
}
foreach($article_types as $subject){
if ($subject->name ==’Technology’){ $istech = true; }
}if ($istech && $isnews ){
?><category>Technology</category><?php
} else {
?>
<category><?php ns_print_taxonomy( $post->ID, ‘article_section’); ?></category>
<?php
}
?>
<?php echo(“<pugpig:thumbnail>”);
echo get_post_meta($post->ID, ‘_wp_article_thumbnail’, true);
echo(“</pugpig:thumbnail>n”);
echo(“<pugpig:topics>”); ns_print_taxonomy( $post->ID, ‘article_topic’); echo(“</pugpig:topics>n”);
echo(“<pugpig:channels>”); ns_print_taxonomy( $post->ID, ‘article_subject’); echo(“</pugpig:channels>n”);
?>
<link><?php the_permalink_rss(); ?></link>
<pubDate><?php ns_print_pubdate( $post->ID ); ?></pubDate>
<guid isPermaLink=”false”><?php ns_print_guid (get_the_guid()) ?></guid>
<description>
<?php
if (!get_post_meta($post->ID,”standfirst_use_strap”,true)){
echo ‘<p class=”infuse”>’.strip_tags(get_the_excerpt()).'</p>’;
} else {
if (get_post_meta(“standfirst”,true));
echo ‘<p class=”note”>’.get_post_meta($post->ID,”standfirst”,true).'</p>’;
}
?>
<?php ns_print_description(get_the_content_feed(‘rss2’));
?></description><?php rss_enclosure(); ?>
<?php do_action(‘rss2_item’); ?>
</item>
<?php endwhile; ?>
</channel>
</rss>
<?php
/*
* Print pubdate.
* it will be embargo_date if set. Otherwise, it will be post date.
*/
function ns_print_pubdate( $post_id ) {
//mysql2date(‘F d Y ‘, get_post_time(‘Y-m-d H:i:s’, true), false);
$embargo_date = get_post_meta($post_id, ’embargo_date’, true);
$creation_date = get_post_time(‘Y-m-d H:i:s’, $post_id);
$publication_date = empty($embargo_date) ? $creation_date : $embargo_date;echo mysql2date(‘F d Y ‘, $publication_date, false);
}/*
* Print description.
* Process the body to adapt it to pugpig content.
* Decode html characters
*/function ns_print_description ( $content ) {
//Instead of get_teh_content(), use get_the_content_feed(‘rss2’) and fix empty tags
$content = str_replace(“–”,”-“,$content);
$content = str_replace(” “,” “,$content);
$content = str_replace(“…”,”…”,$content);
$content = str_replace(“:”,”:”,$content);
$content = preg_replace(“#<script.*?>.*?</script>#”,””,$content); // remove javascript from description
$final_content = str_replace(‘<p>’, ‘<p class=”infuse”>’, $content);
# echo(“1, “.strlen($final_content));
$final_content = str_replace(‘<div class=’box-out’>’, ‘<div class=’artbx bxbg’>’, $final_content);
# echo(“2, “.strlen($final_content));
$final_content = str_replace(‘<p class=’credit’>’, ‘<p class=’copyright’>’, $final_content);
# echo(“3, “.strlen($final_content));
$final_content = preg_replace(‘#[/?caption.*?]#’,””,$final_content);
# echo(“4, “.strlen($final_content));$callback3 = function($matches){
$imgdata = $matches[3];
$matches1 = array();
preg_match(‘#src=”(.*?)”#’,$imgdata,$matches1);
$src = $matches1[1];
$matches1 = array();
preg_match(‘#title=”(.*?)”#’,$imgdata,$matches1);
$title = $matches1[1];
$matches1 = array();
preg_match(‘#class=”(.*?)”#’,$imgdata,$matches1);
$class = $matches1[1];
$matches1 = array();
preg_match(‘#alt=”(.*?)”#’,$imgdata,$matches1);
$alt = $matches1[1];
$matches1 = array();
preg_match(‘#wp-image-(d+)#’,$class,$matches1);
$imgnumber = $matches1[1];
$credit =””;if ($matches[2]){ $title = $matches[2]; }
if ($matches[4]){
$matches1 = array();
preg_match(‘/<figcaption>(.*?)</figcaption>/’,$matches[4],$matches1);
$caption = $matches1[1];
}
if ($matches[5]){
$matches1 = array();
preg_match(‘/<psclass=”copyright”>(.*?)</p>’,$matches[5],$matches1);
$credit = $matches1[1];
}
if ($imgnumber && !$credit){
$credit = get_post_meta($imgnumber,’credit’,true);
}
if (preg_match(‘/graphic/’,$class)){
return “<figure class=”infographic article-img-left”><img src=”$src”/><figcaption>$caption</figcaption>”;
}
return “<figure><img class=”$class” src=”$src”/><figcaption>$caption</figcaption><p class=”copyright”>$credit</p></figure>”;
};$callback2 = function($matches){
$imgdata = $matches[2];
$matches1 = array();
preg_match(‘#src=”(.*?)”#’,$imgdata,$matches1);
$src = $matches1[1];
$matches1 = array();
preg_match(‘#title=”(.*?)”#’,$imgdata,$matches1);
$title = $matches1[1];
$matches1 = array();
preg_match(‘#class=”(.*?)”#’,$imgdata,$matches1);
$class = $matches1[1];
$matches1 = array();
preg_match(‘#alt=”(.*?)”#’,$imgdata,$matches1);
$alt = $matches1[1];
$matches1 = array();
preg_match(‘#wp-image-(d+)#’,$class,$matches1);
$imgnumber = $matches1[1];
$credit =””;if ($matches[2]){ $title = $matches[2]; }
if ($matches[3]){ $credit = $matches[3]; }
$caption = $matches[3];
$credit = $matches[4];
if (preg_match(‘/graphic/’,$class)){
return “<figure class=”infographic article-img-left”><img src=”$src”><figcaption>$caption</figcaption>”;
}
return “<figure><img class=”$class” src=”$src”><figcaption>$caption</figcaption><p class=”copyright”>$credit</p></figure>”;
};
$final_content = preg_replace_callback(“#<figure(.*?)><img(.*?)”/><div class=”image-details”><figcaption>(.*?)</figcaption><p class=’credit’>(.*?)</p></div></figure>#”,$callback3,$final_content);
# echo(“5, “.strlen($final_content));$callback1 = function($matches){
$imgdata = $matches[1];
$matches1 = array();
preg_match(‘#src=”(.*?)”#’,$imgdata,$matches1);
$src = $matches1[1];
$matches1 = array();
preg_match(‘#title=”(.*?)”#’,$imgdata,$matches1);
$title = $matches1[1];
$matches1 = array();
preg_match(‘#class=”(.*?)”#’,$imgdata,$matches1);
$class = $matches1[1];
$matches1 = array();
preg_match(‘#alt=”(.*?)”#’,$imgdata,$matches1);
$alt = $matches1[1];
$matches1 = array();
preg_match(‘#wp-image-(d+)#’,$class,$matches1);
$imgnumber = $matches1[1];
$credit =””;if ($matches[2]){ $title = $matches[2]; }
if ($matches[3]){ $credit = $matches[3]; }
if ($imgnumber && !$credit){
$credit = get_post_meta($imgnumber,’credit’,true);
}
if (!preg_match(‘/graphic/’,$class)){
return “<figure><img class=”$class” src=”$src” alt=”$alt” title=”$title”><figcaption>$title</figcaption><p class=”copyright”>$credit</p></figure>”;
}
return “<figure class=”infographic article-img-left”><img src=”$src” alt=”$alt” title=”$title”><figcaption>$title</figcaption><p class=”copyright”>$credit</p></figure>”;
};
$final_content = preg_replace_callback(‘#<img(.*?)>([^<]+)<i>([^<]+)</i>#’,$callback1,$final_content);
# echo(“6, “.strlen($final_content));$final_content = preg_replace_callback(“#<figure(.*?)”><h3>(.*?)</h3><img(.*?)><divsclass=”images-detail”>(<figcaption>.*?<figcaption>)?(<psclass=”image-descrption”>.*?</p>)(<psclass=”copyright”>.*?</p>)<div></figure>#”,$callback3,$final_content);
$callback = function($matches){
$imgdata = $matches[1];
$matches1 = array();
preg_match(‘#src=”(.*?)”#’,$imgdata,$matches1);
$src = $matches1[1];
$matches1 = array();
preg_match(‘#title=”(.*?)”#’,$imgdata,$matches1);
$title = $matches1[1];
$matches1 = array();
preg_match(‘#class=”(.*?)”#’,$imgdata,$matches1);
$class = $matches1[1];
$matches1 = array();
preg_match(‘#alt=”(.*?)”#’,$imgdata,$matches1);
$alt = $matches1[1];
$matches1 = array();
preg_match(‘#wp-image-(d+)#’,$class,$matches1);
$imgnumber = $matches1[1];
$credit =””;
if ($matches[2]){ $title = $matches[2]; }
if ($matches[3]){ $credit = $matches[3]; }
if ($imgnumber && !$credit){
$credit = get_post_meta($imgnumber,’credit’,true);
}
return “<figure><img class=”$class” src=”$src” alt=”$alt” title=”$title”><figcaption>$title<p class=”copyright”>$credit</p></figcaption></figure>”;
};# echo(“7, “.strlen($final_content));
$final_content = preg_replace_callback(‘#(?<!<figure).*?<img(.*?)>([^<]+)<i>([^<]+)</i></p>#’,$callback,$final_content);
# echo(“8, “.strlen($final_content));
# $final_content = preg_replace_callback(‘#(?<!<figure).*?<img(.*?)>#’,$callback,$final_content);
# echo(“9, “.strlen($final_content));
$final_content = preg_replace(‘#&([^;]{1,8})#’,’&$1′,$final_content);
# echo(“10, “.strlen($final_content));
$final_content = preg_replace(‘/</’,'<‘,$final_content);
$final_content = preg_replace(‘/>/’,’>’,$final_content);
$final_content = ns_decode_characters( $final_content );
$final_content = preg_replace(‘/<figure class=”article-img-inline”>/’,'<figure>’,$final_content);
$final_content = preg_replace(‘/<figure class=”article-img-right”>/’,'<figure>’,$final_content);
$final_content = preg_replace(‘#<img(.*?)>#’,'<img$2>’,$final_content);
echo $final_content;}
// Print authors
function ns_print_authors( $post_id, $authors ){
for ($i = 0; $i < $authors; $i++) {
$author_name = get_post_meta($post_id, ‘authors_’.$i.’_name’, true);
$author_affiliation = get_post_meta($post_id, ‘authors_’.$i.’_affiliation’, true);
$author_affiliation = ns_decode_characters( $author_affiliation);$author_location = get_post_meta($post_id, ‘authors_’.$i.’_location’, true);
$author_location = ns_decode_characters( $author_location);echo ‘<pugpig:author>’;
echo ‘<pugpig:aname>’.$author_name.'</pugpig:aname>’;
echo ‘<pugpig:alocation>’.$author_location.'</pugpig:alocation>’;echo ‘<pugpig:affiliation>’.$author_affiliation.'</pugpig:affiliation>’;
echo ‘</pugpig:author>’;
}
}// Print taxonomy
function ns_print_taxonomy ( $post_id, $taxonomy ) {
$article_types = wp_get_object_terms($post_id, $taxonomy);
$output = ”;
if(!empty($article_types) && !is_wp_error( $article_types )){
$count = 0;
foreach($article_types as $type){
if ($count == 0) {
$output = $type->name;
} else {
$output = $output.’, ‘.$type->name;
}
$count++;
}
}
echo $output;
}// Print guid
function ns_print_guid ( $guid) {
$dir = substr(strrchr($guid, “/”), 1);
echo $dir;
} -
Hello there,
Sorry but that site is not hosted by WordPress.COM. You are posting to the wrong support forums. We provide support here only for WordPress.COM hosted blogs. We do not provide support for WordPress.ORG software and cannot help you.
WordPress.COM and WordPress.ORG are completely separate and have different logins, features, run different versions of some themes with the same names, and have separate support documentation and separate support forums. Read the differences here http://en.support.wordpress.com/com-vs-org/
If you don’t have a username account at WordPress.ORG click http://wordpress.org/support/ and register one on the top right hand corner of the page that opens, so you can post to the support forums there.
Resetting your WordPress.ORG password http://codex.wordpress.org/Resetting_Your_Password
WordPress.org support docs are at https://codex.wordpress.org/Main_Page
- The topic ‘WordPress remove namespace part from my tags in rss feed’ is closed to new replies.