{"id":2432220,"date":"2011-12-05T22:49:32","date_gmt":"2011-12-05T22:49:32","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/need-help-with-syntax-of-conditional-category-statement\/"},"modified":"2016-08-20T03:43:20","modified_gmt":"2016-08-20T03:43:20","slug":"need-help-with-syntax-of-conditional-category-statement","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/need-help-with-syntax-of-conditional-category-statement\/","title":{"rendered":"Need help with syntax of conditional category statement"},"content":{"rendered":"<p>I&#8217;m trying to get WordPress to print out an attribution from a custom field if the post is in a category of &#8220;news&#8221;, and not otherwise. So the logic would be, &#8220;If category = &#8220;news,&#8221; print attribution (e.g., New York Times) and number of comments. Else, print only number of comments.&#8221;<\/p>\n<p>I tried this, but it didn&#8217;t work:<\/p>\n<pre><code>&lt;?php\n   if ( in_category( &#039;3&#039; )) {\n      echo &#039;From &lt;?php if ( function_exists( &#039;get_custom_field_value&#039; ) ) get_custom_field_value( &#039;Attribution&#039;, true ); ?&gt; | &lt;?php comments_popup_link(&#039;No comments&#039;, &#039;1 comment \u00bb&#039;, &#039;% comments \u00bb&#039;); ?&gt;&#039;;\n   } else {\n      echo &#039;&lt;?php comments_popup_link(&#039;No comments&#039;, &#039;1 comment \u00bb&#039;, &#039;% comments \u00bb&#039;); ?&gt;&#039;\n   }\n?&gt;<\/code><\/pre>\n<p>&#8230;but then, not being a PHP&#8217;er, I didn&#8217;t think it would. But I hope someone can tell from the kludge above what the intent was.<\/p>\n<p>Another way to do this, I think, would be to simply test if the custom field exists, and print out different lines accordingly. But I don&#8217;t know how to do that, either.<\/p>\n","protected":false},"template":"","class_list":["post-2432220","topic","type-topic","status-closed","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/2432220","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/2432220\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=2432220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}