Quantcast
Channel: Custom Fields on RSS feed: how to? | WordPress.org
Viewing all articles
Browse latest Browse all 20

stoicboy on "Custom Fields on RSS feed: how to?"

$
0
0

ericr23: Wow, that's really useful.

Here's my question for you: I currently have my site (http://shortformblog.com/) set up with an RSS feed designed from a hacked plugin that uses an array call and a bunch of different styles based on the custom field. It's worked OK so far but occasionally things come in out of order. And right now, for no good reason, everything's coming out in reverse order.

I want to hardcode the order using a bunch of if-then-else statements, like I have it set up on my blog. The method you use … can it be used in such a fashion.

To give you an idea, here's how the code is hacked up at the moment. I left a couple of things out; this is merely to show how I break up code currently:

//  $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', 'grabbag', 'grabbagb', 'grabbagc', 'grabbagd', 'grabbage', 'tightcrop', 'cutline', 'embed', 'cutlinefull', 'source');
function szub_line_mode($key, $value, $sep, $list_mode) {
	switch( $list_mode ) {
		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 == 'grabbag'){
			echo '<h2 style="line-height:normal; color:#c00c20;">One</h2><p>' . $value . '</p>';}
			elseif($key == 'grabbagb'){
			echo '<h2 style="line-height:normal; color:#c00c20;">Two</h2><p>' . $value . '</p>';}
			elseif($key == 'grabbagc'){
			echo '<h2 style="line-height:normal; color:#c00c20;">Three</h2><p>' . $value . '</p>';}
			elseif($key == 'grabbagd'){
			echo '<h2 style="line-height:normal; color:#c00c20;">Four</h2><p>' . $value . '</p>';}
			elseif($key == 'grabbage'){
			echo '<h2 style="line-height:normal; color:#c00c20;">Five</h2><p>' . $value . '</p>';}
			elseif($key !== 'source'){
			echo '<p>' . $value . ' </p>';}
			elseif($key == 'source'){
			echo ' <a href="' . $value . '" target="_blank">Source</a> ';}
			elseif($key !== ''){
			echo '<p>' . $value . ' </p>';}
	}
}

add_filter('the_content', 'szub_custom2feed', 9);

And to give you an idea, this is what I do with the code on the frontend of the site:

<?php //Get source
	$source = get_post_meta($post->ID, 'source', $single = true);
	?>

<?php // PULL QUOTE

	// Get quote
	$quote = wptexturize(get_post_meta($post->ID, 'quote', $single = true));
	// Get attribution
	$attribution = wptexturize(get_post_meta($post->ID, 'attribution', $single = true));

	// If post is in a series
		if($quote !== '' & $attribution !== '' & $source == '') {
		// Echo the post style
		echo '<div class="quotebox">
<p class="pullquote">' . $quote . '</p>
<br />
<p class="attribution">'. $attribution . '</p>
</div>';}
		else if($quote !== '' & $attribution !== '' & $source !== '') {
		// Echo the post style
		echo '<div class="quotebox">
<p class="pullquote">' . $quote . '</p>
<br />
<p class="attribution">'. $attribution . '&nbsp;&bull;&nbsp;<a class="source" href="' . $source . '"
		target="_blank">source</a>
</p>
</div>';}
?>

Is this possible to duplicate (or at least equivocate) in RSS?


Viewing all articles
Browse latest Browse all 20

Trending Articles