WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] link to display new to old and old to new categories (2 posts)

  1. Kevin Kwok
    Member
    Posted 4 years ago #

    site: ampersandbox.net

    basically my index page displays posts and categories, and organizes posts by categories see code here: http://wordpress.org/support/topic/326461?replies=7#post-1266893

    by default my code shows categories in ASC order from low to high (aka old to new) categories, however if you look at my site on the right column I want to have a link to sort by low to high and high to low.

    I can link low to high just to display the index page like normal since its already in ASC order. but how do i display DSC order and link to it?

  2. Kevin Kwok
    Member
    Posted 4 years ago #

    solved myself.

    if(!isset($sortby))
    	{
    		$sortby = 'DESC';
    	}	
    
    	$cat_args = array(
    					  	'orderby' => 'ID',
    						'order' => $_GET[sortby]	// New Code
    					  );
    	$categories = get_categories($cat_args);
    	foreach($categories as $category)
    	{
    		echo '<div>';
    		echo '<div style="float: right; position:absolute; padding-left:690px; padding-right:10px; font-family:Courier New; font-size:16px; width:180px;">
    		<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "" )) . '" ' . '>' . $category->name. ' '.$category->description.'</a></div>';
    		$args = array(
    					  	'orderby' => 'ID',
    						'order' => 'DESC',
    						'showposts' => -1,
    						'category' => $category->term_id,
    						'caller_get_posts' => 1
    					  );
    		$posts = get_posts($args);
    		echo '<div style="float: left; width: 660px;">';
    		foreach($posts as $post)
    		{
    			setup_postdata($post);
    			childtheme_post_header();
    			echo "<a href=\"".$post->guid."\" rel=\"bookmark\">";
    			echo '<div style="float: left; width: 150px; margin-right: 15px;">';
    
    			if(get_post_meta($post->ID, 'full-image', $single = true))
    				echo '<img class="full-image" src="'.get_post_meta($post->ID, 'full-image', $single = true).'" width="150" height="113" /><BR />';
    			else
    				echo '<img class="full-image" src="'.bloginfo('url').'" width="150" height="113" /><BR />';
    				echo '<div style="height:50px;">
    						<div style="float: left; margin-top:6px;">'.get_post_meta($post->ID, 'designed-by', $single = true).'</div>
    						<div style="float: right; margin-top:6px;">'.$post->post_title.'</div>
    						<div style="clear: both;"></div>
    					  </div>';
    			echo '</div>';
    			echo '</a>';
    		}
    		echo '</div>';
    
    		echo '</div>';
    	}
    
    ?>
            </div>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.