• Resolved danedral

    (@danedral)


    Hello,
    I would like to list post in specific category listed by alpabetical order (from A to Z).

    My site is: http://dentistsinsingapore.com/

    Category page is: http://dentistsinsingapore.com/dentist-singapore/singapore-dental-clinics/

    I tryed some plugins that do so but non seams to work with my template.

    Also tryed

    http://codex.wordpress.org/Alphabetizing_Posts

    i made category.php because i didnt have it in template and added code from page but it messups my page puting all post that i have (even thoes that arent related to the category) in a list on begining of page.

    my archive.php contains fallowing code:

    <?php get_header(); ?>
    
    <?php if ( get_option( 'uniq_breadcrumbs' )) {  ?>
       <div class="breadcrumb"><?php yoast_breadcrumb('','');  ?></div>
    <?php } ?>
    
    <div id="the_body">
        <?php if (is_category()) { ?>
        <h4 > <span><?php echo get_option('uniq_browsing_category'); ?> <?php echo single_cat_title(); ?></span> </h4>
        <?php } elseif (is_day()) { ?>
        <h4><span><?php echo get_option('uniq_browsing_day'); ?> <?php the_time('F jS, Y'); ?></span> </h4>
        <?php } elseif (is_month()) { ?>
        <h4><span><?php echo get_option('uniq_browsing_month'); ?>
          <?php the_time('F, Y'); ?></span>
        </h4>
        <?php } elseif (is_year()) { ?>
        <h4><span><?php echo get_option('uniq_browsing_year'); ?>
          <?php the_time('Y'); ?></span>
        </h4>
        <?php } elseif (is_author()) { ?>
        <h4> <span><?php echo get_option('uniq_browsing_author'); ?> <?php echo $curauth->nickname; ?> </span> </h4>
        <?php } elseif (is_tag()) { ?>
        <h4> <span><?php echo get_option('uniq_browsing_tag'); ?> <?php echo single_tag_title('', true); ?>  </span></h4>
        <?php } ?>
    
        <?php if(have_posts()) : $scounter=0; ?>
          <?php while(have_posts()) : the_post() ?>
    	  <?php $scounter++; ?>
          <?php $post_images = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large'); ?>
    
    		<div id="post-<?php the_ID(); ?>" class="posts_small <?php if ($scounter==1) echo 'first_small'; ?>">
    			<?php if ($post_images[0]) { ?>
    				<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>" class="preloader"><img src="<?php echo bloginfo('template_url'); ?>/thumb.php?src=<?php echo $post_images[0];?>&w=200&h=200&zc=1&q=80<?php echo $thumb_url;?>" alt="<?php the_title(); ?>"  class="mag fade_hover" /></a>
    			<?php } ?>
    
    			<div class="post_content">
    				<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    				<p></p>
    				<p><?php echo bm_better_excerpt(280, '...'); ?></p>
    
    			</div>
    
    		</div>
    
          <?php endwhile; ?>
    
    		<div class="pagination">
    			<?php if (function_exists('wp_pagenavi')) { ?>
    				<?php wp_pagenavi(); ?>
    			<?php } ?>
    		</div>
    	<?php endif; ?>
    
    </div> <!-- the_body end -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    and my index.php contains fallowing code:

    <?php get_header(); ?>        
    
    	<div id="the_body">
    		<?php dynamic_sidebar(2);  ?>
    		<div class="clearboth"></div>
    
    	<?php if (get_option('uniq_homepage_content')) { ?>
    		<?php wp_reset_query(); ?>
    		<?php if(have_posts()) : $scounter=0; ?>
          <?php while(have_posts()) : the_post() ?>
    	  <?php $scounter++; ?>
          <?php $post_images = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large'); ?>
    
    		<div id="post-<?php the_ID(); ?>" class="posts_small <?php if ($scounter==1) echo 'first_small'; ?>">
    			<?php if ($post_images[0]) { ?>
    				<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>" class="preloader"><img src="<?php echo bloginfo('template_url'); ?>/thumb.php?src=<?php echo $post_images[0];?>&w=200&h=200&zc=1&q=80<?php echo $thumb_url;?>" alt="<?php the_title(); ?>"  class="mag fade_hover preloader" /></a>
    			<?php } ?>
    
    			<div class="post_content">
    				<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    				<p class="meta">By <?php the_author_posts_link(); ?> | <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?> | <a href="<?php the_permalink(); ?>#commentarea"><?php comments_number('No comments', 'One comment', '% comments'); ?></a></p>
    				<p><?php echo bm_better_excerpt(280, '...'); ?></p>
    				<p class="tags">Posted in: <span class="category"><?php the_category(", "); ?> </span></p>
    			</div>
    
    		</div>
    
          <?php endwhile; ?>
    
    		<div class="pagination">
    			<?php if (function_exists('wp_pagenavi')) { ?>
    				<?php wp_pagenavi(); ?>
    			<?php } ?>
    		</div>
    	<?php endif; } ?>
    	</div> <!-- the_body -->
    
    	<?php get_sidebar(); ?>
    
    <?php  get_footer(); ?>

    Thanks in advance for your help.

Viewing 6 replies - 1 through 6 (of 6 total)
  • In your templates I don’t see you actually using different args for getting the posts, like sorting on something.

    Maybe you it’s the concept of ‘the loop’. When you call have_posts(); WP will make a database query of posts for you with the standard arguments.

    I would advice you to take a look at WP_Query

    // The Query
    $query = new WP_Query( $args );
    
    // The Loop
    if ( $query->have_posts() ) {
    	while ( $query->have_posts() ) {
    		$query->the_post();
    		echo '<li>' . get_the_title() . '</li>';
    	}
    } else {
    	// no posts found
    }
    /* Restore original Post Data */
    wp_reset_postdata();

    In $args this way you can give a orderBy argument to order on fields.

    Thread Starter danedral

    (@danedral)

    Hey Bas Schuiling,
    thank you so much for your replay but mmm im now even more confused what should i do?

    Oh and i forgot to post functions.php file:

    [ Commercial theme code redacted ]

    do you have any idea is there any plugin that could help me sort this?

    Use a custom WP_Query instead of the standard loop

    So replace this:
    <?php while(have_posts()) : the_post() ?>

    with a custom query as shown in my previous reply.

    Thread Starter danedral

    (@danedral)

    when tried to replace it in archive.php
    also had to remove <?php endwhile; ?> from line 58 was giving error.

    Now under category it shows only one post. Where it was two or more it only shows 1.

    Thread Starter danedral

    (@danedral)

    Thanks Bas for helping.

    I found this plugin and it let me sort posts

    http://wordpress.org/plugins/wp-post-sorting/

    its old plugin but seams still to work ok

    Thread Starter danedral

    (@danedral)

    Solved problems ty

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Cant list Posts in category alphabeticaly’ is closed to new replies.