[wp-hackers] Can't use the same conditional tag twice?
Bryan Harley
bryanharley at gmail.com
Sat Sep 5 03:15:39 UTC 2009
Thanks Jeremy, that explains it!
On Fri, Sep 4, 2009 at 9:11 AM, Jeremy Clarke <jer at simianuprising.com>wrote:
> Bryan,
>
> query_posts() effectively says to WordPress "I know you THOUGHT you
> should load these XYZ posts (home page, category listing, single
> article, whatever), but actually what this page *IS* is something
> else, and i'll tell you what with query_posts()". When you use it you
> completely reset the page.
>
> So if you are on the homepage and you do a query_posts('cat=1'); then
> right before that line is_home() will be true but right after it will
> be false. After that is_cat() would return true instead.
>
> If you need extra queries you should just use the object instead:
>
> $myposts = new WP_Query('cat=1');
>
> Then you just need a slightly modified loop:
>
> if ($myposts->have_posts() ) : while ($myposts->have_posts()) :
> $myposts->the_post() ;
>
> Until I figured that one out I was constantly having problems with
> conditional tags not doing what I expected. Clean up your extra
> queries and your life will be a lot simpler.
>
> --
> Jeremy Clarke | http://jeremyclarke.org
> Code and Design | http://globalvoicesonline.org
>
>
>
>
>
> On Mon, Aug 31, 2009 at 8:43 PM, Bryan Harley<bryanharley at gmail.com>
> wrote:
> > Yes, I'm using query_posts.
> >
> > On Mon, Aug 31, 2009 at 1:13 AM, Dion Hulse (dd32) <wordpress at dd32.id.au
> >wrote:
> >
> >> are you using query_posts()?
> >>
> >> query_posts overrides the current query, Its not the best way to go
> about
> >> what most people use it for.
> >>
> >> try adding wp_reset_query() iin your footer and see if that helps (for
> >> future reference) - Or call it after query_posts is finished.
> >>
> >>
> >> On Mon, 31 Aug 2009 12:37:00 +1000, Bryan Harley <bryanharley at gmail.com
> >
> >> wrote:
> >>
> >> Peter/Jeremy,
> >>>
> >>> I'm using the following code in both my header and footer.
> >>>
> >>> <li class="<?php if ( is_home() ) { echo 'current_page_item'; } ?>"><a
> >>> href="URLHERE">Welcome</a></li>
> >>>
> >>> Here's the CSS:
> >>>
> >>> li.current_page_item a{border-bottom: 3px solid #ec1c24;}
> >>>
> >>> But the border is only showing in the header, not the footer. To
> >>> correct this, I left my header code the same and changed the footer
> >>> code to:
> >>>
> >>> <li class="<?php if ( is_front_page() ) { echo 'current_page_item'; }
> >>> ?>"><a href="URLHERE">Welcome</a></li>
> >>>
> >>> That solved the problem, but I don't understand why it just didn't
> >>> WORK in the first place. Which lead me to believe maybe you can only
> >>> use one conditional tag per page.
> >>>
> >>> -Bryan
> >>>
> >>>
> >>> On Thu, Aug 27, 2009 at 10:58 AM, Jeremy Clarke<jer at simianuprising.com
> >
> >>> wrote:
> >>>
> >>>> On Wed, Aug 26, 2009 at 9:10 PM, Bryan Harley<bryanharley at gmail.com>
> >>>> wrote:
> >>>>
> >>>>> It seems to me that you can't use the same conditional tag on the
> same
> >>>>> page twice. Can anyone else confirm this. Why is this so?
> >>>>>
> >>>>
> >>>> In my experience this is definitely not the case. You probably have
> >>>> some kind of other issue with your template. Conditional tags would be
> >>>> practically useless if they were limited to once per page.
> >>>>
> >>>>
> >>>> --
> >>>> Jeremy Clarke | http://jeremyclarke.org
> >>>> Code and Design | http://globalvoicesonline.org
> >>>> _______________________________________________
> >>>> wp-hackers mailing list
> >>>> wp-hackers at lists.automattic.com
> >>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
> >>>>
> >>>> _______________________________________________
> >>> wp-hackers mailing list
> >>> wp-hackers at lists.automattic.com
> >>> http://lists.automattic.com/mailman/listinfo/wp-hackers
> >>>
> >>>
> >>
> >> --
> >> --
> >> Dion Hulse
> >> e: contact at dd32.id.au
> >> w: http://dd32.id.au/
> >> m: 04 6621 9112 (+614 6621 9112)
> >> WordPressQI: http://wordpressqi.com/
> >>
> >> _______________________________________________
> >> wp-hackers mailing list
> >> wp-hackers at lists.automattic.com
> >> http://lists.automattic.com/mailman/listinfo/wp-hackers
> >>
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list