1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

get_posts php issue

Discussion in 'WordPress' started by sixrfan, Jan 4, 2011.

  1. #1
    I'm using the code below on the homepage here to display the most recent post from the News Businesses Category (cat. 1). But for some reason, when you click on the title of the posting, it's just a link to the Homepage, and doesnt take the user to the posting.

    
    <?php
    $latestposts = get_posts('numberposts=1&category=1');
    foreach($latestposts as $post) :
       setup_postdata($post);
    ?>
    <h4><a href="<?php the_permalink(); ?>"><?php echo $post->post_title; ?></h4>
    <?php the_content(); ?>
    <?php endforeach; ?>
    
    PHP:



    any idea what's wrong? please advise. thanks in advance.
     
    sixrfan, Jan 4, 2011 IP
  2. robaid

    robaid Member

    Messages:
    126
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    35
    #2
    Does this help?

    <?php query_posts('category=1&showposts=1'); ?>
    <?php while (have_posts()) : the_post(); ?>
            <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
            <?php the_content(); ?>
    <?php endwhile; ?>
    PHP:
     
    robaid, Jan 4, 2011 IP
    sixrfan likes this.
  3. sixrfan

    sixrfan Well-Known Member

    Messages:
    354
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    bingo. thank you!!!
     
    sixrfan, Jan 4, 2011 IP