Web Design Forum: Conditional titles in WordPress - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Conditional titles in WordPress Rate Topic: -----

#1 User is online   MikeChipshop 

  • Small but imperfectly formed
  • Group: Moderators
  • Posts: 7,045
  • Joined: 19-April 10
  • Reputation: 503
  • Gender:Male
  • Location:Scotland

Posted 12 January 2012 - 06:57 PM

For some reason this is playing with my mind and i could do with a fresh pair of eyes.

Basically in plain English i'm looking to have an <h2> next to the websites title <h1> that contains different content depending on where the user is on the site, like so...

Users on homepage, author page, 404 page, 'page' or search results = Website Description
User on Post = Posts Category Name
User on Category page = Category name
User on tag page = Tag name

I was running a few conditionals but it just wasn't producing any results worth mentioning. Various problems ranging from multiple outputs of the description to no output at all!
So i've scrapped it all and am looking to the help of the one and only WDF crew!

Just FYI this was last thing i was going with which had been butchered multiple times and i sort of got lost in the process, hence the multiple "elseif's".

<?php 
    if($post->post_parent) { ?>
        <h3> 
	    <?php
	    $parent_title = get_the_title($post->post_parent);
	    echo $parent_title;
	    ?>
	</h3>
    	<?php                   	
	    } 
            elseif (is_home() ) { 
        ?>
        <h2><?php bloginfo('description'); ?></h2>
        <?php }	
	elseif ( is_search() ) { ?> 
        <h2><?php bloginfo('description'); ?></h2>
<?php } ?>

0

#2 User is online   brightonmike 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 2,996
  • Joined: 27-June 11
  • Reputation: 340
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 13 January 2012 - 09:00 AM

Tried a simple statement first? E.g

	<?php if ( is_home() ) { ?>
        <h2><?php bloginfo('description'); ?></h2>
	<?php } else { ?>
        <h2>hello margaret</h2>
	<?php } ?>

This post has been edited by brightonmike: 13 January 2012 - 09:01 AM

0

#3 User is online   MikeChipshop 

  • Small but imperfectly formed
  • Group: Moderators
  • Posts: 7,045
  • Joined: 19-April 10
  • Reputation: 503
  • Gender:Male
  • Location:Scotland

Posted 13 January 2012 - 09:05 AM

Yup. But i'm going to have another go this morning now i'm fresh.
I'm thinking of writing a one page WP theme that does everything via conditionals. Not because it would ever be a good idea but because it would accelerate the learning of conditionals for me and give me a fun (?) personal project. That is when i have the time...

Anyway i'm likely to be back here over the day trying to figure why this damn header won't work.
Any more ideas just drop 'em here.
Cheers Mike.
0

#4 User is online   Spitfire 

  • Mighty Pirate™
  • PipPipPipPip
  • Group: Members
  • Posts: 891
  • Joined: 05-February 11
  • Reputation: 189
  • Gender:Male
  • Location:Berkshire
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 13 January 2012 - 09:51 AM

Maybe something like:

<h2>
<?php
if(is_home() || is_author() || is_404() || is_search()){
   bloginfo('description');
} elseif(is_category()){
   single_cat_title();
} elseif(is_tag())
  single_tag_title();
} else {
  bloginfo('description'); //You could even just have an if functions for the category and tag, then use the else as a fallback for all the other pages like home, 404, etc...
}
?></h2>

This post has been edited by Spitfire: 13 January 2012 - 09:52 AM

1

#5 User is online   MikeChipshop 

  • Small but imperfectly formed
  • Group: Moderators
  • Posts: 7,045
  • Joined: 19-April 10
  • Reputation: 503
  • Gender:Male
  • Location:Scotland

Posted 13 January 2012 - 09:58 AM

View PostSpitfire, on 13 January 2012 - 09:51 AM, said:

Maybe something like:

<h2>
<?php
if(is_home() || is_author() || is_404() || is_search()){
   bloginfo('description');
} elseif(is_category()){
   single_cat_title();
} elseif(is_tag())
  single_tag_title();
} else {
  bloginfo('description'); //You could even just have an if functions for the category and tag, then use the else as a fallback for all the other pages like home, 404, etc...
}
?></h2>



Now this is exactly what i was doing but for some reason it either caused the description to be printed on every page as well as the other stuff or, with a little jiggling, it printed random category titles on the main page under the description :mellow:

I'm cracking on with another bit of the same site at the moment but when that's done i'll try again and post up some code.

Cheers chaps.
0

#6 User is online   MikeChipshop 

  • Small but imperfectly formed
  • Group: Moderators
  • Posts: 7,045
  • Joined: 19-April 10
  • Reputation: 503
  • Gender:Male
  • Location:Scotland

Posted 18 January 2012 - 10:40 AM

Just a quick thanks to the chaps here as i got it working. I have no idea what was going on in my mind that day!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users