I have a function whose purpose is to list the posts where each post has the specified category "Top-menu". However, I first want to exclude all those positions where the range is "hidden" ...
How can I edit this code to do this?
global $ post; $ Cat = get_cat_ID ('top-menu'); If ($ cat & gt; 1) $ myposts = get_posts ('numberposts = 5 & amp; class ='. $ Cat); And $ myposts = get_posts ('numberposts = 10'); Forex Currency ($ myposts as post):? & Gt; & Lt; Li & gt; & Lt; A href = "& lt ;? php the_permalink () ;? & gt;" & Gt; & Lt ;? Php the_title (); ? & Gt; & Lt; / A & gt; & Lt; / Li & gt; & Lt ;? Php endforeach; ? & Gt;
This is what you should do. Not sure if you had a if
statement, you are free to join again, feel free if you need it, feel free to You can always use category
and replace it with an ID instead of category_name
because I'm using it as a shortcut here.
$ exclude_cat = get_cat_ID ('hidden'); $ Include_cat = get_cat_ID ('top-menu'); $ Myposts = get_posts (array ('numberposts' => 5, 'category__in' = & gt; array ($ include_cat), 'category__not_in' = & gt; array ($ exclude_cat));
Edit: category_name
can not be associated with category__not_in
, so I have both code Will be turned slightly changed.
I have tested this and it works in WordPress 2.8, just supply the name of the actual class in the get_cat_ID
call and slug
crash To
No comments:
Post a Comment