Bird
0
0

Given this snippet in index.php of a theme:

medium📝 Predict Output Q4 of 15
Wordpress - Custom Theme Development
Given this snippet in index.php of a theme:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php endwhile; else : ?>
<p>No posts found.</p>
<?php endif; ?>

What will be displayed if there are no posts?
AAn error message
BA list of post titles
CA blank page
DNo posts found.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the WordPress Loop structure

    The code checks if posts exist with have_posts(). If none, it executes the else block.
  2. Step 2: Identify the else block output

    The else block outputs a paragraph with "No posts found." message.
  3. Final Answer:

    No posts found. -> Option D
  4. Quick Check:

    No posts message = "No posts found." [OK]
Quick Trick: Loop else block shows message if no posts [OK]
Common Mistakes:
  • Expecting post titles when none exist
  • Thinking it shows blank page
  • Assuming an error appears

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes