WordPress.org

Forums

Easy question! The first who anwser win a cookie (9 posts)

  1. poliquinp
    Member
    Posted 4 years ago #

    Where can I find the template for previous_post_link() and next_post_link() ?

    Anyone?

  2. alchymyth
    Forum Moderator
    Posted 4 years ago #

    a: not a very thematic title :-(

    b:
    a useful template file for this would be single.php

    for further inspiration,
    either have a look into loop-single.php of twenty ten (the default theme is always a good source of information)

    or in the codex:
    http://codex.wordpress.org/Function_Reference/previous_post_link
    http://codex.wordpress.org/Function_Reference/next_post_link

  3. poliquinp
    Member
    Posted 4 years ago #

    a : You still win a cookie

    b: I know that I can find it into the single.php.. But what doesn't help me.. I need to enter in the function because I would like to workarround with this.

    Do you know where I could find it?

  4. alchymyth
    Forum Moderator
    Posted 4 years ago #

    I need to enter in the function because I would like to workarround with this.

    can you explain what you are trying to achieve?

    do you mean where the functions are defined?

    general

    /wp-includes/link-template.php

    a useful site to find and follow functions:

    http://phpxref.ftwr.co.uk/wordpress/wp-includes/link-template.php.source.html#l1416

    http://phpxref.ftwr.co.uk/wordpress/wp-includes/link-template.php.source.html#l1402

  5. poliquinp
    Member
    Posted 4 years ago #

    I'm actually trying to let the "previous button" visible event if there is no more "previous Post" and the same for Next.

    My designer did this way..

  6. alchymyth
    Forum Moderator
    Posted 4 years ago #

    you could use a conditional with 'get_adjacent_post()' with the appropriate parameters; or with 'get_next_post()'

    'get_next_post()' returns empty if there is no further post in that direction.

    same for 'prev' resp.

    http://codex.wordpress.org/Function_Reference/get_adjacent_post

    i had dealt with that a while ago.

  7. poliquinp
    Member
    Posted 4 years ago #

    Your exemple works pretty well execpt the next/prev doesn't respect my categories..

    I can infinite "next" from all my posts.

    ++ Little problem... My next button stop showing at a moment..

    <div class="left">
    <?php if(get_adjacent_post(false, '', true)) { previous_post_link('%link', '<img src="btn-prev-page.gif">', 'true'); }
    else { echo '<img src="btn-prev-page-disable.gif">'; } ?>
    </div>
    
    <div class="right">
    <?php if(get_adjacent_post(false, '', false)) { next_post_link('%link', '<img src="btn-next-page.gif">', 'true'); }
    else { echo '<img src="btn-next-page-disable.gif">'; }  ?>
    </div>

    Before I was using this line of code to respect my categories

    <div class="right"><?php next_post_link('%link', '<img src="btn-next-page.gif">', 'true') ?></div>

    Do you know why this is happening?

  8. poliquinp
    Member
    Posted 4 years ago #

    Ok.. Almost awnser myself..

    Usage

    <?php get_adjacent_post( $in_same_cat, $excluded_categories, $previous ) ?>

    Parameters

    $in_same_cat
    (boolean) (optional) Whether post should be in same category.

    Default: false

    $excluded_categories
    (string) (optional) Excluded categories IDs.

    Default: ''

    $previous
    (boolean) (optional) Whether to retrieve previous post.

    Default: true

  9. poliquinp
    Member
    Posted 4 years ago #

    The script works fine but when the same post is in two categories, the script goes crazy...

    I can pass from Category X to Y and Z just because the Post is in the three categories, so my Next / Previous become completly useless.

    Any clues how to fix it?

Topic Closed

This topic has been closed to new replies.

About this Topic