{"id":3673,"date":"2009-09-03T13:47:22","date_gmt":"2009-09-03T20:47:22","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=3673"},"modified":"2009-09-03T13:47:22","modified_gmt":"2009-09-03T20:47:22","slug":"run-a-loop-outside-of-wordpress","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/snippets\/wordpress\/run-a-loop-outside-of-wordpress\/","title":{"rendered":"Run a Loop Outside of WordPress"},"content":{"rendered":"

Include Basic WordPress Functions<\/h4>\n
<?php\r\n  \/\/ Include WordPress\r\n  define('WP_USE_THEMES', false);\r\n  require('\/server\/path\/to\/your\/wordpress\/site\/htdocs\/blog\/wp-blog-header.php');\r\n  query_posts('showposts=1');\r\n?><\/code><\/pre>\n

Run Loop<\/h4>\n
<?php while (have_posts()): the_post(); ?>\r\n   <h2><?php the_title(); ?><\/h2>\r\n   <?php the_excerpt(); ?>\r\n   <p><a href=\"<?php the_permalink(); ?>\" class=\"red\">Read more...<\/a><\/p>\r\n<?php endwhile; ?><\/code><\/pre>\n

This can be used on any PHP file even OUTSIDE your WordPress installation.<\/p>\n","protected":false},"excerpt":{"rendered":"

Include Basic WordPress Functions <?php \/\/ Include WordPress define(‘WP_USE_THEMES’, false); require(‘\/server\/path\/to\/your\/wordpress\/site\/htdocs\/blog\/wp-blog-header.php’); query_posts(‘showposts=1’); ?> Run Loop <?php while (have_posts()): the_post(); ?> <h2><?php the_title(); ?><\/h2> <?php the_excerpt(); ?> <p><a href=”<?php the_permalink(); ?>” class=”red”>Read more…<\/a><\/p> <?php endwhile; ?> This can be used on any PHP file even OUTSIDE your WordPress installation.<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":3229,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"page-snippet.php","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":""},"tags":[],"acf":[],"jetpack-related-posts":[{"id":3313,"url":"https:\/\/css-tricks.com\/snippets\/wordpress\/run-loop-on-posts-of-specific-category\/","url_meta":{"origin":3673,"position":0},"title":"Run Loop on Posts of Specific Category","date":"August 10, 2009","format":false,"excerpt":"If you were to use this, for example, in a left sidebar which ran before the main loop on your page, remember to reset the query or it will upset that main loop.","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4566,"url":"https:\/\/css-tricks.com\/snippets\/wordpress\/custom-loop-based-on-custom-fields\/","url_meta":{"origin":3673,"position":1},"title":"Custom Loop\/Query Based on Custom Fields","date":"October 30, 2009","format":false,"excerpt":"Last updated by Jason Witt. If you design or develop WordPress themes or plugins, there's a good chance that someday you'll need to make a query for custom meta fields. These are those completely custom key\/value pairs that you can attach to any post, page, or custom post type. WordPress\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":249342,"url":"https:\/\/css-tricks.com\/snippets\/javascript\/replacements-setinterval-using-requestanimationframe\/","url_meta":{"origin":3673,"position":2},"title":"Replacements for setInterval Using requestAnimationFrame","date":"December 26, 2016","format":false,"excerpt":"When it comes to animation, we're told that setInterval is a bad idea. Because, for example, the loop will run regardless of anything else going on, rather than politely yielding like requestAnimationFrame will. Also some browsers might \"play catchup\" with a setInterval loop, where an inactive tab might have been\u2026","rel":"","context":"With 1 comment","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3309,"url":"https:\/\/css-tricks.com\/snippets\/wordpress\/remove-specific-categories-from-the-loop\/","url_meta":{"origin":3673,"position":3},"title":"Remove Specific Categories From The Loop","date":"August 10, 2009","format":false,"excerpt":"

<\/h3>

<\/p> The area inside the while loop could be anything, that's just some example typical inside-loop code. The trick is the first line, and the\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":18651,"url":"https:\/\/css-tricks.com\/lodge\/v10\/122-building-the-videos-archive-part-1\/","url_meta":{"origin":3673,"position":4},"title":"#122: Building the Videos Archive, Part 1","date":"October 1, 2012","format":false,"excerpt":"The videos archive page is the part of the site where people can browse all the free videos available to watch. It's for browsing, must like the homepage for the snippets or the homepage for the demos. These pages are their own template, which we can very quickly and easily\u2026","rel":"","context":"With 2 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5872,"url":"https:\/\/css-tricks.com\/snippets\/php\/insert-element-every-nth-loop\/","url_meta":{"origin":3673,"position":5},"title":"Insert Element Every nth Loop","date":"March 10, 2010","format":false,"excerpt":"When inside of a loop, you can keep track of the iteration number of the loop (shown below is a simple for loop). Using that iteration number, you can calculate it's modulus of some number (number left over after an even division). If that modulus is zero, you are at\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3673"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=3673"}],"version-history":[{"count":1,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3673\/revisions"}],"predecessor-version":[{"id":3674,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3673\/revisions\/3674"}],"up":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3229"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=3673"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=3673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}