Wordpress conditional is_archive() not working for custom post types

Posted on 2011-10-11
Medium Priority
Last Modified: 2012-06-27
Hey folks,
I've got two custom post types:
writer and work.
I've set up a conditional in my header so that the main title of the page can have a different class depending on whether it's front page & singular writer page have hard coded title, page and custom post type archive have dynamic titles.
The titles are working fine. But I can't seem to get different classes for the archives. The same class shows up for both depending on which one I add to the code first. For instance, if I list is_archive('work') first then both work and writers titles get the class: works-title. I'm getting better at PHP, but this one's got me stumped!

<?php if(is_front_page() OR is_singular('writer')) {
echo '<h2 class="main-title">A Place for Girls to Connect</h2>';
							} else if(is_page()) {
							echo '<h2 class="main-title page-title">'; ?>
							<?php the_title(); ?>
							<?php echo '</h2>';
							} else if(is_archive('work')) {
							echo '<h2 class="main-title works-title">'; ?>
							<?php post_type_archive_title(' ', true); ?>
							<?php echo '</h2>'; 
							} else if(is_archive('writer')) {
							echo '<h2 class="main-title writers-title">'; ?>
							<?php post_type_archive_title(' ', true); ?>
							<?php echo '</h2>';

Open in new window

Question by:Alicia St Rose
  • 2

Accepted Solution

Alicia St Rose earned 0 total points
ID: 36951531
figured this out.
I don't use is_archive(). I use is_post_type_archive()!

Author Closing Comment

by:Alicia St Rose
ID: 36951532
I figured it out on my own.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question