WordPress.org

Ready to get started?Download WordPress

Forums

Different Title for Each Category (1 post)

  1. jpfieber
    Member
    Posted 6 years ago #

    I like to have my page titles customized to display differently than the actual database title. I don't know a heck of a lot of PHP, but so far I've used the following, I'm sure it can be optimized for better performance:

    <?php if (in_category(12)) { ?>ITsVISTA KB-Link: <?php } ?>
    <?php if (in_category(18)) { ?>ITsVISTA Adobe KB-Link: <?php } ?>
    <?php if (in_category(19)) { ?>ITsVISTA AutoDesk KB-Link: <?php } ?>
    <?php if (in_category(21)) { ?>ITsVISTA Novell TID-Link: <?php } ?>
    <?php if (in_category(22)) { ?>ITsVISTA ATI KB-Link: 737-<?php } ?>
    <?php if (in_category(14) || in_category(15)) { ?>Vista's <?php } ?>
    <?php the_title(); ?>
    <?php if (in_category(14)) { ?> Command<?php } ?>
    <?php if (in_category(15)) { ?> Service<?php } ?>

    I tried different variations on the following with no luck:


    <?php
    $post = $wp_query->post;
    if ( in_category('12') ) {
    $title = "ITsVISTA KB-Link: " . the_title();
    } elseif ( in_category('14') ) {
    $title = "Vista's " . the_title() . " Command";
    } elseif ( in_category('15') ) {
    $title = "Vista's " . the_title() . " Service";
    } elseif ( in_category('18') ) {
    $title = "ITsVISTA Adobe KB-Link: " . the_title();
    } elseif ( in_category('19') ) {
    $title = "ITsVISTA AutoDesk KB-Link: " . the_title();
    } elseif ( in_category('21') ) {
    $title = "ITsVISTA Novell TID-Link: " . the_title();
    } elseif ( in_category('22') ) {
    $title = "ITsVISTA ATI KB-Link: 737-" . the_title();
    } else {
    $title = the_title();
    }
    echo $title;
    ?>

    Anyone willing to give me some pointers on the most efficient way to accomplish my goal (full control over the displayed titles with as little hit on performance as possible)?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.