The Loop Flashcards
Q: What is “The Loop” in WordPress?
A: The Loop is a PHP code structure used to display posts or pages retrieved from the WordPress database.
Q: What function is typically used to start The Loop?
A: have_posts()
Q: What function is used to iterate through posts in The Loop?
A: the_post()
Q: What does have_posts() return?
A: A boolean value indicating whether there are more posts to process.
Q: What is the minimum structure of The Loop?
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
// Display content
}
}
Q: What function is used to display the title of a post in The Loop?
A: the_title()
Q: What function is used to display the content of a post?
A: the_content()
Q: How can you display the excerpt of a post?
A: Using the the_excerpt() function.
Q: What function is used to display the featured image of a post?
A: the_post_thumbnail()
Q: How can you display the author of a post?
A: Using the the_author() function.
Q: How can you display the publish date of a post?
A: Using the the_date() or the_time() function.
Q: What function is used to display the categories of a post?
A: the_category()
Q: How can you display the tags of a post?
A: Using the the_tags() function.
Q: How do you display the permalink of a post?
A: Using the the_permalink() function.
Q: What function is used to display custom fields in The Loop?
A: get_post_meta()
Q: How can you customise The Loop to display only posts from a specific category?
A: By using a custom query with WP_Query or modifying the global query with pre_get_posts.