Does anyone happen to know where an expo on query_posts is to be found please. On Codex it is descibed as coming shortly. (1.5).
Does anyone happen to know where an expo on query_posts is to be found please. On Codex it is descibed as coming shortly. (1.5).
query_posts allows you to reuse the $wp_query object. By passing in parameters to query_posts, that query will be performed.
This will reset the loop counter and rebuild the collection of posts allowing you to go back through the_loop again.
By parameters, I mean you would call query_posts as such:
query_posts('category_name=your_category&showposts=10');
Too late. I got it fixed up. Thanks for readiong this far. There is an example of it in action on Codex.
Ah crap, I remembered seeing it somewhere. For future reference, see here.
I *really* have to get to work on that query_posts page...
I still havent quite got the syntax. Does the query go inside the loop. Then the rewind ?
Use it just before (but not in) the loop it's to act upon.
Then rewind? I ask because it isnt running smoothly. I have tried most combos.
Or is the rewind built into the query as it seems ? In the Codex example the query sits first but then the loop only executes the query.
You shouldn't need to rewind. The loop counter is reset upon execution so it acts as an implicit rewind.
Ah cool. But then the loop wont execute.
rewind is somewhat unrelated to query_posts. Depending on what you're trying to do, an option may be to reinitialize the default loop through query_posts('showposts').
Here's roughly what you would be doing:
if (have_posts()) : while (have_posts()) : the_post();
the_title();
endwhile;
//now run a new query
query_posts('category_name=site&showposts=10');
//as $wp_query is reinitialise, let's run the_loop
while (have_posts()) : the_post();
the_title();
endwhile;
endif;
This looks good. TY.
The thing with the query post is that it bypasses any password protection if you're using PW's. Know of a way to still include the PW protection?
lawtai: Try reusing the code for that from the_content() and perform an if/else just after the start of your custom loop:
<?php if(!empty($post->post_password)) :
if(stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password) { // and it doesn't match the cookie
$output = get_the_password_form();
echo $output;
}
else : ?>
~drop your regular loop stuff here ~
<? endif; ?>
Don't know if it'll work, but worth a shot.
This is what I have for the "blog.php" file which is basically the index but on the blog template so that there could be a home page.
<?php if(!empty($post->post_password)) :
if(stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password) { // and it doesn't match the cookie
$output = get_the_password_form();
echo $output;
}
else : ?>
<?php query_posts("showposts=10"); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
~The rest of my loop~
I end up getting this error:Parse error: parse error, unexpected ':' in /home/.nabbenna/yogaboat/cottonmill.info/wp-content/themes/daisyraegemini/blog.php on line 15
Any suggestions?
Well there is a period just before nabbenna ?
"Any suggestions?"
Without seeing the whole thing...do you have the closing endif in there after your normal loop content?
yes, I do have the closing endif.
That's the current code for the blog.php file. Since it's considered a "page" by WP, and I'm trying to have it show what the index normally would, I want to be able to PW protect the whole page. Hopefully you understand what I'm trying to get at.
That's without your code.
-with your code
Hmm. You've hit a limitation to page templating. Or rather, password protection.
When you set a password on a post or Page, you're protecting the content of that post, and not an actual document. If you were to run a regular iteration of The Loop before your custom post query, you'd see your Page is password protected--but only the contents of your Page, and not the page.
Ok, possible solution:
I've inserted a simplified loop to grab the Page's password, and use it for your custom post query verification.
Note: I commented out your gravatar.php include, but forgot to uncomment it in the paste up.
I am still not quite getting this. Is it mandatory that the query runs inside the loop?
Thanks Kafkaesqui! That worked great!
Root: The query should run justbefore the loop from what I understand. But by doing so, you basically force your loop to show the query, therefore bypassing any password protection you may be using.
Well it doesnt work :)
Works for me! I'd like to thank lawtai for his persistence with this issue. :D
Mine is up too. Thanks guys and to Nick at MtDewVirus.
kafkaesqui, installed your password query and combined it as suggested with individual categories. this works also for what i need, besides of two things:
1) when entering the protected category by pw it shows all entries instead of only those from the protected one
2) i would like to exclude the entries (headers etc.) of the protected category from the mainpage
you can try it at www.eyetag.de/weblog
pw: test
for what reason do i have to put it into its own category template?
you could simply leave in index.php, couldn´t you?
thanks&cheers
ANYTHING WRONG WITH MY REQUEST?
guys, please help me out of this!
can´t get further without your help! i´m really wondering why some posts get ignored sometimes (like those on this topic)...
is it only because there´s no quick solution to it? if there´s anything i can do better in my problems description or anythng else to improve feedback rate, please let me know!
again: thanks in advance!
et
I'm trying to display a page at the top of my home page and the posts as normal below. However, the navigation links disappear in almost any combination of adding a Page to the top of the home page (I've tried plugins and my own variations).
I believe the problem is from calling the loop twice in the same page, which is not getting reset properly the second time thorugh. I even tried using my own WP query object. I did notice that the WP query object refers to a global post on the "the_post()" function. The use of globals in instance variables is what leads me to believe something isn't getting reset properly.
This is my first time into the guts of WordPress, and I haven't gone too far to debug the problem. Before I do, I wanted to see if anyone else is seeing the same problem.
This is two problems mixed together. Putting a *page* at the top is not quite the same as having a sticky or an initial query. Could you post your loop code?
This topic has been closed to new replies.