Alicia St Rose
asked on
Wordpress conditional is_archive() not working for custom post types
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!
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>';
}?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER