wordpress键盘翻页功能

2014-06-03 23:11 wordpress键盘翻页功能已关闭评论

将代码加入到当前使用的wordpress主题的functions.php文件中(PS:代码加到第一个之后),即可。(PS:添加以上代码后即可使用左右方向键进行翻页~~)

<?php
add_action(‘wp_footer’,’v7v3_keyCode’);
function v7v3_keyCode(){
global $paged, $wp_query;
if ( !$max_page )
$max_page = $wp_query->max_num_pages;
if ( !$paged )
$paged = 1;
$nextpage = intval($paged) + 1;
?>
<?php if( is_single() ) : ?>
<script type=”text/javascript”>
document.onkeydown = v7v3_page;function v7v3_page(e) {
var e = e || event,
keycode = e.which || e.keyCode;
var obj = e.target || e.srcElement;
if(obj.tagName.toLowerCase()==”textarea”){return;}
if(obj.tagName.toLowerCase()==”input”){return;}
if (keycode == 37) location = ‘<?php echo get_permalink(get_adjacent_post(false,”,false)); ?>’;
if (keycode == 39) location = ‘<?php echo get_permalink(get_adjacent_post(false,”,true)); ?>’;
}
</script>
<?php elseif( is_home() || is_category() ) : ?>
<script type=”text/javascript”>
document.onkeydown = v7v3_page;function v7v3_page(e) {
var e = e || event,
keycode = e.which || e.keyCode;
var obj = e.target || e.srcElement;
if(obj.tagName.toLowerCase()==”textarea”){return;}
if(obj.tagName.toLowerCase()==”input”){return;}
if (keycode == 37) location = ‘<?php echo get_previous_posts_page_link(); ?>’;
if (keycode == 39)
<?php if ( $nextpage <= $max_page ) : ?>
location = ‘<?php echo get_next_posts_page_link(); ?>’;
<?php else : ?>
location = ‘<?php echo get_pagenum_link( $max_page ); ?>’;
<?php endif; ?>
}
</script>
<?php endif; ?>
<?php
}
?>

 

引用自:http://www.v7v3.com/wpjiaocheng/2014111317.html