[wp-hackers] Problem with custom title tags
Jennifer Hodgdon
yahgrp at poplarware.com
Wed Feb 18 20:26:51 GMT 2009
I think your first problem may be(?) because you are using a bunch of
if() statements rather than if/elseif/elseif/etc. It's possible that
more than one of those if statements is true, and theat is where the
second name is coming from. Maybe?
The problem in your second one is that single_cat_title() only
generates the right title for category archives, not for single pages
(check the PHP doc on this function; not sure what the codex says but
if it says something different it is wrong). That function is deciding
which category to display based on the URL, such as (whatever)?cat=3
(or your permalink equivalent). You will need to use a different
function (or group thereof) to retrieve one of the categories assigned
to the post and display it in the title.
--Jennifer
Kim Parsell wrote:
> I am trying to set up custom title tags using conditional tags, and have
> run into a problem with a couple of them. Here is the code that I am
> using in header.php of the theme:
>
> --------------------------------------------------
> <title><?php if (is_front_page()) { ?><?php bloginfo('name'); ?> - <?php
> echo bloginfo ('description'); } ?>
> <?php if (is_page()) { ?> <?php bloginfo('name'); ?> <?php wp_title(' |
> ', true, 'left'); } ?>
> <?php if (is_home()) { ?><?php bloginfo('name'); ?> | Blog Posts<?php } ?>
> <?php if (is_404()) { ?><?php bloginfo('name'); ?> | Error 404 - Not
> Found<?php } ?>
> <?php if (is_category()) { ?><?php bloginfo('name'); ?> | <?php
> single_cat_title(); } ?>
> <?php if (is_single()) { ?><?php bloginfo('name'); ?> | <?php
> single_cat_title(); ?>: <?php the_title(); } ?>
> <?php if (is_day()) { ?><?php bloginfo('name'); ?> | Archives for <?php
> the_time('F j, Y'); } ?>
> <?php if (is_month()) { ?><?php bloginfo('name'); ?> | Archives for
> <?php the_time('F Y'); } ?>
> <?php if (is_year()) { ?><?php bloginfo('name'); ?> | Archives for <?php
> the_time('Y'); } ?>
> <?php if (is_search()) { ?><?php bloginfo('name'); ?> | Search Results
> for <?php the_search_query(); } ?></title>
> -------------------------------------------------
>
> The first one that I am having problems with is:
>
> <?php if (is_front_page()) { ?><?php bloginfo('name'); ?> - <?php echo
> bloginfo ('description'); } ?>
>
> This returns <title>Blog Name - Service, Support, Solutions Blog Name
> </title>. The blog name is being repeated after the description (is this
> a bug or intended behavior?).
>
> The other one I am having problems with is:
>
> <?php if (is_single()) { ?><?php bloginfo('name'); ?> | <?php
> single_cat_title(); ?>: <?php the_title(); } ?>
>
> This code returns <title>Blog Name | : Who We Are</title> - note that
> the Category title (single_cat_title) is missing.
>
> <?php if (is_category()) { ?><?php bloginfo('name'); ?> | <?php
> single_cat_title(); } ?> returns <title>Blog Name | Company
> News</title>, so single_cat_title() works properly there, but not in the
> above code for is_single().
--
Jennifer Hodgdon * Poplar ProductivityWare
www.poplarware.com
Drupal/WordPress Sites, Themes, Modules/Plugins
Custom Web Programming, Web Databases
PHP, Perl, MySQL, JavaScript, XML, AJAX
More information about the wp-hackers
mailing list