{"id":1,"date":"2005-07-20T16:04:00","date_gmt":"2005-07-20T16:04:00","guid":{"rendered":"http:\/\/www.creativeblogging.com\/0\/?p=1"},"modified":"2023-03-15T18:28:07","modified_gmt":"2023-03-15T18:28:07","slug":"content-outside-wp-loop","status":"publish","type":"post","link":"http:\/\/www.creativeblogging.com\/?p=1","title":{"rendered":"The WordPress Loop And Adding Content Outside Of It"},"content":{"rendered":"\n<p>The\u00a0<a href=\"https:\/\/web.archive.org\/web\/20100724190847\/http:\/\/codex.wordpress.org\/The_Loop\" target=\"_blank\" rel=\"noreferrer noopener\">WordPress loop<\/a>\u00a0is what controls the posts on the page. And like it\u2019s name &#8211; it \u2018loops\u2019 the content and anything placed within the loop will be repeated until the loop ends.<\/p>\n\n\n\n<p>Sometimes we\u2019ll need to add content to a page that shouldn\u2019t be repeated with every single post displayed (i.e. ads) and in order to do that, we need to know where the WordPress loop begins and where it ends.<\/p>\n\n\n\n<p>For this example, I\u2019ll be using the default WordPress template (Kubrick) index.php file located in the \u2018[WP-INSTALL]\/wp-content\/themes\/default\/\u2018 folder.<\/p>\n\n\n\n<p>You\u2019ll see the loop starts around line 7* with:<br><code>&lt;?php while (have_posts()) : the_post(); ?&gt;<\/code><\/p>\n\n\n\n<p>The give-away? The word \u2018while\u2019 &#8211; that is the element that tells you the WordPress loop is starting. You can add your information or content above this line and it will not be repeated with each post, instead, it will show before your posts start.<\/p>\n\n\n\n<p>The loop ends around line 20 with:<br><code>&lt;?php endwhile; ?&gt;<\/code><\/p>\n\n\n\n<p>The give-away? The word \u2018endwhile\u2019 &#8211; that is the element that tells you the WordPress loop is ending. You can add your information under this line and it will not be repeated with each post, instead, it will show after all of your posts.<\/p>\n\n\n\n<p>* Technicalities:<br>\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2013<br>Technically the loop starts at line 5 with:<br><code>&lt;?php if (have_posts()) : ?&gt;<\/code><\/p>\n\n\n\n<p>However, this is simply a statement saying \u201cif posts are available, go ahead and start \u2018looping\u2019 them\u201d &#8211; anything you add before this will not be included in the loop, however, if you add something below it and no posts exist, whatever you added won\u2019t be displayed either.<\/p>\n\n\n\n<p>And technically the loop ends at line 33 with:<br><code>&lt;?php endif; ?&gt;<\/code><\/p>\n\n\n\n<p>This is saying, end the \u2018if posts are available\u2026\u201d statement from above and anything added above this line will only be displayed if there are posts, however, anything below it will be displayed regardless.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The\u00a0WordPress loop\u00a0is what controls the posts on the page. And like it\u2019s name &#8211; it \u2018loops\u2019 the content and anything placed within the loop will be repeated until the loop ends. Sometimes we\u2019ll need to add content to a page that shouldn\u2019t be repeated with every single post displayed (i.e. ads) and in order to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-1","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"http:\/\/www.creativeblogging.com\/index.php?rest_route=\/wp\/v2\/posts\/1","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.creativeblogging.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.creativeblogging.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.creativeblogging.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.creativeblogging.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1"}],"version-history":[{"count":3,"href":"http:\/\/www.creativeblogging.com\/index.php?rest_route=\/wp\/v2\/posts\/1\/revisions"}],"predecessor-version":[{"id":19,"href":"http:\/\/www.creativeblogging.com\/index.php?rest_route=\/wp\/v2\/posts\/1\/revisions\/19"}],"wp:attachment":[{"href":"http:\/\/www.creativeblogging.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.creativeblogging.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.creativeblogging.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}