WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] using jquery for post navigation with keyboard (2 posts)

  1. rhonorginal
    Member
    Posted 2 years ago #

    Hello

    I have tried various code examples for implementation next/prev navigation of posts using the keyboard's arrow keys.

    Anyone got an example they know to work?

    These don't:

    html

    <ul class="step-nav clearfix">
        <li class="prev button">
            <?php previous_post_link('%link', 'Previous'); ?>
        </li>
        <li class="next button">
            <?php next_post_link('%link', 'Next'); ?>
        </li>
    </ul>

    js

    $(document).ready(function () {
    
        // This uses the Hotkeys jQuery plugin. See below for
        // the native jQuery alternative.
        $(document).bind('keydown', 'left', function() {
            var url = $('.prev a').attr('href');
            if (url) {
                window.location = url;
            }
        });
        $(document).bind('keydown', 'right', function() {
            var url = $('.next a').attr('href');
            if (url) {
                window.location = url;
            }
        });
    
    });
  2. rhonorginal
    Member
    Posted 2 years ago #

    sorry, above example works, I omitted the final semi

    see original doc here

Topic Closed

This topic has been closed to new replies.

About this Topic