Community Forums › Forums › Archived Forums › Design Tips and Tricks › Conditionally remove Post Info by Category
- This topic has 8 replies, 2 voices, and was last updated 10 years, 11 months ago by Brad Dalton.
-
AuthorPosts
-
May 8, 2013 at 12:26 pm #39931achase409Member
I want to remove post info on all posts & category archives except for the 'News' category. I can do it easily in the CSS, but I am wondering why my PHP function is not accomplishing this task.
Here is my code:
`add_action('genesis_before_post_content','remove_info_by_category');function remove_info_by_category() {
if ( !is_category('News') || !in_category('News') ) {
remove_action( 'genesis_before_post_content', 'genesis_post_info' );
}
}
`I am using the Executive Theme. Any advice?
May 8, 2013 at 12:57 pm #39936Brad DaltonParticipantI wrote this for you and tested it:
Code not displaying? Grab it on Github.
Copy the view raw link and paste the code at the end fo your child themes functions.php file using a text editor like Notepad++.
You could also use the category i.d rather than the category name which is safer.
In this case we're using a filter rather than adding an action.
May 8, 2013 at 1:24 pm #39940achase409MemberThanks for the reply braddalton. I tried using your function, and it is still not working for me. The post info displays on the news posts, which is good, but it also displays on other categories as well even though the function is excluding them. I have tried adding a filter as well as an action. Neither of them have worked. I have come to the conclusion that the theme for whatever reason just doesn't support displaying post info conditionally. It's either on all or on none.
Any other ideas/suggestions??
May 8, 2013 at 1:29 pm #39941Brad DaltonParticipantWorked fine for me using the Genesis Sample theme.
Could you please link to you site and i'll find out what the problem is.
Just tested my code on the Executive theme and it works perfectly.
Must be a conflict somewhere in your code.
May 8, 2013 at 1:39 pm #39942achase409MemberOkay, here is the site:
I will unhide the post info in my CSS until you msg me back. Here is a link to a test post that is in the category 'test': http://gregthompsonmediator.com/this-is-a-test-post-3/
May 8, 2013 at 1:46 pm #39947achase409MemberThe only other place in the functions file that 'post_info' is referenced is in this filter:
<code>
/** Customize the post info function */
add_filter( 'genesis_post_info', 'post_info_filter' );
function post_info_filter($post_info) {
if (!is_page()) {
$post_info = '
<div class=\'date-info\'>' .
__('posted on', 'executive' ) .
' [post_date format="F j, Y" before="<span class=\'date\'>" after="</span>"] ' .
__('by', 'executive' ) . ' [post_author_posts_link] [post_edit]
</div>
<div class="comments">
[post_comments]
</div>';
return $post_info;
}
}</code>May 8, 2013 at 2:29 pm #39957Brad DaltonParticipantMay 8, 2013 at 2:43 pm #39962achase409MemberI removed the function from my previous post, and added the one you wrote. The results are still unchanged. The post info is displaying on all categories, regardless of the conditions that are declared within the function.
I spoke with my co-worker, and we think that some of the plugins we have installed may be preventing the function from working. The suspect is:'Download Manager' which uses custom post types.
Thoughts on this?
May 8, 2013 at 3:06 pm #39965Brad DaltonParticipantDeactivate all plugins and see if this works. You can then reactive them one by one to find the problem plugin.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.