WordPress.org

Ready to get started?Download WordPress

Forums

Ascending posts not working? (4 posts)

  1. EntarteteMuzak
    Member
    Posted 3 years ago #

    I don't know what I'm doing wrong, but sorting posts in a category to be ascending doesn't seem to work.

    Here are my snippets:

    <?php
    if ( is_category() ) {
      $cat = get_query_var('cat');
      query_posts(array('category__in' => array($cat), 'posts_per_page' => -1, 'orderby' => 'date',
         'order' => 'ASC'));
    }
    if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php
       $args = array(
         'category_name' => 'Category',
         'posts_per_page' => 1,
         'order_by' => 'date',
         'order' => 'ASC'
    );
    $args['order'] = 'ASC';
    $my_query = new WP_Query($args);
    while ($my_query->have_posts()) {
      $my_query->the_post(); ?>
      <a href="<?php the_permalink(); ?>" title="Latest post">Latest post</a>
      <?php }
    ?>
  2. Tara
    Member
    Posted 3 years ago #

    try this 1nstead of the 1st snippet:

    <?php
    foreach( get_categories() as $cat_id ) {
      $args=array(
        'cat' => $cat_id,
        'post_type' => 'post',
        'post_status' => 'publish',
        'posts_per_page' => 2,
        'caller_get_posts'=> 1
      );
      $my_query = null;
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        echo 'List of Posts for category '. $cat_id;
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
          <?php
        //the_content();  //or the_excerpt{};
        endwhile;
      }
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  3. EntarteteMuzak
    Member
    Posted 3 years ago #

    No, sorry that doesn't work.
    Catchable fatal error: Object of class stdClass could not be converted to string in /storage/content/26/129226/palaistra.org/public_html/wp-includes/query.php on line 1420

  4. quanxitung
    Member
    Posted 3 years ago #

    i think code below:
    $cat = get_query_var('cat');
    query_posts(array('category__in' => array($cat), 'posts_per_page' => -1, 'orderby' => 'date',
    'order' => 'ASC'));
    have problem parameter 'category__in' => array($cat) or 'orderby' => 'date'

    code second:
    foreach( get_categories() as $cat_id ) {
    $args=array(
    'cat' => $cat_id,
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => 2,
    'caller_get_posts'=> 1
    );
    }
    have problem parameter 'cat' => $cat_id ($cat_id is array)

    give me question:
    do you need any posts ?
    can i help you?
    sorry, my english is very bad, not describle good

Topic Closed

This topic has been closed to new replies.

About this Topic