WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] using jquery for post navigation with keyboard

[Resolved] using jquery for post navigation with keyboard

  • 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;
            }
        });
    
    });
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] using jquery for post navigation with keyboard’ is closed to new replies.
Skip to toolbar