Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Keyboard navigation on WordPress

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #30801
    infocentre
    Member

    In creating a pretty unique themed wordpress site, i think it would be cool to have the ‘Left’ and ‘Right’ arrow keys to navigate from page to page (which would be next/prev post in wordpress).

    I came across this tutorial on how to write the JS, but can not figure out how to incorporate it with WordPress to use make a dynamic link upon page load for the next or previous post.

    This is how the code looks:

    document.onkeyup = KeyCheck;

    function KeyCheck(e)
    {
    var KeyID = (window.event) ? event.keyCode : e.keyCode;

    switch(KeyID)
    {

    }
    }
    document.onkeyup = KeyCheck;

    function KeyCheck(e)
    {
    var KeyID = (window.event) ? event.keyCode : e.keyCode;

    switch(KeyID)
    {
    case 37:
    window.location = "page.html"; //back
    break;

    case 39:
    window.location = "another-page.html"; //forward
    break;
    }
    }

    Cheers guys!

    #72186
    cybershot
    Participant

    you need to replace the

    window.location ="page.html";

    with the wordpress code that takes you to the older posts and the another-page.html with the newer post

    #54631
    thesaint
    Member

    do i just put that code anywhere in the single.php file?

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.