Confused about wordpress 'the loop'

Hello

I have read this webpage about how the loop works in wordpress

http://blog.teamtreehouse.com/wordpress-loop-beginners-guide

How does wordpress know if it is displaying a single page or single post or multiple posts. Does the wordpress interface set something behind the scenes?

If it is a single page I presume the content i add in the wordpress text editor is stored in a database and retrieved by this call

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

	<h1><?php the_title() ;?></h1>	
	<?php the_content(); ?> <========HERE

<?php endwhile; else: ?>

	<p>Sorry, this page does not exist</p>

<?php endif; ?>

Open in new window


Lets say i was using one template for all of my website pages, and these pages were having their main content included through the template part above (which i believe gets copy from the database ), how would i have another page in the website that had additional content in the main section other than text , would i have to add the code to the template part above (probably in some if statement which checked the page?). Or would i do this with widgets somehow. In the default wordpress installation it looks like i can only drag widgets into something called primary. I was assuming you would be able to drag them into the main 'loop content' somehow

Thanks for your help.
If i wanted to add something else (other than simple text) to a web page which used the above template part for the main content of the webpage, how would i do it? Would i have to make a specific template just for that page which basically adds some extra code to that show above to generate the additional content
andiejeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

uzzidesignCommented:
If it is a single page I presume the content i add in the wordpress text editor is stored in a database and retrieved by this call
Yes. => the_content()
And you want another template that has more than one of those, right? More on that below.

First, you have two different questions. I will attempt to answer them separately.

I can see why they are being confusing on that blog you posted. For beginner purposes, just ignore this part: "The WordPress Loop is the code used to display main content and excerpts of content on WordPress sites." And focus on this part: "Often times the loop is used to “loop” through and display a number of posts titles and excerpts like on a blog listing page."

Then skip the stuff in the middle of their post and pick back up again on the part that begins with: "What the Loop Can Display" to understand that the loop is just an index that can list whatever you want it to list in terms of Post Data that is stored in the database.

To simplify things, The Loop is simply a for loop that iterates over your most recent blog posts. By posts, I mean "Posts" and not Pages. This loop is by default located on the index.php template. In recent years, with Wordpress becoming more ubiquitous as a general purpose CMS, "The Loop" has been minimized in importance in most themes. The loop usually is just an html list that shows the post title and a truncated version of the_content() as an excerpt, that links to the actual post url.

On to what I think you really might be getting at:

You can have Page Templates and Post Templates separately, where templates dictate the layout and any static content or customized dynamic widgets that you would like to add in addition to the default the_content() section which is from the default WYSIWYG editor. You may also place HTML content inside this, or shortcodes which sometime call dynamic content from plugins.

how would i have another page in the website that had additional content in the main section other than text
Either with a static Page template or a Post template (via Custom Post Types), which once setup can be selected from the template drop down when writing a Post/Page. You can add additional dynamic content to these pages with custom sidebars or with additional WYSIWYG content areas (awesome plugin).

i can only drag widgets into something called primary
Primary refers to your default sidebar, I believe. Registering multiple sidebars will allow you to customize this.

Perhaps I am over-explaining things if all you really want to do is have some static Pages that are not "blog" type posts, like an "About Us" page or something. That is what Pages are for, and you can assign custom navigation for these one-off pages with custom Menus under Appearance. Blog posts by definition are organized into categories and archives, not navigation, and filed under the loop automatically because they are chronological vs. one-off Pages. You can also design custom category templates, FYI, and a good example of why you would want to understand what the loop can display is for a custom category template if you wanted to display, for example, a list of articles vs. a list of videos and you wanted to display different meta data in the index/loop of the category page for each type of post.

If i wanted to add something else (other than simple text) to a web page which used the above template part for the main content of the webpage, how would i do it
As I have hopefully answered by now, there are many ways: Text Widgets via custom sidebars if you wanted to be able to have a CMS interface for editing that text. Or like I said, additional WYSIWYG content areas which accept HTML. Or, custom page templates as one-offs if they are not likely to change. Either way you will have to edit some HTML or add PHP calls to existing template pages. In any case, you will find those calls and what arguments they can take in the Wordpress Codex.

A Glossary that may help
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
andiejeAuthor Commented:
Sorry, you are right. I posted it late at night after a frustrating evening. I should have known better and I apologise for degrading the quality of the forum
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.