WordPress.org

Ready to get started?Download WordPress

Forums

PHP help (1 post)

  1. Kineta
    Member
    Posted 6 years ago #

    I'm a newbie w/ php. I found this nice bit of code that sorts categories into sections with the category as the header. I'd like to sort the posts alphabetically, but can't figure where to put the query_posts code.

    Here's what I have - bold text is what I added, but it doesn't do anything. if I use $myposts=query_post(etc) I get an alphabetical list, however it's all the entries, not just the relevant category

    <?php if($cats != NULL) { ?>
    		<ul>
    
    		<?php foreach ($cats as $cat) { ?>
    			<li>
    
    			<?php if($cat != NULL) {
    				$base_url = get_bloginfo('home') . "/?cat=" . $cat->cat_ID; ?>
    				<h3><a href="<?php echo $base_url?>"><?php echo $cat->cat_name?></a></h3>
    			<?php } ?>
    
    			<?php // Show category description
    				if ($cat->category_description != NULL) ?>
    					<p><?php echo $cat->category_description ?></p>
    
    				<?php $myposts = get_posts("category=$cat->cat_ID"); ?>
    				<ul>
    
    				<?php  query_posts($query_string . '&orderby=title&order=asc') ; foreach($myposts as $post) : ?>
    				<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    				<?php endforeach; ?>
    				</ul>
    			</li>
    	<?php } ?>
    		</ul>
    <?php } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.