Support » Fixing WordPress » Help creating a link that always points to the newest static page

  • Resolved chrisanthropic

    (@chrisanthropic)


    Hi all,

    I’m using WordPress as a CMS with the loop displayed on the main page.
    My wife posts a new chapter of her book every week as a PAGE (paginated) and then writes a POST with notes and a link to it.

    We’re creating a series of links in the header:
    “First Chapter”
    “Newest Chapter”
    “Next”
    “Previous”

    I’m using the “next-page-not-next-post” plugin for the next/previous links, but I can’t for the life of me figure out how to make a “Newest Chapter” link that dynamically links to the most recent static PAGE.

    The site’s still local only for now, but here’s a link to a screenshot for clarification.

    Thanks for the help!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Michael

    (@alchymyth)

    Forum Moderator

    something like this might work:

    <?php $latest = get_pages('number=1&sort_column=post_date&sort_order=desc');
    echo '<a href="' . get_permalink($latest[0]->ID) . '">Newest Chapter</a>'; ?>

    http://codex.wordpress.org/Function_Reference/get_pages
    http://codex.wordpress.org/Function_Reference/get_permalink

    It’s grabbing the latest post but still isn’t registering pages.

    Thanks though, that gives me somewhere to start – I’ll dig in to get_permalink a bit more.

    **Edit**
    Then again, reading through wp_get_pages it doesn’t make sense why it’s even pulling posts at all…now I’m really confused.

    Ah, got it. It didn’t like the fact that the new page was a sub page. Knowing that, I can get it figured out — Thank you so much for your help!

    For anyone interested, here is how I solved the issue (thanks to alchymyth’s code):

    <?php $latest = get_pages('number=1&sort_column=menu_order&sort_order=desc');
    echo '<a href="' . get_permalink($latest[0]->ID) . '">Newest Chapter</a>'; ?>

    No subpages but since she’s postings chapters from a book I just let non-chapter pages default to “order 0” and chapters use a 2 digit number where the first number is the book # and the second is the chapter #;

    so book 1 chapter 3 would be #13, chapter 4 is #14, etc. Table of Contents would be 10.

    Hope this helps with anyone else trying to publish stories online.

    Ok, I’m back.

    The code that Alchymyth provided works great unless I use parent/child pages.

    Our current setup is like this:
    -Books
    – Series 1
    – Book 1
    -Ch1
    -Ch2
    – Book 2
    -Ch 1
    – Series 2

    Etc.

    I’ve tried hundreds of variations of wp_list_pages but I don’t understand the code provided in the codex to list children and how to mix it with the code provided by Alchymyth.

    Currently I can only get it to list the newest page in a single given parent.

    Any suggestions?

    Michael

    (@alchymyth)

    Forum Moderator

    you are right – for some unexplained reason, get_pages() fails in some levels of child pages 🙁

    try this:

    <?php $latest = get_posts('numberposts=1&post_type=page&orderby=post_date&order=desc');
    echo '<a href="' . get_permalink($latest[0]->ID) . '">Newest Chapter</a>'; ?>

    Damn, that was quick. It worked, thank you yet again for the help. I truly appreciate it.

    Michael

    (@alchymyth)

    Forum Moderator

    gee – you are even quicker testing it 😉

    thanks for marking this thread as ‘resolved’

    Marked as solved.

    As a note, I tried orderby=menu_order and it works as well.

    Thanks again!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Help creating a link that always points to the newest static page’ is closed to new replies.