WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
Woocommerce: Post above products pages (6 posts)

  1. joecoll
    Member
    Posted 1 year ago #

    Hello,

    I would like to include content from a post displayed above my products pages.

    I put the following code into my archive-product.php file, which I copied into my child-theme (using Twenty Twelve).

    <?php
    global $more;
    $more = 0;
    query_posts('cat=37');
    if(have_posts()) :
    while(have_posts()) :the_post();
    ?>
    <h2><a>"><?php the_title();?></a></h2>
    <div><?php the_content('Read More') ?></div>
    <?php
    endwhile;
    endif;
    wp_reset_query();?>

    As you know, this is displaying the content of the post from a particular category.

    But here is the issue.

    I want each of my product pages to display content from a different post/different category.

    In Woocommerce, I created my categories: Mens (parent), Boots, Shoes etc. as children.


    Then using the Appearance > Menu, I inserted the categories creating the pages on my site.

    Then I went into Posts > Categories and created new categories eg; mens-featured which as an id of 37.

    So I want to have the mens-featured post appear on my Mens page, boots-featured appear on my Boots page etc.

    Hope that is clear... I'm a newbie!

    I'm running a local install, but could put the site live if you would like to view the site?

    Thanks
    Joe

    http://wordpress.org/extend/plugins/woocommerce/

  2. joecoll
    Member
    Posted 1 year ago #

    Anyone got any ideas please?

    Even a quick nod in the right direction would be mich appreciated.

    Thanks
    Joe

  3. jameskoster
    Member
    Plugin Author

    Posted 1 year ago #

    In your archive-product.php (or better still, hooked in via a custom function) you'll need to query the category and then change the ID based on that.

    You can use is_tax (http://codex.wordpress.org/Function_Reference/is_tax) to check which product category is being viewed. The product category taxonomy is product_cat.

    So you'd check that the product_cat is Men's and then set the $id as 37. And so on, for each category.

    Thanks

  4. joecoll
    Member
    Posted 1 year ago #

    Thanks a mil James, will give that a go!

    J

  5. joecoll
    Member
    Posted 1 year ago #

    Sorry James, but could you please provide the basic code for what you described?

    Spent the last hour trying to figure this out but I'm getting nowhere.
    I'm pretty new to this.

    Appreciate the assistance.

    Joe

  6. joecoll
    Member
    Posted 1 year ago #

    Is this anywhere close?

    <?php
    is_tax( $product_cat, $37 );
    if(have_posts()) :
    while(have_posts()) :the_post();
    ?>
    <h2><a>"><?php the_title();?></a></h2>
    <div><?php the_content('Read More') ?></div>
    <?php
    endwhile;
    endif;
    wp_reset_query();?>

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic