• Resolved goldmember

    (@goldmember)


    I’m using the code below on the homepage here (http:/www.willowbilliards.com) to display an event from the Featured Event Category (cat. 5). But for some reason, rather then display the title of the post, there’s a link for HOME. How do I get the title of the post to appear instead???

    <h2>Recent Featured Event</h2>
    
    <?php
    $latestposts = get_posts('numberposts=1&category=5');
    foreach($latestposts as $post) :
       setup_postdata($post);
    ?>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php the_content(); ?>
    <?php endforeach; ?>

    please advise. thanks in advance!

Viewing 6 replies - 1 through 6 (of 6 total)
  • DigitalSquid

    (@twelvefootsnowman)

    Try replacing the_title() with $post->post_title

    Also, the link goes back to homepage instead of the post so you would need to replace get_permalink() with get_permalink($post->ID)

    Thread Starter goldmember

    (@goldmember)

    when i do that, and have the line of code like below, then nothing appears where the post title should be.

    <h2><a href="<?php the_permalink(); ?>"><?php $post->post_title; ?></a></h2>

    please advise.

    DigitalSquid

    (@twelvefootsnowman)

    Whoops! Sorry, it should be <?php echo $post->post_title; ?>

    Thread Starter goldmember

    (@goldmember)

    bingo. thank you!!!

    Thread Starter goldmember

    (@goldmember)

    actually, now i’m having the same problem on this site

    <?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; ?>

    how come, even with the fix, it says “Home” instead of the name of the post? it still reverts to the homepage when someone clicks on the link of the business title???

    Thread Starter goldmember

    (@goldmember)

    nevermind. this seems to have worked:

    <?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; ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘get_posts issue’ is closed to new replies.