Forums

need help on my hack about show related post (9 posts)

  1. adamramadhan
    Member
    Posted 3 years ago #

    <?php
    //for use in the loop, list 5 post titles related to first tag on current post
    $tags = wp_get_post_tags($post->ID);
    if ($tags) {
      echo 'Related Posts';
      $first_tag = $tags[0]->term_id;
      $args=array(
        'tag__in' => array($first_tag),
        'post__not_in' => array($post->ID),
        'showposts'=>5,
        'caller_get_posts'=>1
       );
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        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
        endwhile;
      }
    }
    ?>

    there is 10 post on my blog
    and it shows 5 of the last post that the code search
    how can we make it shows 5 of the first post that the code search ?

  2. MichaelH
    Volunteer
    Posted 3 years ago #

    and it shows 5 of the last post that the code search
    how can we make it shows 5 of the first post that the code search ?

    I am confused by your question. Please rephrase.

  3. adamramadhan
    Member
    Posted 3 years ago #

    as u see at
    http://www.eattuts.com/html-xhtml-part-1/

    result :
    Html - Xhtml Part 7
    Html - Xhtml Part 6
    Html - Xhtml Part 5
    Html - Xhtml Part 4
    Html - Xhtml Part 3

    how can i make it
    Html - Xhtml Part 2
    Html - Xhtml Part 3
    Html - Xhtml Part 4
    Html - Xhtml Part 5
    Html - Xhtml Part 6

  4. MichaelH
    Volunteer
    Posted 3 years ago #

    To those query_posts() arguments, add 'orderby' => 'title' and 'order' => 'ASC'

  5. adamramadhan
    Member
    Posted 3 years ago #

    yes thanks michealh u save my life . may god bless u somehow haha.

  6. adamramadhan
    Member
    Posted 3 years ago #

    wait
    when i go to http://www.eattuts.com/html-xhtml-part-2/
    it does't show like
    Html - Xhtml Part 3
    Html - Xhtml Part 4
    Html - Xhtml Part 5
    Html - Xhtml Part 6
    Html - Xhtml Part 7
    but it shows like
    Html - Xhtml Part 1
    Html - Xhtml Part 3
    Html - Xhtml Part 4
    Html - Xhtml Part 5
    Html - Xhtml Part 6

    can u help me once more ? sry .

  7. MichaelH
    Volunteer
    Posted 3 years ago #

    Got me confused.

  8. adamramadhan
    Member
    Posted 3 years ago #

    maybe another hack can solve this any idea ?

  9. MichaelH
    Volunteer
    Posted 3 years ago #

    If you want different order for different 'pages' then you will need to review Conditional Tags and Template Hierarchy

Topic Closed

This topic has been closed to new replies.

About this Topic