WordPress.org

Ready to get started?Download WordPress

Forums

Sorting Product Pages (5 posts)

  1. dalla
    Member
    Posted 5 years ago #

    Hi guys,

    Long time troll. First time poster. Apologies if there is a thread for this. I'm working on a website for a friend and trying to get the product pages to sort alphabetically. I've tried using codes provided in other threads but to no avail.

    http://kobrashredders.com.au/scec-endorsed-high-security-shredders/paper/

    I want these products to sort alphabetically in ascending order (I.E: 240, 260, 300, 400, Cyclone, etc).

    <?php
        function getParents($id) {
    	    global $wpdb;
    	    $posts_table = $wpdb->prefix . "posts";
    	    $parent_id = $wpdb->get_var("SELECT post_parent FROM $posts_table WHERE ID=$id");
    	    if($parent_id == 0) return '';
    	    $parent = get_post($parent_id);
    	    return getParents($parent_id) . '<a href="'. get_permalink($parent_id) .
    	    	"\" title=\"$parent->post_title\">$parent->post_title</a> > ";
        }
        ?>
    
    	<!-- LOOP -->
    <?php if (have_posts()) : ?>
    
    		<?php while (have_posts()) : the_post(); ?>
    				<h2><?php global $post; echo getParents($post->ID); ?>
    						   <a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    
    		<!-- Display Subpages & Products -->
    				<ul id="productlist">
    				<?php
    				$children = get_children("post_type=page&post_parent=$post->ID&order=ASC");
    				foreach ($children as $child):
    				?>
    					<li>
    						<a href="<?php echo get_permalink($child->ID) ?>" title="<?php echo $child->post_title ?>">
    						<img src="<?php echo get_post_meta($child->ID, "Product Image", true) ?>" />
    						<span><?php echo $child->post_title ?></span></a>
    					</li>
    				<?php endforeach; ?>
    				</ul>
    		<?php endwhile; ?>
    
    	<?php else : ?>

    Any help would be much appreciated.

  2. zeronex
    Member
    Posted 5 years ago #

    replace following line

    $children = get_children("post_type=page&post_parent=$post->ID&order=ASC");

    with

    $children = get_posts("numberposts=-1&post_type=page&post_parent=$post->ID&orderby=title&order=ASC");
  3. dalla
    Member
    Posted 5 years ago #

    Thank you! Fixed straight away!

  4. champwarez
    Member
    Posted 4 years ago #

    Hi Dalla,
    Could you help me to do product pages like yours please ?
    Are you using any plug-in ?

  5. tlrshopkeeper
    Member
    Posted 4 years ago #

    Hello, Dalla, Zeronex, Champwarez.

    I'm in the same boat. It seems so illogical that products do not sort by Name in ascending alpha-order.

    How did you work this solution? I tried to find code that matched what you've shown and nothing seems to match.

    Thanks,
    Jen

Topic Closed

This topic has been closed to new replies.

About this Topic