I’m developing a custom theme for my website and I can’t seem to check if the current page is a blog post or a page. How would I do this?
My code so far (post.php):
<?php get_header(); ?>
<?php if (is_front_page()) : ?>
<div class="hero">
<h1>hello world</h1>
</div>
<? elseif (is_page()) : ?>
<div class="hero">
<h1><?php the_title(); ?></h1>
</div>
<? elseif (is_singular()) : ?>
<div class="hero">
<h1><?php the_title(); ?></h1>
<p>Date: <?php echo get_the_date(); ?></p>
<p>Categories:</p>
</div>
<?php endif; ?>
<?php get_footer(); ?>
2
Answers
The WordPress helper function
is_singular()
checks if the current request "is for an existing single post of any post type".There are additional helper functions, like
is_single()
andis_page()
that vary slightly fromis_singular()
.Hi you can use something like this….
Hopefully this one can help you…