ThemeShaper Forums » Thematic

[closed]

What's wrong with this postfooter code??

(5 posts)
  • Started 4 years ago by Seijun
  • Latest reply from Seijun
  • This topic is resolved
  1. I just want the comments and permalink info removed from the post footer.

    // New PostFooter
    function replacement_postfooter($postfooter) {
        global $id, $post;
    
        if ($post->post_type == 'page' && current_user_can('edit_posts')) { /* For logged-in "page" search results */
            $postfooter = '<div class="entry-utility">' . thematic_postfooter_posteditlink();
            $postfooter .= "</div><!-- .entry-utility -->\n";
        } elseif ($post->post_type == 'page') { /* For logged-out "page" search results */
            $postfooter = '';
        } else {
            if (is_single()) {
                $postfooter = '<div class="entry-utility">' . thematic_postfooter_postcategory() . thematic_postfooter_posttags();
            } else {
                $postfooter = '<div class="entry-utility">' . thematic_postfooter_postcategory() . thematic_postfooter_posttags();
            }
            $postfooter .= "</div><!-- .entry-utility -->\n";
    		return $postfooter;
        }
    
        // Put it on the screen
        echo apply_filters( 'replacement_postfooter', $postfooter ); // Filter to override default post footer
    }

    This does not work (permalink and comment info remains), but I have a feeling there is just something wrong with my "put it on the screen" part, but I don't know what that would be. Help, please?

    Posted 4 years ago #
  2. Hi Seijun,

    this is the problem:

    echo apply_filters( 'replacement_postfooter', $postfooter ); // Filter to override default post footer

    The apply_filters belongs only inside the parent function. A child theme would use add_filter outside of the function like so:

    // New PostFooter
    function replacement_postfooter($postfooter) {
        global $id, $post;
    
        if ($post->post_type == 'page' && current_user_can('edit_posts')) { /* For logged-in "page" search results */
            $postfooter = '<div class="entry-utility">' . thematic_postfooter_posteditlink();
            $postfooter .= "</div><!-- .entry-utility -->\n";
        } elseif ($post->post_type == 'page') { /* For logged-out "page" search results */
            $postfooter = '';
        } else {
            if (is_single()) {
                $postfooter = '<div class="entry-utility">' . thematic_postfooter_postcategory() . thematic_postfooter_posttags();
            } else {
                $postfooter = '<div class="entry-utility">' . thematic_postfooter_postcategory() . thematic_postfooter_posttags();
            }
            $postfooter .= "</div><!-- .entry-utility -->\n";
            return $postfooter;
        }
    }
    add_filter('thematic_postfooter','replacement_postfooter');
    Posted 4 years ago #
  3. Thanks.
    Now I've run into a different problem. I'm trying to remove the postfooter only on certain categories. I added this

    // Remove thematic_postfooter
    function remove_postfooter() {
     // We test if we are on the category with id 16, 7, 6, 8, 9, 17, or 13
     if (is_category(array('16','7','6','8','9','17','13'))) {
     // Yes, we are .. now we switch off the postfooter
     return FALSE;
     } else {
     // We are not .. we leave the switch on
     return TRUE;
     }
    }
    // Connect the filter to thematic_postfooter()
    add_filter('thematic_postfooter', 'remove_postfooter');

    Which does remove the postfooter from posts in those categories, but in the categories where the footer is supposed to show, it is replaced with a solitary "1".

    Posted 4 years ago #
  4. The boolean is not necessary. You need to pass on the value of the filter function.

    function remove_postfooter($thm_footer) {
     // We test if we are on the category with id 16, 7, 6, 8, 9, 17, or 13
     if (is_category(array('16','7','6','8','9','17','13'))) {
     // Yes, we are .. return nothing
     return;
     } else {
     // We are not .. return the original value from thematic_postfooter()
     return $thm_footer;
     }
    }
    // Connect the filter to thematic_postfooter()
    add_filter('thematic_postfooter', 'remove_postfooter');
    Posted 4 years ago #
  5. Thanks. Never would have guessed that in a million years (im one of those people who writes php by copying stuff on the forum that looks similar and then trying to squish other code into it). In this case I was going off of a piece of code that gets rid of the sidebar on certain pages.

    Posted 4 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.