Forums

1 article per page & descriptive next/previous links (7 posts)

  1. sknob
    Member
    Posted 5 years ago #

    I have a comic strip blog in which I have one strip per page (see http://geeksinlove.free.fr/). The theme is a modified Kubrick.

    So in effect, there is no difference in presentation when I access the blog normally (via index.php) or via a specific post (?=11).

    The one difference is that when I access via a specific post, the next/previous links show the strip descriptive titles (see http://geeksinlove.free.fr/?=11). When I access via the general URL, the next/previous links are a generic ("previous" / "next").

    I would like my next/previous links to use the post/comic strip titles when I access the blog via index.php.

    The "previous_post_link" function from single.php doesn't work in index.php (which uses "previous_posts_link").

    Any idea how I might get the descriptive links in index.php?

    Thanks in advance.

  2. tsguitar
    Member
    Posted 5 years ago #

    The only thing that would show up on index.php would be the most current comic and the previous one, right? I don't see a way that there would be any "next" when you're on the main index template. So you want to format the latest post to show the actual comic and the previous post to show the title only, right? Check this page out:
    http://codex.wordpress.org/The_Loop

    Set your preferences to only show 2 posts on your index page. This, taken from the above codex page and with only one thing changed, should allow you to format the latest post however you want:
    <?php $my_query = new WP_Query('showposts=1');
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID; ?>
    <!-- Do stuff... -->
    <?php endwhile; ?>

    Now, you'll grab the next available post:
    <?php if (have_posts()) : while (have_posts()) : the_post();
    if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
    <!-- Do stuff... -->
    <?php endwhile; endif; ?>

    I've used almost exactly that code in the past and it works just fine. Does this do what you want?

  3. sknob
    Member
    Posted 5 years ago #

    Thanks for your reply.

    'The only thing that would show up on index.php would be the most current comic and the previous one, right?"

    Actually, no, I want just ONE post on the index page (see the site http://geeksinlove.free.fr/). I want the /"previous" link/ to show the /title/ of the previous post, instead of simply a generic "previous page" type of message.

    So I'm not sure that the solution you outlined is applicable.

  4. tsguitar
    Member
    Posted 5 years ago #

    You actually want TWO posts on the home page, it's just that you want them formatted differently. You want the most recent post to show the comic and the other post to only show the title. See what I mean? The solution I suggested should work just fine for that.

  5. moshu
    Member
    Posted 5 years ago #

    So in effect, there is no difference in presentation when I access the blog normally (via index.php) or via a specific post (?=11).

    Actually, there is. A huge difference. WP is very well aware whether you are on the index (in WP code terms: is_home) or you are on a single post (is_single) - regardless of the number of posts shown on the index!
    That's why the previous_post_link doesn't work on the index. That tag is designed to be used on a single post view.

    This thread might be able to help you:
    http://wordpress.org/support/topic/43446?replies=3

  6. sknob
    Member
    Posted 5 years ago #

    tsguitar, I understand what you mean now.

    Moshu, thanks for the thread reference. I think that approach would be easier, given my limited php chops.

    Thanks to both of you! I'll experiment and let you know how I fare.

  7. sknob
    Member
    Posted 5 years ago #

    I tried moshu's suggestion and it works great.

    I put the code in my theme's index, which I prefer, because it means all my customizations are in the theme and not in WP's files.

    I do have one more problem though. it turns out that if I set $wp_query->is_single = true;, then the the comments_popup_link()doesn't work (no link shows up).

    Argh. Any suggestions would be welcome.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags