I'm making a custom rss feed, with which outputs tags in particular namespaces. But when i output for example, the pugpig part disappears and i'm left with 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
//URL: http://ift.tt/1wuBNFE (for current issue) //URL: http://ift.tt/1zlKeh9 (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 '';
- Vol Issue "); self_link(); echo("\n"); ?> RSS feed for Volume Issue ID, 'page', true ); $authors = get_post_meta( $post->ID, 'authors', true ) ?> ID, $authors ); } ?> ID,"standfirst_use_strap",true)){ ?> ");echo strip_tags(the_excerpt_rss()); echo("
\n"); } else { echo(""); echo get_post_meta($post->ID,"standfirst",true); echo ("\n"); } ?> "); ns_print_taxonomy( $post->ID, 'article_type'); echo ("\n"); echo(""); echo $issue; echo("\n"); echo(""); echo $page; echo("\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 ){ ?>Technology ID, 'article_section'); ?> "); echo get_post_meta($post->ID, '_wp_article_thumbnail', true); echo("\n"); echo(""); ns_print_taxonomy( $post->ID, 'article_topic'); echo("\n"); echo(""); ns_print_taxonomy( $post->ID, 'article_subject'); echo("\n"); ?> ID ); ?> ID,"standfirst_use_strap",true)){ echo ''.strip_tags(get_the_excerpt()).'
'; } else { if (get_post_meta("standfirst",true)); echo ''.get_post_meta($post->ID,"standfirst",true).''; } ?>
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("#.?#","",$content); // remove javascript from description $final_content = str_replace('
', '', $content); $final_content = str_replace('', '', $final_content); $final_content = str_replace('', '', $final_content); $final_content = preg_replace('#[/?caption.?]#',"",$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>/',$matches[4],$matches1); $caption = $matches1[1]; } if ($matches[5]){ $matches1 = array(); preg_match('/(.?)
',$matches[5],$matches1); $credit = $matches1[1]; } if ($imgnumber && !$credit){ $credit = get_post_meta($imgnumber,'credit',true); } if (preg_match('/graphic/',$class)){ return "$caption"; } return "$caption$credit"; };
$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 "$caption"; } return "$caption$credit
"; }; $final_content = preg_replace_callback("#(.?)(.?)#",$callback3,$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 "$title$credit
"; } return "$title$credit"; }; $final_content = preg_replace_callback('#([^<]+)([^<]+)#',$callback1,$final_content);
$final_content = preg_replace_callback("#
(.?)
(.?)?(.?
)(.?)#",$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 "$title$credit
"; };
$final_content = preg_replace_callback('#(?([^<]+)([^<]+)
#',$callback,$final_content);
$final_content = preg_replace_callback('#(?#',$callback,$final_content);
$final_content = preg_replace('#&([^;]{1,8})#','&$1',$final_content); $final_content = preg_replace('//','>',$final_content); $final_content = ns_decode_characters( $final_content ); $final_content = preg_replace('//','',$final_content); $final_content = preg_replace('//','',$final_content); $final_content = preg_replace('##','',$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 ''; echo ''.$author_name.''; echo ''.$author_location.'';
echo ''.$author_affiliation.''; echo ''; } }
// 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;
Aucun commentaire:
Enregistrer un commentaire