Support » Fixing WordPress » Problems displaying posts!

  • Resolved evilpixy

    (@evilpixy)


    Hi,

    I’m having some trouble displaying the post correctly from a certain category.
    The code I use:

    <?php query_posts('cat=1&showposts=15'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php endwhile;?>

    Ok – it shows the text/images of the 15 last posts from the category, but fail to give the title and/or date.

    Is there a simple/advance way to get it displayed like:

    <div>
    <strong>[TITLE]</strong><small>[date]</small>
    [Content of the post]
    </div>

    Thanks in advance,
    EvilPixy

Viewing 7 replies - 1 through 7 (of 7 total)
  • One example you can draw on:

    <?php the_time('m.d.y') ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>

    You need to add something between <?php while (have_posts()) : the_post(); ?> and <?php endwhile;?> – eg:

    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <?php the_content('Read the rest of this entry &raquo;'); ?>

    etc.

    Ok, that works – but the problem is that it shows it all 2 times ?!?
    First – within the same sheet and then seperately like it was before.

    What am I doning wrong here.
    Could it be my code above that is interfering with the code?
    I will post it here for you to see.

    <ul>
    <div style="float:left; width:200px; margin-right:10px;">
    <?php $count=0;
     global $post;
     $myposts = get_posts('numberposts=15&cat=1');
     foreach($myposts as $post) :
       setup_postdata($post); $count++;
     ?>
        <a href="<?php the_permalink(); ?>"><? echo $count?>. <?php the_title(); ?></a>
    	<?php if($count%5 == 0) { echo '</div><div style="float:left; width:200px; margin-right:10px;">'; } ?>
     <?php endforeach; ?>
     </div>
    </ul>
    <div>
    <?php query_posts('cat=1&showposts=15'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <?php the_content('Read the rest of this entry &raquo;'); ?>
    <?php endwhile;?>
    </div>

    I hope you can figure this out cause I’m starting to loose it over here.

    Kind regards,
    EvilPixy

    the problem is that it shows it all 2 times

    Because you asked for the same 15 posts in each Loop.

    $myposts = get_posts('numberposts=15&cat=1');
    […]
    <?php query_posts('cat=1&showposts=15'); ?>

    What is it that you’re trying to do?

    Both yes and no.

    Ok – I’m sorry if I’m beeing cryptic.
    The layout of my page is this.
    First show links with text to the 15 first posts in category 1. They will be distributed in 3 columns. Then the idea is to display the 15 first posts in category 1 below my three columns.

    I just chose to display 15, but it might aswell be 10 or something.

    With my current code (2 posts above) it shows the links with text – then one page with a summary of the posts – and then 15 separate “sheets” (everyone with only the text from the posts)

    By only having the code:

    <?php query_posts('cat=1&showposts=15'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php endwhile;?>

    on the page it will show the 15 separate “sheets” with no Title.

    Try adding <php wp_reset_query();?> just before<?php query_posts('cat=1&showposts=15'); ?>.

    http://codex.wordpress.org/Function_Reference/wp_reset_query

    Thanks – that did the trick!

    Kind regards,
    EvilPixy

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Problems displaying posts!’ is closed to new replies.