Forums

[resolved] conditional post title (6 posts)

  1. Begin
    Member
    Posted 1 year ago #

    I want to tell my site in the <title></title> section:

    if your showing a post that is in a sub category of the category '9'
    make the page title "title1", but if it's not (on any other page on the site)
    make the page title "title2".

    How can I do it?

    Thank's!!!

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    http://codex.wordpress.org/Conditional_Tags
    http://codex.wordpress.org/Function_Reference/get_categories

    <?php $subs = get_categories('parent=9');
    $sub_ids = array();
    if( $subs ) foreach( $subs as $sub ) { $sub_ids[] = $sub->term_id; }
    if( is_single() && in_category( $sub_ids ) ) : ?>
    <title>title2<.title>
    <?php else : ?>
    <title>title2</title>
    <?php endif; ?>
  3. Begin
    Member
    Posted 1 year ago #

    Oh Great! it work's perfect! Thank's :-)

    I did try those articles, but could not get it... :=P I don't realy know php..
    Thank you very much!

    is there a way to insert another conditional that says if your showing
    one of the sub categories them self (not a post inside them) make the
    title "title 3"?

    thank you very much anyway!

  4. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    if your showing
    one of the sub categories them self

    to make it work for the category archives of these sub categories,
    keep the top three lines, and change here:

    if( is_single() && in_category( $sub_ids ) ) : ?>
    <title>title2<.title>
    <?php elseif( is_category( $sub_ids ) ) : ?>
    <title>title3</title>
    <?php else : ?>
    <title>title2</title>
    <?php endif; ?>
  5. Begin
    Member
    Posted 1 year ago #

    Wow That's great!!!!! Thank you very very much!

    You really helped me so much!

  6. ahkar83
    Member
    Posted 11 months ago #

    hello...

    I have 2 related questions...really appreciate your feedbacks..thanks!

    #1) Where exactly do i put the 2 above codes?

    #2) I would like to put the Specific Tags in front of their respective posts...

    for example: if a post is about car title is "best car of the year".. i'd like to display: "Cars: - best car of the year" .. something like this.. btw...I'm pulling rss feeds for this 2nd purpose.

    Please advise.. thanks!!!!!!!

Topic Closed

This topic has been closed to new replies.

About this Topic