ThemeShaper Forums » Thematic

[closed]

Displaying tag descriptions on tag archive pages

(13 posts)
  • Started 10 years ago by simonafilote
  • Latest reply from simonafilote
  • This topic is resolved
  1. Hi there,

    I'm looking for a way to display tag descriptions as page descriptions on tag archive pages, right under the page title, in a similar way to how the category descriptions are shown on the category archive pages.

    I've found some code on some other forums but wouldn't know where exactly to place it. Here it is:

    <?php if (is_tag()) { ?><?php echo tag_description(); ?><?php } ?>

    and then:

    <?php if ( is_tag() && tag_description() ) : ?>
    <meta name=”description” content=”<?php echo wp_specialchars( strip_tags( tag_description() ), 1 ); ?>” />
    <?php endif; ?>

    I would appreciate any help with this. My blog is: www.crumbs-of-life.net

    Thanks!
    Simona

    Posted 10 years ago #
  2. check out:
    http://forums.themeshaper.com/topic/tip-modify-thematic-page-title

    you could trim the filter down so that it is only for is_tag()

    Posted 10 years ago #
  3. This helps, thanks Helga.

    Posted 10 years ago #
  4. please post your final solution and mark the thread as resolved.

    Posted 10 years ago #
  5. Sure Helga. So what I've done is I copied the 'thematic_page_title' function in my child theme functions.php and only adjusted the is_tag, because I wanted to keep the rest of the function as it was.

    I'm still playing with the CSS to see how I can bring the tag title and tag description text on the same line and right next to each other, without any space gaps between them.

    function childtheme_page_title() {
    
    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:', '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 .= '<div class="archive-head">';/*Same deal*/
    				$content .= '<h1 class="page-title">';
    $content .= __('Tag Archives:', 'thematic');
    			        $content .= ' <span>';
    				$content .= single_tag_title('', FALSE);
    				$content .= '</span></h1>';
    				$content .= '<div class="archive-meta">';
    				if ( !(''== tag_description()) ) : $content .= apply_filters('archive_meta', tag_description()); endif;
    				$content .= '</div></div>' . "\n";
    		} 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>';
    		}
    
    			return $content;
    		}
    add_filter('thematic_page_title', 'childtheme_page_title');
    Posted 10 years ago #
  6. if you are only change the is_tag() section that's the only part you need in your filter

    function childtheme_page_title($content) { /*pass the variable into the function like this and you don't need to recreate the entire function*/
    
      if (is_tag()) {
    	$content .= '<div class="archive-head">';/*Same deal*/
    	$content .= '<h1 class="page-title">';
            $content .= __('Tag Archives:', 'thematic');
    	$content .= ' <span>';
    	$content .= single_tag_title('', FALSE);
    	$content .= '</span></h1>';
    	$content .= '<div class="archive-meta">';
    	if ( !(''== tag_description()) ) : $content .= apply_filters('archive_meta', tag_description()); endif;
    	$content .= '</div></div>' . "\n";
      }
      return $content; /*sends back the modified version if is_tag() was true.  otherwise sends back the unchanged variable from thematic_page_title*/
    }
    add_filter('thematic_page_title', 'childtheme_page_title');
    Posted 10 years ago #
  7. Thanks for that, Helga, this comes in handy - I was actually wondering if there was a way to avoid repeating the parts of the function I don't need to alter.

    In the mean time, I realised I need to change 'is_category' too. Would it work adding the category-related code like I've done below?

    Then, I wanted to add a dash and a space between the tag title (page title) and the tag description. The way I've placed the dash in the code below makes the dash appear after the tag title even when there isn't a tag description defined, which is what I'd like to avoid. Where would I have to place the dash in the code to achieve that?

    function childtheme_page_title($content) { /*pass the variable into the function like this and you don't need to recreate the entire function*/
    
      if (is_tag()) {
    	$content .= '<div class="archive-head">';/*Same deal*/
    	$content .= '<h1 class="page-title">';
            $content .= __('Tag Archives:', 'thematic');
    	$content .= ' <span>';
    	$content .= single_tag_title('', FALSE);
    	$content .= '</span> -&nbsp </h1>';
    	$content .= '<div class="archive-meta">';
    	if ( !(''== tag_description()) ) : $content .= apply_filters('archive_meta', tag_description()); endif;
    	$content .= '</div></div>' . "\n";
      }
    
       elseif (is_category()) {
    	$content .= '<h1 class="page-title">';
    	$content .= __('Category:', 'thematic');
    	$content .= ' <span>';
    	$content .= single_cat_title('', FALSE);
    	$content .= '</span> -&nbsp  </h1>' . "\n";
    	$content .= '<div class="archive-meta">';
    		if ( !(''== category_description()) ) : $content .= apply_filters('archive_meta', category_description()); endif;
    
        return $content; /*sends back the modified version if is_tag() was true.  otherwise sends back the unchanged variable from thematic_page_title*/
    }
    add_filter('thematic_page_title', 'childtheme_page_title');
    Posted 10 years ago #
  8. in the condition that checks for the presence of the description

    if ( !(''== tag_description()) ) : $content .= '<span> -&nbsp </span>' . apply_filters('archive_meta', tag_description()); endif;
    Posted 10 years ago #
  9. Ah. I see. However, this caused a line break and the tag description fell off on the next line...

    Posted 10 years ago #
  10. maybe you have spans set to display as blocks. if you don't already use it, you should be using www.getfirebug.com to solve issues like this. also, there is no reason you have to wrap the dash in a span element.

    Posted 10 years ago #
  11. I've now removed the span element, but that didn't fix the line break. I'm using Firebug, but in this case I'm not really sure what I should be looking for.

    I'm looking at this page for example, it shows entries tagged as 'actors church' and has a tag description which went on the next line after adding "&nbsp-&nbsp" (in the code below). I'm probably asking a silly question, but how do I figure if I have spans set to display as blocks?

    http://crumbs-of-life.net/tag/actors-church/

    if ( !(''== tag_description()) ) : $content .= '&nbsp-&nbsp' . apply_filters('archive_meta', tag_description()); endif;

    Posted 10 years ago #
  12. h1 (class="page-title") and div (class="archive-meta") and both block level elements that always generate a new line unless you alter them w/ CSS. i think ridgely provides some style css in the link i posted earlier

    Posted 10 years ago #
  13. Actually, I managed to keep them together by using the display: inline element.
    Thanks for all your help, Helga.

    Posted 10 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.