Conditionally remove Post Info by Category

Community Forums Forums Design Tips and Tricks Conditionally remove Post Info by Category

This topic is: not resolved

This topic contains 8 replies, has 2 voices, and was last updated by  braddalton 1 year, 5 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #39931

    achase409
    Participant
    Post count: 16

    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?

    • This topic was modified 1 year, 5 months ago by  achase409.
    • This topic was modified 1 year, 5 months ago by  achase409.
    • This topic was modified 1 year, 5 months ago by  achase409.
    • This topic was modified 1 year, 5 months ago by  achase409.
    #39936

    braddalton
    Participant
    Post count: 10217

    I 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.


    #39940

    achase409
    Participant
    Post count: 16

    Thanks 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??

    #39941

    braddalton
    Participant
    Post count: 10217

    Worked 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.


    #39942

    achase409
    Participant
    Post count: 16

    Okay, here is the site:

    gregthompsonmediator.com

    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/

    • This reply was modified 1 year, 5 months ago by  achase409.
    • This reply was modified 1 year, 5 months ago by  achase409.
    • This reply was modified 1 year, 5 months ago by  achase409.
    • This reply was modified 1 year, 5 months ago by  achase409.
    #39947

    achase409
    Participant
    Post count: 16

    The 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>

    • This reply was modified 1 year, 5 months ago by  achase409.
    • This reply was modified 1 year, 5 months ago by  achase409.
    • This reply was modified 1 year, 5 months ago by  achase409.
    • This reply was modified 1 year, 5 months ago by  achase409.
    #39957

    braddalton
    Participant
    Post count: 10217

    Remove that PHP code please and it should be working fine then.


    #39962

    achase409
    Participant
    Post count: 16

    I 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?

    #39965

    braddalton
    Participant
    Post count: 10217

    Deactivate all plugins and see if this works. You can then reactive them one by one to find the problem plugin.


Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.