0

I'm struggling with displaying a single post page.

I have the following code on the static front page:

<?php
                $args = array( 'numberposts' => 5, 'order'=> 'ASC', 'orderby' => 'date' );
                $postslist = get_posts( $args );
                foreach ($postslist as $post) :  setup_postdata($post); ?> 
                    <div class="single_post">

                        <h3><?php the_date(); ?></h3>

                        <h3>
                            <a href="<?php get_permalink();?>">
                                <?php the_title(); ?>   
                            </a>
                        </h3>
                        <?php the_excerpt(); ?>
                    </div>
            <?php endforeach; ?>

That fetches latest posts.

I'm trying to understand how single post page works by copying it from twentytwelve wp theme folder but for some reason it doesn't work. I would really appreciate any help in pointing directions i should follow to make single.php work.

Thank you.

5
  • 1
    I'm afraid I can't understand what are you trying to accomplish. The code you posted here shows 5 oldest posts. It has nothing to do with showing single post, so...? Aug 6, 2013 at 13:07
  • Agreed. This is confusing. You posted code for your static home page but the question seems to be about a single.php page for which you've provide little information except that "it doesn't work".
    – s_ha_dum
    Aug 6, 2013 at 13:11
  • I want to be able to open this latest posts in separate single.php page that will only show one post.
    – mr.oizo
    Aug 6, 2013 at 13:21
  • Still not clear... are you asking how to make an HTML anchor(link)?
    – s_ha_dum
    Aug 6, 2013 at 13:32
  • probably yes...
    – mr.oizo
    Aug 6, 2013 at 13:32

1 Answer 1

0

See the change of get_permalink to the_permalink

This might work for you.

<?php
                $args = array( 'numberposts' => 5, 'order'=> 'ASC', 'orderby' => 'date' );
                $postslist = get_posts( $args );
                foreach ($postslist as $post) :  setup_postdata($post); ?> 
                    <div class="single_post">

                        <h3><?php the_date(); ?></h3>

                        <h3>
                            <a href="<?php the_permalink();?>">
                                <?php the_title(); ?>   
                            </a>
                        </h3>
                        <?php the_excerpt(); ?>
                    </div>
            <?php endforeach; ?>
3
  • For some reason <?php the_permalink();?> and <?php get_permalink();?> are rendering blank for me :(
    – mr.oizo
    Aug 6, 2013 at 17:28
  • Try removing H3 tag arround a tag. Aug 7, 2013 at 5:49
  • I've tried pasting it in different locations but it didn't work for me.
    – mr.oizo
    Aug 7, 2013 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.