ThemeShaper Forums » Thematic

[closed]

Filtering Thematic_page_title

(9 posts)
  • Started 2 years ago by Andrew
  • Latest reply from umberto
  • This topic is resolved
  1. Hi Guys,
    I need a little syntax help with how to properly filter the Thematic_page_title function.
    I'd like to modify the page titles of the category loop to not say 'Category Archives:' Category Name. But just to read the Category Name itself or to have the parent category name (Community in this case) outputted beforehand.

    I started searching here and found reference to Ian's article here..
    http://themeshaper.com/2009/05/03/filters-wordpress-child-themes/

    And I got soo excited thinking how I can get this working by myself. But in the end the Thematic_page_title function is pretty darn big, filled with lots of if statements and it doesn't have a specific variable for Category Page titles.. Soo.. I think the only way I can filter it is to pass the whole function..

    The original Thematic_page_title looks like this...

    function thematic_page_title() {
    
    		global $post;
    
    		$content = '';
    		if (is_attachment()) {
    				$content .= '<h2 class="page-title"><a href="';
    				$content .= apply_filters('the_permalink',get_permalink($post->post_parent));
    				$content .= '" rev="attachment"><span class="meta-nav">&laquo; </span>';
    				$content .= get_the_title($post->post_parent);
    				$content .= '</a></h2>';
    		} elseif (is_author()) {
    				$content .= '<h1 class="page-title author">';
    				$author = get_the_author_meta( 'display_name' );
    				$content .= __('Author Archives: ', 'thematic');
    				$content .= '<span>';
    				$content .= $author;
    				$content .= '</span></h1>';
    		} elseif (is_category()) {
    				$content .= '<h1 class="page-title">';
    				$content .= __('Category Archives:', 'thematic');
    				$content .= ' <span>';
    				$content .= single_cat_title('', FALSE);
    				$content .= '</span></h1>' . "\n";
    				$content .= '<div class="archive-meta">';
    				if ( !(''== category_description()) ) : $content .= apply_filters('archive_meta', category_description()); endif;
    				$content .= '</div>';
    		} elseif (is_search()) {
    				$content .= '<h1 class="page-title">';
    				$content .= __('Search Results for:', 'thematic');
    				$content .= ' <span id="search-terms">';
    				$content .= esc_html(stripslashes($_GET['s']));
    				$content .= '</span></h1>';
    		} elseif (is_tag()) {
    				$content .= '<h1 class="page-title">';
    				$content .= __('Tag Archives:', 'thematic');
    				$content .= ' <span>';
    				$content .= __(thematic_tag_query());
    				$content .= '</span></h1>';
    		} elseif (is_tax()) {
    			    global $taxonomy;
    				$content .= '<h1 class="page-title">';
    				$tax = get_taxonomy($taxonomy);
    				$content .= $tax->labels->name . ' ';
    				$content .= __('Archives:', 'thematic');
    				$content .= ' <span>';
    				$content .= thematic_get_term_name();
    				$content .= '</span></h1>';
    		}	elseif (is_day()) {
    				$content .= '<h1 class="page-title">';
    				$content .= sprintf(__('Daily Archives: <span>%s</span>', 'thematic'), get_the_time(get_option('date_format')));
    				$content .= '</h1>';
    		} elseif (is_month()) {
    				$content .= '<h1 class="page-title">';
    				$content .= sprintf(__('Monthly Archives: <span>%s</span>', 'thematic'), get_the_time('F Y'));
    				$content .= '</h1>';
    		} elseif (is_year()) {
    				$content .= '<h1 class="page-title">';
    				$content .= sprintf(__('Yearly Archives: <span>%s</span>', 'thematic'), get_the_time('Y'));
    				$content .= '</h1>';
    		} elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {
    				$content .= '<h1 class="page-title">';
    				$content .= __('Blog Archives', 'thematic');
    				$content .= '</h1>';
    		}
    		$content .= "\n";
    		echo apply_filters('thematic_page_title', $content);

    I brought in the entirety of thematic_page_title and once I did so, the category page titles disappeared completely. I turned the value for single_cat_title to TRUE and added the parent category name manually 'Community: '. And this seems to work (http://www.tendercarevets.com/wp/category/community/testimonials/) BUT I've lost the <h1> markup around the title and it just is dropped in there all by itself.

    Here's the code...

    function remove_cat_titles() {
      function remove_cat_titles() {
    	global $post;
    
    		$content = '';
    		if (is_attachment()) {
    				$content .= '<h2 class="page-title"><a href="';
    				$content .= apply_filters('the_permalink',get_permalink($post->post_parent));
    				$content .= '" rev="attachment"><span class="meta-nav">&laquo; </span>';
    				$content .= get_the_title($post->post_parent);
    				$content .= '</a></h2>';
    		} elseif (is_author()) {
    				$content .= '<h1 class="page-title author">';
    				$author = get_the_author_meta( 'display_name' );
    				$content .= __('Author Archives: ', 'thematic');
    				$content .= '<span>';
    				$content .= $author;
    				$content .= '</span></h1>';
    		} elseif (is_category()) {
    				$content .= '<h1 class="page-title">';
    				$content .= __('Category Archives:', 'thematic');
    				$content .= ' <span>';
    				$content .= single_cat_title('Community: ', TRUE);// CHANGED THIS TO TRUE
    				$content .= '</span></h1>' . "\n";
    				$content .= '<div class="archive-meta">';
    				if ( !(''== category_description()) ) : $content .= apply_filters('archive_meta', category_description()); endif;
    				$content .= '</div>';
    		} elseif (is_search()) {
    				$content .= '<h1 class="page-title">';
    				$content .= __('Search Results for:', 'thematic');
    				$content .= ' <span id="search-terms">';
    				$content .= esc_html(stripslashes($_GET['s']));
    				$content .= '</span></h1>';
    		} elseif (is_tag()) {
    				$content .= '<h1 class="page-title">';
    				$content .= __('Tag Archives:', 'thematic');
    				$content .= ' <span>';
    				$content .= __(thematic_tag_query());
    				$content .= '</span></h1>';
    		} elseif (is_tax()) {
    			    global $taxonomy;
    				$content .= '<h1 class="page-title">';
    				$tax = get_taxonomy($taxonomy);
    				$content .= $tax->labels->name . ' ';
    				$content .= __('Archives:', 'thematic');
    				$content .= ' <span>';
    				$content .= thematic_get_term_name();
    				$content .= '</span></h1>';
    		}	elseif (is_day()) {
    				$content .= '<h1 class="page-title">';
    				$content .= sprintf(__('Daily Archives: <span>%s</span>', 'thematic'), get_the_time(get_option('date_format')));
    				$content .= '</h1>';
    		} elseif (is_month()) {
    				$content .= '<h1 class="page-title">';
    				$content .= sprintf(__('Monthly Archives: <span>%s</span>', 'thematic'), get_the_time('F Y'));
    				$content .= '</h1>';
    		} elseif (is_year()) {
    				$content .= '<h1 class="page-title">';
    				$content .= sprintf(__('Yearly Archives: <span>%s</span>', 'thematic'), get_the_time('Y'));
    				$content .= '</h1>';
    		} elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {
    				$content .= '<h1 class="page-title">';
    				$content .= __('Blog Archives', 'thematic');
    				$content .= '</h1>';
    		}
    		$content .= "\n";
    }
    add_filter('thematic_page_title','remove_cat_titles');

    Any tips on getting back the <h1> markup would be much appreciated.
    Thanks!

    Posted 2 years ago #
  2. kwight
    Member

    Hi Andrew,

    You're kind of mixing methods (child theme overrides and filter hooks). To start with the entire function and change it (as you have here), create childtheme_override_page_title() and change the parts you want:

    function childtheme_override_page_title() {
    
    	// paste original function contents and edit to please
    
    }

    If Thematic finds this function, it will use it instead of thematic_page_title.

    Filters require something coming in, which gets manipulated and then spit out ("returned") again:

    function kwight_change_category_title($content) {
    	global $post;
    	if (is_category()) {
    		$content = '<h1 class="page-title">';
    		$content .= __('Community:', 'thematic');
    		$content .= ' <span>';
    		$content .= single_cat_title('', FALSE);
    		$content .= '</span></h1>' . "\n";
    		$content .= '<div class="archive-meta">';
    		if ( !(''== category_description()) ) : $content .= apply_filters('archive_meta', category_description()); endif;
    		$content .= '</div>';
    	}
    	return $content;
    }
    add_filter('thematic_page_title','kwight_change_category_title');

    Check out these links for more info:

    http://codex.wordpress.org/Plugin_API
    http://themeshaper.com/modify-wordpress-themes/

    This is all untested, but I think it's right...

    Posted 2 years ago #
  3. boden
    Member

    If I'm following your intentions properly, I think there's a quick a dirty way to do this like shown below.

    function massage_cat_title($content) {
    if ($content != NULL) {
    return str_replace('Category Archives:', '', $content);
    }
    return $content;

    }
    add_filter('thematic_page_title', 'massage_cat_title', $content);

    This is not the most elegant way to solve the problem, but it should do the trick. Obviously if subsequent releases of thematic change the string 'Category Archive:' you'd have to update the function.

    Posted 2 years ago #
  4. this was a good post about modifying the output and look of the page title

    http://forums.themeshaper.com/topic/tip-modify-thematic-page-title

    Posted 2 years ago #
  5. HI Everyone, Thanks alot for you super helpful responses. Seems like I have all I need here.

    Kwight, I do have a question for you. Is the 'childtheme_overide' a specific function native to thematic, and can it be applied to all actions? It doesn't have to be executed (ie add_action) but just placed like your above example into the child functions PHP?
    Your links were helpful in helping me clarify the role of actions and hooks, but if this is some special overide function I'd love to put it into action.

    It seems like these $content values at the start and end of my code

    $content = '';
    $content .= "\n";

    were partly what was messing up my former code?

    Posted 2 years ago #
  6. andrew- those two bits just mean that you are setting $content equal to a null string in the beginning.. so that you can add on as you will. the end is just a line break.

    i think the part that may have been tripping you was:
    function remove_cat_titles() {
    function remove_cat_titles() {

    also you were using add_filter without returning any value... see kwight's example.

    childtheme_override is specific to thematic. there are a lot of functions that first check if the override function exists and preferentially runs that. failing the presence of the override thematic will run it's default function. take a look around in the library/extensions folder to see where this is available

    Posted 2 years ago #
  7. kwight
    Member

    There's also a list of all the child theme overrides here:

    http://kirkwight.com/thematic/thematic_overrides.txt

    Posted 2 years ago #
  8. Woah, That was a little bit of a slip.. :-)

    function remove_cat_titles() {
    function remove_cat_titles() {

    Thanks so much Helga for clarifying the Thematic child theme overides, I had no idea this existed and I'll be happy to investigate it further.
    And thanks Kwight for the list of all the overrides. Super handy.

    I look forward to be able to help in this community a little more as my knowledge gets to a basic level :-)

    Posted 2 years ago #
  9. umberto
    Member

    I'm still getting to grips with filtering and overriding but overrides don't seem to work without a 'return' line eg (this removes the 'published' before the date):

    function childtheme_override_postmeta_entrydate() {
    
    	    $entrydate = '<span class="meta-prep meta-prep-entry-date">' . __(' ', 'thematic') . '</span>';
    	    $entrydate .= '<span class="entry-date"><abbr class="published" title="';
    	    $entrydate .= get_the_time(thematic_time_title()) . '">';
    	    $entrydate .= get_the_time(thematic_time_display());
    	    $entrydate .= '</abbr></span>';
    
    	    return $entrydate;
    	    }

    Snip out the return $entrydate; and it removes the whole of the postmeta entrydate.

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.