Showing Product Category

How do I call the product category up with php? I tried to pull <?php the_category(', ') ?> out of the meta header, and i tried to use the same structure as other calls <?php echo the_category(); ?> and still got nothing.

Help would be greatly appreciated!

  • Kimberly

    Parking,

    Hi and Thanks for using WPMUdev forums!

    Snagged a bit of code from the Marketpress functions.php that calls the categories, may not be what you need though. Perhaps taking a peek in there would give you some clues :slight_smile:

    @param int $product_id Optional. Post ID to retrieve categories.
    * @param string $before Optional. Before list.
    * @param string $sep Optional. Separate items using this.
    * @param string $after Optional. After list.
    */

    function mp_category_list( $product_id = false, $before = '', $sep = ', ', $after = '' ) {
      $terms = get_the_term_list( $product_id, 'product_category', $before, $sep, $after );
      if ( $terms )
        return $terms;
      else
    		return __( 'Uncatagorized', 'mp' );

    Best,

    Kimberly

  • Kimberly

    I wasn't referring to the theme. The file references which .php files control which functions for use in customizing your theme.

    Advanced Themes:

    MarketPress uses custom post types to display it's products. This means that you can use
    the same WP theme templating system you are familiar with. We simply provide a customized
    subset of template functions so you don't have to worry about dealing with post meta. Template
    functions are fully documented and can be found in the /marketpress/marketpress-includes/template-functions.php file.

    MarketPress searches your current theme folder for template files specific to store pages. If
    a template file does not exist it loads the theme's page template instead. Just like WP, the
    plugin will search for templates in order of priority from top to bottom. Here are possible
    file names for store templates in order:

    Single Product Page
    mp_product-PRODUCTNAME.php
    mp_product-PRODUCTID.php
    mp_product.php

    Store Page
    mp_store.php

    Cart/Checkout Page
    mp_cart.php

    Order Status Page
    mp_orderstatus.php

    Product List Page
    mp_productlist.php

    Product Category List Page
    mp_category-CATEGORYSLUG.php
    mp_category-CATEGORYID.php
    mp_category.php
    mp_taxonomy.php
    mp_productlist.php

    Product Tag List Page
    mp_tag-TAGSLUG.php
    mp_tag-TAGID.php
    mp_tag.php
    mp_taxonomy.php
    mp_productlist.php

    Looking into template-functions.php I can see the mp_list_categories function and the parameters, line 47 thru 86

    * Display or retrieve the HTML list of product categories.
     *
     * The list of arguments is below:
     *     'show_option_all' (string) - Text to display for showing all categories.
     *     'orderby' (string) default is 'ID' - What column to use for ordering the
     * categories.
     *     'order' (string) default is 'ASC' - What direction to order categories.
     *     'show_last_update' (bool|int) default is 0 - See {@link
     * walk_category_dropdown_tree()}
     *     'show_count' (bool|int) default is 0 - Whether to show how many posts are
     * in the category.
     *     'hide_empty' (bool|int) default is 1 - Whether to hide categories that
     * don't have any posts attached to them.
     *     'use_desc_for_title' (bool|int) default is 1 - Whether to use the
     * description instead of the category title.
     *     'feed' - See {@link get_categories()}.
     *     'feed_type' - See {@link get_categories()}.
     *     'feed_image' - See {@link get_categories()}.
     *     'child_of' (int) default is 0 - See {@link get_categories()}.
     *     'exclude' (string) - See {@link get_categories()}.
     *     'exclude_tree' (string) - See {@link get_categories()}.
     *     'current_category' (int) - See {@link get_categories()}.
     *     'hierarchical' (bool) - See {@link get_categories()}.
     *     'title_li' (string) - See {@link get_categories()}.
     *     'depth' (int) - The max depth.
     *
     * @param bool $echo Optional. Whether or not to echo.
     * @param string|array $args Optional. Override default arguments.
     */
    function mp_list_categories( $echo = true, $args = '' ) {
      $args['taxonomy'] = 'product_category';
      $args['echo'] = false;
    
      $list = '<ul id="mp_category_list">' . wp_list_categories( $args ) . '</ul>';
    
      if ($echo)
        echo $list;
      else
        return $list;
    }

    does this help? Sorry I'm not better with .php

    Kimberly

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.