Wordpress conditional is_archive() not working for custom post types

Posted on 2011-10-11
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
    LVL 7

    Accepted Solution

    figured this out.
    I don't use is_archive(). I use is_post_type_archive()!
    LVL 7

    Author Closing Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    This video teaches users how to migrate an existing Wordpress website to a new domain.
    The viewer will learn how to dynamically set the form action using jQuery.

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now