You can test on the post title for any of the above requests within your templates. Examples:
Author/Date
<?php if( get_the_title() != "Welcome" ) : ?>
Posted by <?php the_author(); ?> on <?php the_date(); ?>
<?php endif; ?>
Note the use of !=
in the if() which is PHP for ‘does not equal.’
CSS class assignment
<?php $title_class = ( get_the_title() == "Welcome" ) ? 'welcome-title' : 'post-title'; ?>
<h2 class="<?php echo $title_class; ?>"><?php the_title(); ?></h2>
This one is a bit more complicated. We’re using what’s called a ternary operator to choose between two values for $title_class. The operator evaluates the expression in the parentheses:
( get_the_title() == "Welcome" )
If true, $title_class will be set to ‘welcome-title’; if false, ‘post-title’. Then we output $title_class as the value for the h2 class attribute using the PHP echo command:
<?php echo $title_class; ?>