Day 2 - What is this Famous "loop" of WordPress that everyone talks about? And some information on single.php, page.php file on wordpress

Day 2 - What is this Famous "loop" of WordPress that everyone talks about? And some information on single.php, page.php file on wordpress

Wow! you are checking out my day 2 blog. Are we becoming friends now? Hope we do :)

Anyways, let's start with this famous "loop" of WordPress.

As per the image below, you can see the single.php file:-

image.png

So, you may notice the while loop. That's where the famous "loop" comes in.

As you can see, the condition of have_posts() is given which checks the posts from the WordPress backend.

If the post exits then the_post() initializes the first post in the loop and then the_title(); echos the title of that particular post. the_content( ); echos the content of that particular post.

You may also notice that the code is in the single.php file. So, there the while loop will only work for each blog post clicked on.

image.png

Now, in the picture above the while loop will only work to show pages only, as it's in the page.php file, governing each WordPress page.

image.png

Now, here the while loop is in index.php. So, it will by default show all blog posts at once, instead of pages. Wordpres prefer posts over pages.

image.png

Like the image above. All posts are shown on the homepage.

Also, that the_permalink() function is linking to each blog post in the title.

That's about it for day 2. Look forward to day 3 now!