Pages and The Loop
-
I’m confused.
I’ve heard that pages are supposed to are static. Yet, you can have php and template tags in them. So what I’m wondering is, can you place The Loop in a Page template?
I’m trying this, but with little success.
-
Pages are not static. They are in MYSQL and dynamically created every time someone calls one up.
Yes you can put The Loop on them. You need to check out the Default Kubric Theme for how they are set up.
Also, check out the codex page for creating and using Pages.
I’ve got them going on my site: create a custom template, Write New Page, choose your custom template to base the Page on, save the Page. It then displays as a link with the tag
wp_list_pages
on your sidebar, for instance.Hope that helps a bit!
After looking over the above post (thank you), I went back to the codex. It gave me an idea to try to test to see what I’m doing wrong, or what it is that I don’t understand.
Here’s what I did. As suggested in the codex, I began a new custom page template with a copy of index.php. And then all I did to change it was to add the 4 template descriptions at the top of the file, changed the class to “widecolumn”, and deleted the line that loads the sidebar. Thats it. Saved it with a new name.
Then I went to the Write Pages page, made a new page and selected my new index-based template file as the template. Gave the page a title and some words. Saved the new page.
I’m sure all of you know what I saw when I went to the new page. A page with one post on it. That post had title and copy that I typed in when I made the page. What I don’t understand is what is different about this page and the index.php. Their templates have (mostly) the same code, but in index.php “The Loop” loops over all the posts. On my custom page “The Loop” loops over just the page itself. What decides which set of records gets looped over? How do you “feed” “The Loop”?
What I’m trying to build is a “page” which acts like a filter, which will show a list of authors who have posted new material in the last seven days and links to those posts. I think I’ve come up with the logic to insert into “The Loop”, but I don’t know where to apply it. I don’t want this filtered page to replace the main index.php. But if I make it a Page, then only the contents of the Page itself gets filtered, not the contents of the entire blog.
I also tried to make it a stand alone page (weekly_posters.php) and saved it in the same directory as index.php. But when point my browser to it it just get the following error message: No input file specified.
Anybody understand what I’m trying to do and how to do it?
Thanks for reading,
Paulheh I think I get what you’re trying to do. One suggestion is to basically create a template file with your author listing and basically anything that would go in your index.php file, except cut out the area where it brings posts into it. In fact, if you created your stand alone page correctly using the right functinos, then you could simply add a template tag to it, and then put it in your themes folder, and then just create a “blank” page with that page as your template. Then you’d get a “static” page.
Iawatai, I think your last suggestion is what I’ve been trying. Make a custom Page template file that includes “The Loop”. Use an if-then block to filter out posts that are over a week old. Then make a Page that uses this new template file as its template. Give this new page a title, but no story.
The problem I’m having is that the resulting page always returns no posts other that the Page itself. “The Loop” in this Page never loops over the posts. How do I tell this custom page to look at all of the post, not just at itself?
Here’s my code for the custom Page template
<?php
/*
Template Name: Weekly Posters
*/
?>
<?php get_header(); ?>
<h2>The Weeks Posts:</h2>
<ul>
<!-- Start The Loop. -->
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php if (get_the_time('U') >= date(U) - (60 * 24 * 7) ) : ?><li><?php the_excerpt(); ?></li>
<?php endif; ?>
<?php endwhile; ?>
<?php else:???>
<li><?php _e('Sorry, no posts matched your criteria.');???></li>
<?php endif;???>
<!-- Close The Loop. --></ul>
<?php get_footer(); ?>All this produces a list with two empty list items
yea, but I don’t think you really need the loop at all. This is what I have for my archives section:
<?php
/*
Template Name: Archives
*/
?>
<?php
require('wp-config.php'); $single = 1; $siteurl = get_settings('siteurl');
?>
<?php get_header(); ?><div id="content">
<div class="post"><h2>10 Most Recent Posts:</h2>
<ul>
<?php get_archives('postbypost', '10'); ?>
</ul>
<h2>Most Commented Posts:</h2>
<ul>
<?php mdv_most_commented(10); ?>
</ul>
<h2>Archives by Month:</h2>
<ul>
<?php wp_get_archives('type=monthly&show_post_count=TRUE'); ?>
</ul><h2>Archives by Subject:</h2>
<ul>
<?php wp_list_cats('sort_column=name&optioncount=1'); ?>
</ul><h2>Fun Fact:</h2>
<ul>
<li>A total of <strong><?php total_word_count(); ?></strong> words have been written in the posts for this site.</li>
</ul>
</div>
</div><?php get_sidebar(); ?>
<div id="clearer"> </div>
<?php get_footer(); ?>
</div>
</div>
</body>
</html>you could change it to fit what you want it to do.
Thats interesting. Its close to what I want. I tried this code
<?php
/*
Template Name: Weekly Posters #4 (Say NO to The Loop!)
*/
?>
<?php get_header(); ?><div id="content" class="widecolumn">
<h2>Weekly Archive</h2>
<p><?php wp_get_archives('type=weekly&format=html');???></p>
<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
</div><?php get_footer(); ?>
One big problem, though. When I click on one of the links this generates, I’m take to a yearly archive for 2005!
takes you to a yearly archive? do you have a link to take a look at?
https://www.sbox.net/blogrd105
Go to the Weekly Posters (exparimental) link
do you have an archive.php page? cause i think that’s what’s causing the problem you’re getting. Although, it does show the week worth of posts.
I’m using the default Kubrick theme, slightly tweeked. The archive.php is untouched.
Hmmm. Looking into the archive.php, no provisions were made for weekly. How do I fix that, I wonder. Time to tinker.
I just want to remind everyone of the old cliche “Think outside the box!”
That’s what Pages are. They can do almost anything you can come up with. Keep it off your main page and give it it’s own special space to shine in. Anything can be pulled into it, not just a Page post. That’s the MAGIC of the templates you can build. It can be simple and “normal” or totally a mixed up mishmosh mayhem of beautifulyl info gathered in one spot. ??
Yes, but how?
heh, not sure how to help you with the weekly listing, take a look in teh codex?
- The topic ‘Pages and The Loop’ is closed to new replies.