• Sorry for my bad english.
    I think it could be a challenge for a wp expert… I’ve googled for days and found nothing.
    I have a magazine-style wp theme. With some categories and subcategories. When in single posts, previous_post_link and next_post_link works well, but they includes the sticky post of the category (every category and subcategory has his own sticky post, wich is not intended to be properly a post, but a sort of description with links e.g. to a form). I want to exclude this sticky post from the navigation, because it ‘breaks’ the real continuity of ‘previous-next’.
    An sketch of my single.php:

    <em>// (commented out here in WP.org) get_header, etc.</em>
      <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       <?php
       // excludes this post from 'Related posts' in the sidebar
        $GLOBALS['current_id'] = $post->ID;
        if (is_sticky()) { ?>
        <div id="post-<?php the_ID(); ?>" <?php post_class('sticky'); ?>
      <em> // (commented out here in WP.org) title, content, etc.</em>
       <?php } else { ?>
       <div class="post" id="post-<?php the_ID(); ?>">
       <em>// (commented out here) title, time, entry, content, tags, etc.</em>
        <div class="navigation">
        <div class="alignleft"><?php next_post_link('&laquo;&laquo; %link', '%title', TRUE); ></div>
        <div class="alignright"><?php previous_post_link('%link &raquo;&raquo;', '%title', TRUE); ?></div>
        </div><!--/navigation-->
        <div class="clear"></div>
        <?php comments_template(); ?>
        <?php } ?>
        <?php endwhile; else: ?>
        <p>some text</p>
        <?php endif; ?>
    </div><!--/content-->
    <?php get_sidebar(); ?>
    <div class="clear"></div>
    <?php get_footer(); ?>
    <?php } ?>

    I’m sure it’s possible, but how? Any solution or idea? Please, without a plugin.
    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter falopiuss

    (@falopiuss)

    Is anyone there…?

    Well, I think that if WordPress team still bet on the sticky post feature, here is an interesting situation to consider. I know, I’ve ‘googled’ for days and tried to adapt the common solutions to the common problems related to sticky posts (not a wide range, a lot of blogs repeats the same few ideas and solutions), and It seems that the sticky feature has not been fully tested, it must get better at compatibility with other WP functions…
    There is no doubt it’s a feature that could make WP a platform with a greater potential.
    In the meantime, maybe somebody can suggest an ingenious solution or alternative way I cannot see now…

    I think you’ll need to exclude the sticky posts via a custom query>

    https://codex.www.ads-software.com/Function_Reference/query_posts#Sticky_Post_Parameters

    Hi Falopiuss,

    This is a problem w/ sticky posts that I have also experienced. There are a couple of ways to work around it.

    1) If you have LOTS of other posts in your blog, just set the publishing date to your sticky posts to be WAY back in the beginning of your blog. Then, they won’t really get in the way of previous/next navigation. This is a hacky and inelegant solution, but might tide you over.

    2) Rather than using sticky posts for category descriptions, you can use the “Category description field”. You can put whatever HTML you want in there, and it will show up IF your theme displays the category description.

    Cheers,

    Anca.

    Thread Starter falopiuss

    (@falopiuss)

    (sorry again for my poor english)
    @ esmi:
    Thanks, I appreciate your help, really. Unfortunately, I’ve tried yet your suggestion, via a custom query, with no luck. With a lot of variants (wp query, myquery, inside and outside the loop, with $args like post_not_in, etc.) Don’t work.

    @ ancawonka:
    You’re my angel!! I think you really suggest an ingenious solution, with a lot of sense! Changing the publishing date of the post… I like it! Not very orthodox, neither perfect, but probably efficient enough. I hope… If the sticky posts goes to the beginning of the navigation, not in the middle, I will feel better.
    I’ve thinked yet about something similar, but without an exact knowledge, no concisely.
    I’ve also thinked yet about the second solution, more concisely, but -call me stubborn if you want-, I didn’t want to renounce the use of the wp sticky functionality.
    Well, I don’t know exactly how to change the publishing date of a post, but I’m sure I will find it through a google search, when I have the time.
    Thank you very much!

    P.S. to WordPress developers: please, when you have the time, make the sticky function a little more compatible with the rest of functions… Anyway, I still think WP is a great platform!

    Thread Starter falopiuss

    (@falopiuss)

    Oops…
    It seems that this don’t work. I got too much excited hastily.
    Nevermind, I hope the WordPress team will solve this one day…
    Maybe I will investigate a bit. Curiosly I’ve observed the fact that previous_post_link shows the link to the first sticky post at the end of navigation, when viewing the last post. However, next_post_link does not show this same first sticky post at the beginning of navigation, when viewing the first post (I mean inside the sequence of the same category or subcategory).
    All this seems to be related to some lines in the file wp-includes/link-template.php. I’m going to ‘googling’ again about the functions inside that file, maybe a little hack is possible…

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Exclude sticky post from navigation in single.php’ is closed to new replies.