Forums

Query post by GETTING the category Id of page your on??? (9 posts)

  1. NexxGenDrue
    Member
    Posted 1 year ago #

    This is what I have..

    <?php query_posts(array("cat" => "7"));
    if(have_posts()): ?>

    This works to display my 'bags cat (7)' but i have a template, and need all my categories to feed off this one template, so instead of defining what cat id, i need it to get the cat id of the page your on, and display the product under that cat. I know its probably simple but im not to advanced yet. Thanks in advance!!!

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    <?php query_posts(array("cat" => get_query_var('cat')));
    if(have_posts()): ?>

    but this is the default in the category archive, anyway ...

  3. NexxGenDrue
    Member
    Posted 1 year ago #

    Thanks alot for the input, but when used code u gave, it got all my post and displayed, and stripped my css for it for some reason. Any other ideas?

    http://militarypewter.com/?p=544

    I know theirs got to be a way to display all my product from the category the post belongs to.

  4. alchymyth
    The Sweeper
    Posted 1 year ago #

    display all my product from the category the post belongs to.

    that is different.

    in a post, you get the posts categories (there could be more than one) with get_the_categories():
    http://codex.wordpress.org/Function_Reference/get_the_category

    <?php $post_cats = get_the_categories($post->ID);
    foreach($post_cats as $post_cat) { $cats[] = $post_cat->term_id; }
    $args = array(
    'posts_per_page' => -1,
    'category__in' => $cats
    ); ?>
    <?php query_posts( $args );
    if(have_posts()): ?>
  5. NexxGenDrue
    Member
    Posted 1 year ago #

    Thanks alot! Your there, but if you look at that link again you can see what its doing. Its messing it up somehow, but still pulling from the category, it also pulled the post itself and put there too.

  6. alchymyth
    The Sweeper
    Posted 1 year ago #

    there are ways to prvent this:
    http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action

    you could paste the code of your template into a http://pastebin.com/ and post the link ot it here.
    someone might be able to make a suggestion how to prevent the duplicate post to show.

  7. NexxGenDrue
    Member
    Posted 1 year ago #

    http://pastebin.com/J2VgaKdR

    Can anyone else help?
    It is now pulling from that category but messing up the css and pulling the post its on as well.

  8. alchymyth
    The Sweeper
    Posted 1 year ago #

    catch up on the basics:
    -http://codex.wordpress.org/Theme_Development
    http://codex.wordpress.org/The_Loop
    http://codex.wordpress.org/The_Loop_in_Action
    http://codex.wordpress.org/Stepping_Into_Templates

    there are a few things wrong with your template;
    there is no loop to show the post itself;

    what exactly is the purpose of this template?
    is it supposed to show a single post, with something extra?

    there are also some validation errors:
    http://validator.w3.org/check?uri=http%3A%2F%2Fmilitarypewter.com%2F%3Fp%3D544&charset=%28detect+automatically%29&doctype=Inline&group=0

    http://codex.wordpress.org/Validating_a_Website

  9. NexxGenDrue
    Member
    Posted 1 year ago #

    Im not the best at this yet, but im trying.

    Isn't what im trying to achieve right now starting the loop?

    The purpose here is that im changing my site from pages to post that way I have better control. I need BAGS to show bags, CHAIRS to show chairs, etc. The only way I thought of was making them categories and displaying the categories for the page your on. I could make a new page template for each cat and say 'query post display cat id' but that seems sloppy.

    Im open to new ideas. But im new with this post thing and would love to learn.

Topic Closed

This topic has been closed to new replies.

About this Topic