Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter szury

    (@szury)

    Thanks Esmi. Checked that page already, but i couldn’t figure it out how to do it with pages. Could you post the exact code?

    Try something like:

    <ul class="recent-pages"><?php
    $args = array( 'posts_per_page' => 5, 'post_type' => 'page');
    $postslist = get_posts( $args );
    foreach ($postslist as $post) :  setup_postdata($post); ?> 
    
    <li><a>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>

    [Untested]

    Thread Starter szury

    (@szury)

    unfortunately it is not working 🙁

    Moderator keesiemeijer

    (@keesiemeijer)

    I tested and changed it a little, try it with this:

    <?php
    $args = array( 'posts_per_page' => 5, 'post_type' => 'page');
    $postslist = get_posts( $args );
    if($postslist) : ?>
    <ul class="recent-pages"><?php
    foreach ($postslist as $post) :  setup_postdata($post); ?>
    <li><a><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>
    <?php endif; ?>

    Thread Starter szury

    (@szury)

    Doesn’t work. This is what I get: http://img13.imageshack.us/img13/9085/unled23n.png

    I just copy pasted what you said as a sidebar widget. Have I done something wrong?

    Moderator keesiemeijer

    (@keesiemeijer)

    This is in sidebar.php right?
    Can you paste and submit the full code of sidebar.php of your theme into a pastebin.com and post the link to it here? see the Forum Rules for posting code and using the pastebin.

    Thread Starter szury

    (@szury)

    found out it works if I add it to the sidebar file. Thanks guys 🙂

    Thread Starter szury

    (@szury)

    There is another problem now.
    keesiemeijer i am using your version. It shows the titles of the most recent pages but it doesn’t link to anything. How can I fix it?

    Thread Starter szury

    (@szury)

    FOUND THE SOLUTION!

    Add this to sidebar.php:

    <?php
    $args = array( 'posts_per_page' => 5, 'post_type' => 'page');
    $postslist = get_posts( $args );
    if($postslist) : ?>
    <ul class="recent-pages"><?php
    foreach ($postslist as $post) :  setup_postdata($post); ?>
    <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>
    <?php endif; ?>

    Thanks to esmi and keesiemeijer

    Moderator keesiemeijer

    (@keesiemeijer)

    Try changing this:

    <li><a><?php the_title(); ?></a></li>

    to this:

    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>

    Moderator keesiemeijer

    (@keesiemeijer)

    Your code is even better, well done! Glad you got it resolved.

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘Display 5 recent pages?’ is closed to new replies.