{"id":3345,"date":"2014-07-08T14:16:27","date_gmt":"2014-07-08T14:16:27","guid":{"rendered":"https:\/\/www.inmotionhosting.com\/support\/2014\/07\/08\/the-wordpress-loop\/"},"modified":"2024-05-14T12:17:41","modified_gmt":"2024-05-14T16:17:41","slug":"the-wordpress-loop","status":"publish","type":"post","link":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/","title":{"rendered":"Using The WordPress Loop"},"content":{"rendered":"\n<p>When developing WordPress themes, it&#8217;s important to know about the loop. The WordPress Loop is a function that grabs posts from your database, and allows you to display multiple posts on a page, such as the index page of a blog.<\/p>\n\n\n\n<p>There are many advanced variations of the loop, but in this article we&#8217;ll focus on the basic loop, so you can build up from there.<\/p>\n\n\n\n<p>If you would like more information on creating WordPress plugins, see our tutorial series on <a href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/plugins\/create-a-wordpress-plugin\/\">creating your first WordPress plugin<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-you-need\">What you will need\u2026<\/h2>\n\n\n\n<p>In order to edit your theme, you will need a local development site, or you can edit the theme files on your server using the <a href=\"\/support\/edu\/cpanel\/using-file-manager-in-cpanel\/\">cPanel File Manager<\/a>. (It is recommended that you <em>do not<\/em> edit live site files for a production site.) Creating a local WordPress installation on your computer is outside the scope of this article.<\/p>\n\n\n\n<p>You will also need a plain, bare bones text editor like Notepad, TextEdit, Sublime, or similar. Editing files in a Word document will add all kinds of extra text that will corrupt your file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-loop-works\">How the Loop Works<\/h2>\n\n\n\n<p>So how does the loop work? A basic understanding of PHP is important here, but here are the basics.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The loops checks for posts.<\/li>\n\n\n\n<li>If there are posts, each one will be displayed until there are no more.<\/li>\n\n\n\n<li>While displaying the posts, you can add any content or HTML.<\/li>\n<\/ul>\n\n\n\n<p>The loop does its job best when you match the elements of your post (like the title, date, or other information) with an appropriate HTML tag.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Starting the Loop<\/h2>\n\n\n\n<p>To begin the loop, simply initiate a PHP <em>while<\/em> statement, which will run as long as there are posts available to process:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(26px, 1.625rem, 39px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"&lt;?php \n\/\/ Check to see if we have posts \nif ( have_posts() ) : while ( have_posts() ) : \n\/\/ Open a 'while' loop \nthe_post(); \n\/\/ Repeatedly grab next post \nthe_content(); \n\/\/Get the content of the post \nendwhile; \n\/\/ End the loop \nendif; \n\/\/ End the 'if' statement \n?&gt;\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F97583\">&lt;?<\/span><span style=\"color: #79B8FF\">php<\/span><span style=\"color: #E1E4E8\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\">\/\/ Check to see if we have posts <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> ( <\/span><span style=\"color: #B392F0\">have_posts<\/span><span style=\"color: #E1E4E8\">() ) <\/span><span style=\"color: #F97583\">:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">while<\/span><span style=\"color: #E1E4E8\"> ( <\/span><span style=\"color: #B392F0\">have_posts<\/span><span style=\"color: #E1E4E8\">() ) : <\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\">\/\/ Open a &#39;while&#39; loop <\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">the_post<\/span><span style=\"color: #E1E4E8\">(); <\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\">\/\/ Repeatedly grab next post <\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">the_content<\/span><span style=\"color: #E1E4E8\">(); <\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\">\/\/Get the content of the post <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">endwhile<\/span><span style=\"color: #E1E4E8\">; <\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\">\/\/ End the loop <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">endif<\/span><span style=\"color: #E1E4E8\">; <\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\">\/\/ End the &#39;if&#39; statement <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">?&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Inside the Loop<\/h2>\n\n\n\n<p>Within the loop, you would call functions like the_permalink(), the_title(), the_content(), and various other WordPress functions that you want displayed for each post on the page.<\/p>\n\n\n\n<p>In this example, we just want to display the post title with a link to the main post, as well as the post content:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(1 * 0.6 * 1rem);line-height:clamp(26px, 1.625rem, 39px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"&lt;h2&gt;&lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot; rel=&quot;bookmark&quot; title=&quot;Permanent Link to &lt;?php the_title_attribute(); ?&gt;&quot;&gt;&lt;?php the_title(); ?&gt;&lt;\/a&gt;&lt;\/h2&gt;\n&lt;?php the_content(); ?&gt;\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F97583\">&lt;<\/span><span style=\"color: #79B8FF\">h2<\/span><span style=\"color: #F97583\">&gt;&lt;<\/span><span style=\"color: #79B8FF\">a<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">href<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #9ECBFF\">&quot;&lt;?php the_permalink() ?&gt;&quot;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">rel<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #9ECBFF\">&quot;bookmark&quot;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">title<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #9ECBFF\">&quot;Permanent Link to &lt;?php the_title_attribute(); ?&gt;&quot;<\/span><span style=\"color: #F97583\">&gt;&lt;?<\/span><span style=\"color: #79B8FF\">php<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">the_title<\/span><span style=\"color: #E1E4E8\">(); <\/span><span style=\"color: #F97583\">?&gt;&lt;\/<\/span><span style=\"color: #79B8FF\">a<\/span><span style=\"color: #F97583\">&gt;&lt;\/<\/span><span style=\"color: #79B8FF\">h2<\/span><span style=\"color: #F97583\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">&lt;?<\/span><span style=\"color: #79B8FF\">php<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">the_content<\/span><span style=\"color: #E1E4E8\">(); <\/span><span style=\"color: #F97583\">?&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>As you can see, we created a link within the title of the post on the first line, then display the content below it.<\/p>\n\n\n\n<p>As this is a loop, it will display this information for each post that you have within WordPress until there are no more posts to process.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Ending the Loop<\/h2>\n\n\n\n<p>Now that we have started the loop and added our content to the loop, we need to end it. To end the loop, you may use the following code:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(26px, 1.625rem, 39px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"&lt;?php endwhile; else: ?&gt;\n&lt;p&gt;&lt;?php _e('Sorry, no posts matched your criteria.'); ?&gt;&lt;\/p&gt;\n&lt;?php endif; ?&gt;\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F97583\">&lt;?<\/span><span style=\"color: #79B8FF\">php<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">endwhile<\/span><span style=\"color: #E1E4E8\">; <\/span><span style=\"color: #F97583\">else:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">?&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">&lt;<\/span><span style=\"color: #79B8FF\">p<\/span><span style=\"color: #F97583\">&gt;&lt;?<\/span><span style=\"color: #79B8FF\">php<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">_e<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;Sorry, no posts matched your criteria.&#39;<\/span><span style=\"color: #E1E4E8\">); <\/span><span style=\"color: #F97583\">?&gt;&lt;\/<\/span><span style=\"color: #79B8FF\">p<\/span><span style=\"color: #F97583\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">&lt;?<\/span><span style=\"color: #79B8FF\">php<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">endif<\/span><span style=\"color: #E1E4E8\">; <\/span><span style=\"color: #F97583\">?&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Complete the WordPress Loop<\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(26px, 1.625rem, 39px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"&lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt;\n&lt;h2&gt;&lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot; rel=&quot;bookmark&quot; title=&quot;Permanent Link to &lt;?php the_title_attribute(); ?&gt;&quot;&gt;&lt;?php the_title(); ?&gt;&lt;\/a&gt;&lt;\/h2&gt;\n&lt;?php the_content(); ?&gt;\n&lt;?php endwhile; else: ?&gt;\n&lt;p&gt;&lt;?php _e('Sorry, no posts matched your criteria.'); ?&gt;&lt;\/p&gt;\n&lt;?php endif; ?&gt;\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F97583\">&lt;?<\/span><span style=\"color: #79B8FF\">php<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> ( <\/span><span style=\"color: #B392F0\">have_posts<\/span><span style=\"color: #E1E4E8\">() ) <\/span><span style=\"color: #F97583\">:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">while<\/span><span style=\"color: #E1E4E8\"> ( <\/span><span style=\"color: #B392F0\">have_posts<\/span><span style=\"color: #E1E4E8\">() ) : <\/span><span style=\"color: #B392F0\">the_post<\/span><span style=\"color: #E1E4E8\">(); <\/span><span style=\"color: #F97583\">?&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">&lt;<\/span><span style=\"color: #79B8FF\">h2<\/span><span style=\"color: #F97583\">&gt;&lt;<\/span><span style=\"color: #79B8FF\">a<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">href<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #9ECBFF\">&quot;&lt;?php the_permalink() ?&gt;&quot;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">rel<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #9ECBFF\">&quot;bookmark&quot;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">title<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #9ECBFF\">&quot;Permanent Link to &lt;?php the_title_attribute(); ?&gt;&quot;<\/span><span style=\"color: #F97583\">&gt;&lt;?<\/span><span style=\"color: #79B8FF\">php<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">the_title<\/span><span style=\"color: #E1E4E8\">(); <\/span><span style=\"color: #F97583\">?&gt;&lt;\/<\/span><span style=\"color: #79B8FF\">a<\/span><span style=\"color: #F97583\">&gt;&lt;\/<\/span><span style=\"color: #79B8FF\">h2<\/span><span style=\"color: #F97583\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">&lt;?<\/span><span style=\"color: #79B8FF\">php<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">the_content<\/span><span style=\"color: #E1E4E8\">(); <\/span><span style=\"color: #F97583\">?&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">&lt;?<\/span><span style=\"color: #79B8FF\">php<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">endwhile<\/span><span style=\"color: #E1E4E8\">; <\/span><span style=\"color: #F97583\">else:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">?&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">&lt;<\/span><span style=\"color: #79B8FF\">p<\/span><span style=\"color: #F97583\">&gt;&lt;?<\/span><span style=\"color: #79B8FF\">php<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">_e<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;Sorry, no posts matched your criteria.&#39;<\/span><span style=\"color: #E1E4E8\">); <\/span><span style=\"color: #F97583\">?&gt;&lt;\/<\/span><span style=\"color: #79B8FF\">p<\/span><span style=\"color: #F97583\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">&lt;?<\/span><span style=\"color: #79B8FF\">php<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">endif<\/span><span style=\"color: #E1E4E8\">; <\/span><span style=\"color: #F97583\">?&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Where does the loop go?<\/h2>\n\n\n\n<p>In theory, you can put the loop anywhere you need to generate an index of posts. But typically, the loop will go into the <code>index.php<\/code> template page, or any pages designated as an index page like Archives, Category pages, and the like.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">References<\/h2>\n\n\n\n<p>For further technical documentation on the WordPress loop, you may review the <a href=\"https:\/\/codex.wordpress.org\/The_Loop\" target=\"_blank\" rel=\"noopener\">WordPress Codex page on the loop<\/a>, and the newer documentation on <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/have_posts\/\" target=\"_blank\" rel=\"noreferrer noopener\">have_posts<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When developing WordPress themes, it&#8217;s important to know about the loop. The WordPress Loop is a function that grabs posts from your database, and allows you to display multiple posts on a page, such as the index page of a blog. There are many advanced variations of the loop, but in this article we&#8217;ll focus<a class=\"moretag\" href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/\"> Read More ><\/a><\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4325,56],"tags":[],"class_list":["post-3345","post","type-post","status-publish","format-standard","hentry","category-wordpress-hosting","category-wordpress"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Introduction to the WordPress Loop | InMotion Hosting<\/title>\n<meta name=\"description\" content=\"In this article, we will introduce you to the loop in WordPress that allows you to display your various posts on a page.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Introduction to the WordPress Loop | InMotion Hosting\" \/>\n<meta property=\"og:description\" content=\"In this article, we will introduce you to the loop in WordPress that allows you to display your various posts on a page.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/\" \/>\n<meta property=\"og:site_name\" content=\"InMotion Hosting Support Center\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/inmotionhosting\/\" \/>\n<meta property=\"article:published_time\" content=\"2014-07-08T14:16:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-14T16:17:41+00:00\" \/>\n<meta name=\"author\" content=\"Jeff Matson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:site\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeff Matson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/\"},\"author\":{\"name\":\"Jeff Matson\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/83776252b196c020e4352a3796e5642b\"},\"headline\":\"Using The WordPress Loop\",\"datePublished\":\"2014-07-08T14:16:27+00:00\",\"dateModified\":\"2024-05-14T16:17:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/\"},\"wordCount\":506,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"articleSection\":[\"WordPress Hosting\",\"WordPress Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/\",\"name\":\"Introduction to the WordPress Loop | InMotion Hosting\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\"},\"datePublished\":\"2014-07-08T14:16:27+00:00\",\"dateModified\":\"2024-05-14T16:17:41+00:00\",\"description\":\"In this article, we will introduce you to the loop in WordPress that allows you to display your various posts on a page.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.inmotionhosting.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using The WordPress Loop\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"name\":\"InMotion Hosting Support Center\",\"description\":\"Web Hosting Support &amp; Tutorials\",\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\",\"name\":\"InMotion Hosting\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"contentUrl\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"width\":696,\"height\":696,\"caption\":\"InMotion Hosting\"},\"image\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/inmotionhosting\/\",\"https:\/\/x.com\/InMotionHosting\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/83776252b196c020e4352a3796e5642b\",\"name\":\"Jeff Matson\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/author\/jeffma\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Introduction to the WordPress Loop | InMotion Hosting","description":"In this article, we will introduce you to the loop in WordPress that allows you to display your various posts on a page.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/","og_locale":"en_US","og_type":"article","og_title":"Introduction to the WordPress Loop | InMotion Hosting","og_description":"In this article, we will introduce you to the loop in WordPress that allows you to display your various posts on a page.","og_url":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/","og_site_name":"InMotion Hosting Support Center","article_publisher":"https:\/\/www.facebook.com\/inmotionhosting\/","article_published_time":"2014-07-08T14:16:27+00:00","article_modified_time":"2024-05-14T16:17:41+00:00","author":"Jeff Matson","twitter_card":"summary_large_image","twitter_creator":"@InMotionHosting","twitter_site":"@InMotionHosting","twitter_misc":{"Written by":"Jeff Matson","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/#article","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/"},"author":{"name":"Jeff Matson","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/83776252b196c020e4352a3796e5642b"},"headline":"Using The WordPress Loop","datePublished":"2014-07-08T14:16:27+00:00","dateModified":"2024-05-14T16:17:41+00:00","mainEntityOfPage":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/"},"wordCount":506,"commentCount":0,"publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"articleSection":["WordPress Hosting","WordPress Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/","url":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/","name":"Introduction to the WordPress Loop | InMotion Hosting","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#website"},"datePublished":"2014-07-08T14:16:27+00:00","dateModified":"2024-05-14T16:17:41+00:00","description":"In this article, we will introduce you to the loop in WordPress that allows you to display your various posts on a page.","breadcrumb":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/the-wordpress-loop\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.inmotionhosting.com\/support\/"},{"@type":"ListItem","position":2,"name":"Using The WordPress Loop"}]},{"@type":"WebSite","@id":"https:\/\/www.inmotionhosting.com\/support\/#website","url":"https:\/\/www.inmotionhosting.com\/support\/","name":"InMotion Hosting Support Center","description":"Web Hosting Support &amp; Tutorials","publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.inmotionhosting.com\/support\/#organization","name":"InMotion Hosting","url":"https:\/\/www.inmotionhosting.com\/support\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/","url":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","contentUrl":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","width":696,"height":696,"caption":"InMotion Hosting"},"image":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/inmotionhosting\/","https:\/\/x.com\/InMotionHosting"]},{"@type":"Person","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/83776252b196c020e4352a3796e5642b","name":"Jeff Matson","url":"https:\/\/www.inmotionhosting.com\/support\/author\/jeffma\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"primary_category":{"id":56,"name":"WordPress Tutorials","slug":"wordpress","link":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/"},"_links":{"self":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/3345","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/comments?post=3345"}],"version-history":[{"count":3,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/3345\/revisions"}],"predecessor-version":[{"id":127875,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/3345\/revisions\/127875"}],"wp:attachment":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/media?parent=3345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/categories?post=3345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/tags?post=3345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}