The code checks if posts exist with have_posts(). If none, it runs the else block.
Step 2: Identify the else block output
The else block outputs <p>No posts found.</p> when no posts exist.
Final Answer:
No posts found. -> Option C
Quick Check:
No posts triggers else output [OK]
Hint: If no posts, the else block runs showing 'No posts found.' [OK]
Common Mistakes:
Assuming no output if no posts
Expecting an error message instead
Thinking titles show even if no posts
4. You created a new theme but WordPress shows a blank page. Which of the following is the most likely cause?
medium
A. Missing style.css file with theme header comment
B. Using get_footer() instead of footer.php
C. Calling get_header() twice in index.php
D. Not adding functions.php file
Solution
Step 1: Check theme registration requirements
WordPress requires style.css with a proper header comment to recognize the theme.
Step 2: Understand blank page cause
If style.css is missing or header comment is absent, WordPress won't load the theme, showing a blank page.
Final Answer:
Missing style.css file with theme header comment -> Option A
Quick Check:
Missing style.css causes blank theme page [OK]
Hint: Always include style.css with header comment to register theme [OK]
Common Mistakes:
Thinking get_footer() usage causes blank page
Assuming duplicate get_header() breaks theme
Believing functions.php is mandatory for theme to load
5. You want to create a WordPress theme from scratch that shows a custom message only on the homepage and lists post titles on other pages. Which code snippet correctly implements this in index.php?
hard
A. <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php endwhile; else : ?>
<p>Welcome to my custom homepage!</p>
<?php endif; ?>
B. <?php if ( is_front_page() ) : ?>
<p>Welcome to my custom homepage!</p>
<?php else : if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php endwhile; endif; endif; ?>
C. <?php if ( is_home() ) : ?>
<p>Welcome to my custom homepage!</p>
<?php else : ?>
<h2>No posts to show</h2>
<?php endif; ?>
D. <?php if ( is_front_page() ) : ?>
<p>Welcome to my custom homepage!</p>
<?php endif; ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php endwhile; endif; ?>
Solution
Step 1: Use conditional tags correctly
is_front_page() checks if the current page is the homepage to show the custom message.
Step 2: Show posts only on other pages
Else block runs the loop to list post titles on non-homepage pages.
Step 3: Verify code structure
<?php if ( is_front_page() ) : ?>
<p>Welcome to my custom homepage!</p>
<?php else : if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php endwhile; endif; endif; ?> nests the else with have_posts() loop correctly, showing message only on homepage.
Final Answer:
The nested if-else code snippet -> Option B
Quick Check:
Conditional homepage message + posts elsewhere = <?php if ( is_front_page() ) : ?>
<p>Welcome to my custom homepage!</p>
<?php else : if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php endwhile; endif; endif; ?> [OK]
Hint: Use is_front_page() for homepage, else loop for posts [OK]
Common Mistakes:
Putting posts loop inside homepage condition
Showing message only when no posts exist
Not separating homepage and other pages logic
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.