<?xml version="1.0" encoding="UTF-8"?><!-- generator="bbPress" -->

<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
>

<channel>
<title>ThemeShaper Forums Topic: Add post_meta custom field data only when fields are true</title>
<link>http://themeshaper.com/forums/</link>
<description>Help In Shaping WordPress Themes</description>
<language>en</language>
<pubDate>Thu, 23 May 2013 06:56:56 +0000</pubDate>

<item>
<title>candregg on "Add post_meta custom field data only when fields are true"</title>
<link>http://themeshaper.com/forums/topic/add-post_meta-custom-field-data-only-when-fields-are-true#post-22098</link>
<pubDate>Thu, 30 Jun 2011 16:34:23 +0000</pubDate>
<dc:creator>candregg</dc:creator>
<guid isPermaLink="false">22098@http://themeshaper.com/forums/</guid>
<description>&#60;p&#62;For the most part, that worked like a charm: &#60;a href=&#34;http://seacliffmm.com/prod/centurion/clients-testimonials/build-a-bear-workshop/.&#34; rel=&#34;nofollow&#34;&#62;http://seacliffmm.com/prod/centurion/clients-testimonials/build-a-bear-workshop/.&#60;/a&#62;  One remaining issue is that the &#38;#38;sponsorlink call is generating an extra character string, %3e, that is messing up the actual sponsor's links.  Any idea where that's coming from?&#60;/p&#62;
&#60;p&#62;Other than that, it's beautiful.  I knew some kind of conditional test was the answer; I just kept messing up the syntax for so many hours that I got frustrated.  Thanks for demonstrating it so clearly.&#60;/p&#62;
&#60;p&#62;Yes, I've seen the function childtheme_override_category_loop() in the newer version of thematic, but have not (until now) had occasion to use it.&#60;/p&#62;
&#60;p&#62;Will file your magic and tips for future use.
&#60;/p&#62;</description>
</item>
<item>
<title>helgatheviking on "Add post_meta custom field data only when fields are true"</title>
<link>http://themeshaper.com/forums/topic/add-post_meta-custom-field-data-only-when-fields-are-true#post-22086</link>
<pubDate>Wed, 29 Jun 2011 21:26:53 +0000</pubDate>
<dc:creator>helgatheviking</dc:creator>
<guid isPermaLink="false">22086@http://themeshaper.com/forums/</guid>
<description>&#60;p&#62;&#34;if I apply it globally&#34;&#60;/p&#62;
&#60;p&#62;does that mean you tried filtering the_content()?&#60;/p&#62;
&#60;p&#62;which is what i'd do and just add in a condition to test if $sponsortext exists&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;function add_after_content($content) {

  global $post;
  $sponsortext = get_post_meta($post-&#38;gt;ID , &#38;#39;sponsor&#38;#39;, true);
  $sponsorlink = get_post_meta($post-&#38;gt;ID , &#38;#39;sponsorlink&#38;#39;, true);

  if($sponsortext &#38;#38;&#38;#38; $sponsorlink){
    $sponsor = &#38;#39;&#38;lt;div id=&#38;quot;sponsor&#38;quot;&#38;gt;&#38;#39;;
    $sponsor .= &#38;#39;&#38;lt;p&#38;gt;&#38;#39;. $sponsortext.&#38;#39;&#38;lt;/p&#38;gt;&#38;#39;;
    $sponsor .= &#38;#39;&#38;lt;p&#38;gt;For more information visit the website, &#38;lt;a href=&#38;quot;http://&#38;#39;.$sponsorlink.&#38;#39;&#38;gt;&#38;quot; target=&#38;quot;_blank&#38;quot;&#38;gt;http://&#38;#39;.$sponsorlink.&#38;#39;&#38;lt;/a&#38;gt;&#38;lt;/p&#38;gt;&#38;#39;;
    $sponsor .= &#38;#39;&#38;lt;/div&#38;gt;&#38;#39;;

    $content .= $sponsor ;
  }
  return $content;
}
add_filter(&#38;#39;the_content&#38;#39;, add_after_content);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;totally untested, you might need to escape the backslashes... i'm not sure, but i think the concept is right.  &#60;/p&#62;
&#60;p&#62;ps- you can now use &#60;/p&#62;
&#60;p&#62;function childtheme_override_category_loop() &#60;/p&#62;
&#60;p&#62;and you don't need to add or remove any actions.  it's magic.
&#60;/p&#62;</description>
</item>
<item>
<title>candregg on "Add post_meta custom field data only when fields are true"</title>
<link>http://themeshaper.com/forums/topic/add-post_meta-custom-field-data-only-when-fields-are-true#post-22084</link>
<pubDate>Wed, 29 Jun 2011 20:58:55 +0000</pubDate>
<dc:creator>candregg</dc:creator>
<guid isPermaLink="false">22084@http://themeshaper.com/forums/</guid>
<description>&#60;p&#62;I'm a relative noob trying to filter post content selectively.  &#60;/p&#62;
&#60;p&#62;In my installation, only posts in one category include the custom fields &#34;sponsor text&#34; and &#34;sponsor link&#34;.&#60;/p&#62;
&#60;p&#62;If I create a custom category loop by category, the custom fields do not show up in single posts; if I apply it globally, then the special div to hold the meta data appears on ALL posts, even where the custom field data doesn't exist.&#60;/p&#62;
&#60;p&#62;Here is the global function:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;//  Custom Category Loop 

function remove_category_loop(){ //  first remove the thematic action
    remove_action(&#38;#39;thematic_categoryloop&#38;#39;, &#38;#39;thematic_category_loop&#38;#39;);
    remove_action(&#38;#39;thematic_archiveloop&#38;#39;, &#38;#39;thematic_archive_loop&#38;#39;);
}
add_action(&#38;#39;init&#38;#39;,&#38;#39;remove_category_loop&#38;#39;);

function child_category_loop() { // now rebuild your version of the action

 while (have_posts()) : the_post();

	 global $post;
     $sponsortext = get_post_meta($post-&#38;gt;ID , &#38;#39;sponsor&#38;#39;, true);
	 $sponsorlink = get_post_meta($post-&#38;gt;ID , &#38;#39;sponsorlink&#38;#39;, true);
	 ?&#38;gt;

        &#38;lt;div id=&#38;quot;post-&#38;lt;?php the_ID(); ?&#38;gt;&#38;quot; class=&#38;quot;&#38;lt;?php thematic_post_class(); ?&#38;gt;&#38;quot;&#38;gt;
           &#38;lt;?php thematic_postheader(); ?&#38;gt;
           &#38;lt;div class=&#38;quot;entry-content&#38;quot;&#38;gt;
             &#38;lt;?php thematic_content(); ?&#38;gt;
             &#38;lt;div id=&#38;quot;sponsor&#38;quot;&#38;gt;
	&#38;lt;p&#38;gt;&#38;lt;?php echo $sponsortext; ?&#38;gt;&#38;lt;/p&#38;gt;
    &#38;lt;p&#38;gt;For more information visit the website, &#38;lt;a href=&#38;quot;http://&#38;lt;?php echo $sponsorlink; ?&#38;gt;&#38;quot; target=&#38;quot;_blank&#38;quot;&#38;gt;http://&#38;lt;?php echo $sponsorlink; ?&#38;gt;&#38;lt;/a&#38;gt;&#38;lt;/p&#38;gt;
    &#38;lt;/div&#38;gt;
           &#38;lt;/div&#38;gt;
           &#38;lt;?php thematic_postfooter(); ?&#38;gt;
        &#38;lt;/div&#38;gt;&#38;lt;!-- .post --&#38;gt;

     &#38;lt;?php endwhile;
}

add_action(&#38;#39;thematic_categoryloop&#38;#39;, &#38;#39;child_category_loop&#38;#39;);
add_action(&#38;#39;thematic_archiveloop&#38;#39;, &#38;#39;child_category_loop&#38;#39;);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;This code works great for the one category page, &#60;a href=&#34;http://seacliffmm.com/prod/centurion/category/clients-testimonials/,&#34; rel=&#34;nofollow&#34;&#62;http://seacliffmm.com/prod/centurion/category/clients-testimonials/,&#60;/a&#62;&#60;br /&#62;
But not for the general blog category page, &#60;a href=&#34;http://seacliffmm.com/prod/centurion/category/news/&#34; rel=&#34;nofollow&#34;&#62;http://seacliffmm.com/prod/centurion/category/news/&#60;/a&#62; &#60;/p&#62;
&#60;p&#62;I'm sure the answer is an if-else construction,but so far I haven't been able to code one that works.  &#60;/p&#62;
&#60;p&#62;Please advise, if possible.
&#60;/p&#62;</description>
</item>

</channel>
</rss>
