Giving custom fields a specific order in an RSS feed?
-
Hey all,
I’m having a little bit of trouble translating my somewhat sophisticated use of custom fields to my RSS feed. Basically, my site ( https://shortformblog.com/ ) relies on Custom Fields to post everything – big numbers, fact boxes, photos and so on.
Since WP doesn’t default to showing custom fields, I had to do a bit of customization to Kaf Oseo’s Custom2Feed plugin to make it do what I wanted. For the most part, that works OK, but I had to make some changes based on what type of custom field it was.
Unfortunately, these don’t show up in my intended order in WordPress. To give you an idea, here’s the feed: https://feeds.feedburner.com/shortformblog/feed
Quotes show up after attributions, numbers show up out of order … it’s kind of a mess, and I’d like to fix it.
Here’s the modified code below. Any clue as to why, or how I should further rework this to make my custom fields go in a specific order? Most of my modifications were made at the bottom, so that certain fields show up in certain HTML styles.
<?php /* Plugin Name: ShortFormBlog RSS feed custom jank Description: A reworked version of Kaf Oseo's Custom2Feed content for my own purposes Author: Kaf Oseo, Ernie Smith Version: 0.1 Copyright (c) 2006, 2008 Kaf Oseo (https://szub.net), 2009 Ernie Smith Custom2Feed Content is released under the GNU General Public License, version 2 (GPL2) https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt This is a WordPress plugin (https://www.ads-software.com). ~Changelog: R1.1 (Feb-23-2008) Fix to post_meta collect to work under newer WordPress versions. */ function szub_custom2feed($text) { /* >> Begin user-configurable variables >> */ // $pass_keys - Array of allowed custom keys. Modify to your needs. $pass_keys = array('bignumber', 'bignumberwords', 'bignumberb', 'bignumberwordsb', 'quote', 'attribution', 'factboxhed', 'factbox', 'factboxhedb', 'factboxb', 'factboxhedc', 'factboxc', 'tightcrop', 'cutline'); /* $list_mode - How to display your custom keys/values. Options are: 'ul' : Unordered list. 'ol-1' : Ordered (numbered) list (also: 'ol'). 'ol-A' : Ordered (lettered) list. 'dl' : Description list. 'p' : Individual paras (customkey: customvalue ). 'tag' : Pseudo-tag format (<customkey>customvalue</customkey>). */ $list_mode = 'p'; // $sep - custom key:value separator character(s). $sep = ': '; /* << End user-configurable variables << */ $customtext = ''; if( is_feed() ) { global $post_meta_cache, $wp_query; if( $post_meta_cache[$wp_query->post->ID] ) $post_meta_cache = $post_meta_cache[$wp_query->post->ID]; else $post_meta_cache = get_post_custom($wp_query->post->ID); if( $post_meta_cache ) { foreach( get_post_custom_keys() as $key ) { if( in_array($key, $pass_keys) ) { foreach( get_post_custom_values($key) as $value ) $customtext .= szub_line_mode($key, $value, $sep, $list_mode); } } if( $customtext ) { switch( $list_mode ) { case 'ul': $text .= "\n <ul>\n$customtext</ul> "; break; case 'ol': case 'ol-1': $text .= "\n <ol>\n$customtext</ol> "; break; case 'ol-A': $text .= "\n<ol type=\"A\">\n$customtext"; break; case 'dl': $text .= "\n<dl>\n$customtext</dl>"; break; default: $text .= $customtext; } } } } return $text; } add_filter('the_content', 'szub_custom2feed', 9); function szub_line_mode($key, $value, $sep, $list_mode) { switch( $list_mode ) { case 'ul': case 'ol': case 'ol-1': case 'ol-A':; return " <li>$key$sep$value</li> \n"; case 'dl': return "<dt>$key$sep</dt><dd>$value</dd>\n"; case 'tag': return "\n<$key>$value</$key>"; case 'p': if ($key == 'quote'){ echo '<h1 style="line-height:normal; font:bold italic;">“' . $value . '” </h1>';} elseif(in_array($key, array('bignumber', 'bignumberb'))){ echo '<h1 style="line-height:normal; color:#c00c20;">' . $value . ' </h1>';} elseif($key == 'tightcrop'){ echo '<img src="' . $value . '"> ';} elseif(in_array($key, array('factboxhed', 'factboxhedb', 'factboxhedc'))){ echo '<h3 style="color:#c00c20;">' . $value . ' </h3>';} elseif($key !== ''){ echo '' . $value . ' ';} } } add_filter('the_content', 'szub_custom2feed', 9); ?>
- The topic ‘Giving custom fields a specific order in an RSS feed?’ is closed to new replies.