Sorting Posts in Alphabetical Order

Discussion in 'WordPress' started by dsimi, Oct 1, 2010.

  1. #1
    How to Sorting Posts in Alphabetical Order in custom wordpress page?.

    I tried query_posts('posts_per_page=10&orderby=title&order=asc'); but it is not working.
     
    dsimi, Oct 1, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    query_posts('posts_per_page=10&orderby=title&order=asc'); is the true way to sorting posts in alphabetical order. I tested it and it worked. Can you write here more part of the code?
     
    s_ruben, Oct 1, 2010 IP
  3. dsimi

    dsimi Member

    Messages:
    265
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    48
    #3
    Thank you. Here is more code.
    <?php

    query_posts('posts_per_page=10&orderby=title&order=asc');

    if ( have_posts() ) : while ( have_posts() ) : the_post(); { ?>

    <h2 class="title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    <?php content(50, __('Find out More...')); ?>
    <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>

    <?php }
    endwhile; else:

    endif;

    //Reset Query
    wp_reset_query();

    ?>
     
    dsimi, Oct 1, 2010 IP
  4. dsimi

    dsimi Member

    Messages:
    265
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    48
    #4
    Iam using this query into custom wordpress page template.
     
    dsimi, Oct 1, 2010 IP
  5. wordpressfan

    wordpressfan Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    the tags take its value from global variables, in our present case, wpdb .
    the query statement does the query properly, but still wpdb is unaffected ...

    assign the result of the query to the global object $wpdb and it will work ...

    thanks
     
    wordpressfan, Oct 1, 2010 IP
  6. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #6
    Can you try this code

    
    <?php
    
    query_posts('posts_per_page=10&orderby=title&order=asc');
    
    if ( have_posts() ) : while ( have_posts() ) : the_post(); { ?>
    
    <h2 class="title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    <?php the_content(50, __('Find out More...')); ?>
    <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    
    <?php }
    endwhile; else:
    
    endif;
    
    //Reset Query
    wp_reset_query();
    
    ?> 
    
    PHP:
    I think it doesn't work because you use function content and I don't know what that function does in your theme. I have changed the function content to the function the_content in my code and I think it has to work.
     
    s_ruben, Oct 1, 2010 IP
  7. dsimi

    dsimi Member

    Messages:
    265
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    48
    #7
    Still it is not work. I have used the following code into functions.php

    // Content Limit
    
        function content($num, $more_link_text = 'Find out More...') {  
    
        $theContent = get_the_content($more_link_text);  
    
        $output = preg_replace('/<img[^>]+./','', $theContent);  
    
        $limit = $num+1;  
    
        $content = explode(' ', $output, $limit);  
    
        array_pop($content);  
    
        $content = implode(" ",$content);  
    
        $content = strip_tags($content, '<p><a><address><a><abbr><acronym><b><big><blockquote><br><caption><cite><class><code><col><del><dd><div><dl><dt><em><font><h1><h2><h3><h4><h5><h6><hr><i><img><ins><kbd><li><ol><p><pre><q><s><span><strike><strong><sub><sup><table><tbody><td><tfoot><tr><tt><ul><var>');
    
          echo close_tags($content);
    
          echo "<p><a href='";
    
          the_permalink();
    
          echo "'>".$more_link_text."</a></p>";
    
    }
    PHP:
    So iam using
    <?php content(50, __('Find out More...')); ?>(
    PHP:
     
    dsimi, Oct 2, 2010 IP