I would like to run a mini-loop that grabs the excerpt from posts in a specific category and displays them in a div under the content of a specific static page.
So far what I have done is added the following to my page.php right after the ‘endif’
this is my text
< ?php } ?>
This does work as expected – that is to say only on that specific page ‘letters-from-africa’ the text ‘this is my text’ appears in the new div I created and I am able to style it fine in my css file.
So, I then tried to add a snippett of php to tell wordpress to run loop on specific category. I found this snippett here on css-tricks,
I changed the ‘cat=5’ to the category I wanted and added this snippett to the conditional tag code as such…
< ?php query_posts('cat=1'); ?>
< ?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
< ?php the_content(); ?>
< ?php endwhile; endif; ?>
< ?php } ?>
And I get a blank page. So I am thinking it might be the second loop causing confusion and I might need to add <?php wp_reset_query(); ?> somewhere, but where? I tried before, after still just get a blank page. I must be missing something else, yes? Anyone?
Read the Codex my friend,
The query_posts function overrides and replaces the main query for the page. To save your sanity, do not use it for any other purpose.
It’s pretty much equall to query_posts, except that it doesn’t override, do no need to rewind, reset or save the main loop.
You can just WP_Query something within a page that has a loop without inteferring or being limited by either.
If there’s any issues still, ofcourse we’re glad to answer any questions and help out with any questions, but seeing the code you got going in your first post I think you’ll get it done with WP_Query ;)
Yeah, you know the codex is a wonderful place and full of information that makes the assumption you know what you are doing. ;-)
For those of us trying to learn it can be frustrating though.
I did go through that info a month ago, tried to use it and when I posted on the wp support forums not a single answer. So I gave up on that idea. Then I found a post here in the snippets area that seemed to describe a simpler way to accomplish what I was after. When it didn’t work I posted here hoping to learn why.
In the meantime I did some more research and found some excellent explanations and more importantly examples using the $newquery = new function. 2 minutes later I had what I wanted up and live. I was also able to modify the example code and understand why, so I actually learned something.
Simply telling a coder in learning to read the codex may seem logical to an advanced coder, I guess.
I appreciate your reply,
You must be logged in to reply to this topic.