Forums

Dynamic list of links to posts of a given category on a page (7 posts)

  1. eleis
    Member
    Posted 3 months ago #

    What I'm trying to do:
    I want a list of links to posts from category 82 to show up after content of page 91 is rendered.

    IT WORKS WONDERFULLY EXCEPT the fact that each post has to be rendered after links. Something to do with the_post() inside The Loop.
    So, there is a better way to do this, right? But what is it!

    This is the code INSIDE "The Loop"

    <!-- STANDARD PAGE HEADER -->
    <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
        <div class="entry">
            <!-- PAGE CONTENT -->
            <?php the_content(); ?>
            <?php link_pages('<p><strong>Pages:</strong> ', '</p>', 'number'); ?>
            <?php edit_post_link('Edit', '<p>', '</p>'); ?>
    
            <!-- PAY ATTENTION TO THESE LINES!!! -->
            <?php if($post->ID == 91){
                query_posts('cat=82&showposts=10&orderby=date&order=DEC');
                while (have_posts()) : the_post(); ?>
                    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br />
                <?php endwhile; ?> <br /><br />
            <?php } ?> <br /><br />
        </div>
    
        <!-- COMMENT BOX -->
        <div class="comments-template">
            <?php comments_template(); ?>
        </div>
  2. iridiax
    Member
    Posted 3 months ago #

    I see these errors (there may be more): You have a number of template tags like the_content that need to be in the Loop and order=DEC in query_posts should be order=DESC.

    These links have more info:

    http://codex.wordpress.org/Template_Tags
    http://codex.wordpress.org/Template_Tags/query_posts
    http://codex.wordpress.org/The_Loop

    I think that you are wanting multiple Loops (see above link), but beware of using nested loops.

  3. kapiljain.in
    Member
    Posted 3 months ago #

    Another error in your code is that you missed out the reset the query.

    To reset query use <?php wp_reset_query();?> just after endwhile loop.

    <?php endwhile; ?> <br /><br /> will be changed to <?php endwhile; ?> <?php wp_reset_query();?> <br /><br />

  4. eleis
    Member
    Posted 3 months ago #

    iridiax, i said that stuff was inside The Loop.
    i also thought it was weird that it wasn't DESC like in SQL

    despite everything, no one has even touched my question

  5. iridiax
    Member
    Posted 3 months ago #

    Don't use nested loops, you need multiple loops.

  6. eleis
    Member
    Posted 3 months ago #

    so how would the second loop look if i were to write it separately?

  7. eleis
    Member
    Posted 3 months ago #

    edit: was unhelpful post

Reply

You must log in to post.

About this Topic