How to display categories on Page in Marketpress?

I want to have a page, like my store home page, where it lists 1 sample item from each category (in a representative fashion), and then when the person clicks on it, they can shop that category.

For example, if I have "dog products" and "cat products" as categories, We could have one product each from those categories, and it would display on this store home page. If they clicked on the cat product item, it would take them into the cat product listing of all cat products. likewise for the dog products.

I don't find an easy way to let people shop by category, other than using the sidebar. Thanks!

  • Vinod Dalvi

    Hi @emily_garman,

    I hope you are well today and thank you for your question.

    You can add following custom code in your store home page template to display product from "dog products" and "cat products" categories respectively.

    <?php
    $args = array( 'post_type' => 'product', 'posts_per_page' => 1, 'category_name' => 'dog-products');
    $myposts = get_posts( $args );
    if ( $myposts ) {
    foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
    	<li>
    		<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    	</li>
    <?php endforeach;
    wp_reset_postdata();
    }
    
    $args = array( 'post_type' => 'product', 'posts_per_page' => 1, 'category_name' => 'cat -products');
    $myposts = get_posts( $args );
    if ( $myposts ) {
    foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
    	<li>
    		<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    	</li>
    <?php endforeach;
    wp_reset_postdata();
    }?>

    Best Regards,

  • emily_garman

    Hi Vinod--thanks for this answer. It is a little beyond my ability to add this to my page template... I currently have my store just on the regular "default" page.php template. So I created a copy of that called store.php that we can use for the store template, but I do not know where to add this custom code (nor how to customize it once I do add it!). I am attaching the PHP for my page template. Can you tell me where to add it in here?

    Sorry--this is just beyond my skill level!! This site has a lot of products in 4-5 categories, and I think this would be a more efficient way to display them to shoppers without overwhelming them with ALL the products just on one page. Thank you!

    Emily

  • emily_garman
    <?php
    /**
     * Default Page Template
     */
    
    // Header
    get_template_part( 'header', 'page' ); // this makes $content_title available
    
    ?>
    
    <?php while ( have_posts() ) : the_post(); ?>
    
    <div id="content">
    
    	<div id="content-inner"<?php if ( risen_sidebar_enabled( 'primary' ) ) : ?> class="has-sidebar"<?php endif; ?>>
    
    		<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
    			<?php if ( $content_title ) : // this comes from header-page.php; empty if no title should show at top of content ?>
    			<header>
    				<h1 class="page-title"><?php echo $content_title ?></h1>
    			</header>
    			<?php endif; ?>
    
    			<div class="post-content"> <!-- confines heading font to this content -->
    				<?php the_content() ?>
    			</div>
    
    			<?php
    			// multipage nav: 1, 2, 3, etc. for when <!--nextpage--> is used in content
    			if ( ! post_password_required() ) {
    				wp_link_pages( array(
    					'before'	=> '<div class="box multipage-nav"><span>' . __( 'Pages:', 'risen' ) . '</span>',
    					'after'		=> '</div>'
    				) );
    			}
    			?>
    
    			<?php if ( get_edit_post_link( $post->ID ) ) : ?>
    			<footer class="box page-footer">
    				<?php edit_post_link( __( 'Edit Page', 'risen' ), '<span class="edit-link">', '</span>' ); ?>
    			</footer>
    			<?php endif; ?>
    
    		</article>
    
    		<?php comments_template( '', true ); ?>
    
    	</div>
    
    </div>
    
    <?php risen_show_sidebar( 'primary' ); ?>
    
    <?php endwhile; ?>
    
    <?php get_footer(); ?>

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.