Maybe I’m going about this the wrong way but this is my scenario… I would like to use WordPress as a CMS rather than a blogging platform. I have a website that will have somewhere between 25-50 pages and will not have any posts.

I’m looking to develop my own theme which should be fairly easy, however I’m getting a little confused on using The Loop functions.

I understand that:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

is used for a page that is pulling x number of posts, however in my scenario, I only want to pull the contents of a page rather than x number of posts. Do I need to create custom SQL queries?

All of the examples I keep running into are using The Loop for posts. If I’m just using static pages, do I even need to use The Loop? Can I just use the unique URL to pull a page out of the post column of the MySQL database?

I hope this is making sense.

2 Answers
2

Strictly, you don’t need to use a loop in a page template, but it doesn’t hurt, the content of the page will still load, the loop will simply only run once as there is only one post/page. Many themes include a loop in page templates, I guess for some compability issue.

If you are building your page template from scratch, you don’t need to add a loop to it, you are right, wordpress will get the right content from the URL, but you still need to run the function the_post() before to use template tags like the_title(), the_content(), etc. Just put the the_post() towards the top of the template.

Hope it makes sense to you, don’t hesitate to ask if you need further clarifications.

Leave a Reply

Your email address will not be published. Required fields are marked *