얼마전에 티스토리 단축키를 워드프레스에 적용하는 방법이랑 티스토리에서의 단축키 의미(?)에 대해 올린글이 있다.
워드프레스에 티스토리 처럼 단축키로 페이지 넘기기를 해보자
근데 써보다 보니 이런 생각 든다 굳이 티스토리 처럼 할 필요 있는가! 여긴 워드프레스인데
뭐 거기다가 그 방식 그대로 쓰는 스킨이랑 블로그들이 어마어마 많으니 굳이 고집할 필요가 있을까 해서
워드프레스 있는 그대로 적용하기로 했다.
워드프레스에선 단축키를 이렇게 인식하면 편하다.
A 버튼은 페이지 좌측버튼 S 버튼은 페이지 우측 버튼
내용이 무엇인가 혹은 최신이냐 아니냐 다 신경 쓸 필요 없이 그냥 A는 좌측에 있는 버튼이라 생각하면 된다.
// 페이지 단축키 기능
// a는 좌측 버튼, s는 우측 버튼 대응
if ( ! function_exists( 'add_shortkey' ) ) :
function add_shortkey() {
//--------------------------------------------------------------------------
// 현재 주소값 가져오는 함수
function get_currentURL() {
$returnURL = '';
if ($_SERVER["HTTPS"] == "on"){
$returnURL = "https";
}else{
$returnURL = 'http';
}
$returnURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$returnURL .= $_SERVER["HTTP_HOST"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$returnURL .= $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
}
return $returnURL;
}
//--------------------------------------------------------------------------
//인자값이 true면 next 기능 false면 prev기능 URL
function linsoo_prev_next_url($goNext){
$currentURL = get_currentURL();
$formatlinsoo = 'location.href="%1$s"';
$result = "";
if( is_single()){
$wantURL = get_permalink(get_adjacent_post(false,'',!$goNext));
if ( strcmp($currentURL, $wantURL) )
$result = sprintf($formatlinsoo, $wantURL);
}
else{
if( $goNext ){
if ( get_next_posts_link() ){
$result = sprintf($formatlinsoo, next_posts(0,false));
}
}else{
if ( get_previous_posts_link() ){
$result = sprintf($formatlinsoo, previous_posts(false));
}
}
}
return $result;
}
//--------------------------------------------------------------------------
?>
<script language="JavaScript">
function movePage() {
var EventStatus = event.srcElement.tagName;
if(EventStatus!='INPUT'&&EventStatus!='TEXTAREA') {
//이전글
if (event.keyCode=='65' || event.keyCode=='97'){
<?php echo linsoo_prev_next_url(false); ?>
//다음글 S,s
}else if (event.keyCode=='83' || event.keyCode=='115') {
<?php echo linsoo_prev_next_url(true); ?>
//관리자페이지 Q,q
}else if (event.keyCode=='81' || event.keyCode=='113') {
location.href="<?php echo get_admin_url(); ?>";
}
}
}
document.onkeypress=movePage;
</script>
<?php }
add_action('wp_footer', 'add_shortkey');
endif;
// 페이지 단축키 기능
// a는 좌측 버튼, s는 우측 버튼 대응
if ( ! function_exists( 'add_shortkey' ) ) :
function add_shortkey() {
//--------------------------------------------------------------------------
// 현재 주소값 가져오는 함수
function get_currentURL() {
$returnURL = '';
if ($_SERVER["HTTPS"] == "on"){
$returnURL = "https";
}else{
$returnURL = 'http';
}
$returnURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$returnURL .= $_SERVER["HTTP_HOST"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$returnURL .= $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
}
return $returnURL;
}
//--------------------------------------------------------------------------
//인자값이 true면 next 기능 false면 prev기능 URL
function linsoo_prev_next_url($goNext){
$currentURL = get_currentURL();
$formatlinsoo = 'location.href="%1$s"';
$result = "";
if( is_single()){
$wantURL = get_permalink(get_adjacent_post(false,'',!$goNext));
if ( strcmp($currentURL, $wantURL) )
$result = sprintf($formatlinsoo, $wantURL);
}
else{
if( $goNext ){
if ( get_next_posts_link() ){
$result = sprintf($formatlinsoo, next_posts(0,false));
}
}else{
if ( get_previous_posts_link() ){
$result = sprintf($formatlinsoo, previous_posts(false));
}
}
}
return $result;
}
//--------------------------------------------------------------------------
?>
<script language="JavaScript">
function movePage() {
var EventStatus = event.srcElement.tagName;
if(EventStatus!='INPUT'&&EventStatus!='TEXTAREA') {
//이전글
if (event.keyCode=='65' || event.keyCode=='97'){
<?php echo linsoo_prev_next_url(false); ?>
//다음글 S,s
}else if (event.keyCode=='83' || event.keyCode=='115') {
<?php echo linsoo_prev_next_url(true); ?>
//관리자페이지 Q,q
}else if (event.keyCode=='81' || event.keyCode=='113') {
location.href="<?php echo get_admin_url(); ?>";
}
}
}
document.onkeypress=movePage;
</script>
<?php }
add_action('wp_footer', 'add_shortkey');
endif;
// 페이지 단축키 기능 // a는 좌측 버튼, s는 우측 버튼 대응 if ( ! function_exists( 'add_shortkey' ) ) : function add_shortkey() { //-------------------------------------------------------------------------- // 현재 주소값 가져오는 함수 function get_currentURL() { $returnURL = ''; if ($_SERVER["HTTPS"] == "on"){ $returnURL = "https"; }else{ $returnURL = 'http'; } $returnURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $returnURL .= $_SERVER["HTTP_HOST"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $returnURL .= $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]; } return $returnURL; } //-------------------------------------------------------------------------- //인자값이 true면 next 기능 false면 prev기능 URL function linsoo_prev_next_url($goNext){ $currentURL = get_currentURL(); $formatlinsoo = 'location.href="%1$s"'; $result = ""; if( is_single()){ $wantURL = get_permalink(get_adjacent_post(false,'',!$goNext)); if ( strcmp($currentURL, $wantURL) ) $result = sprintf($formatlinsoo, $wantURL); } else{ if( $goNext ){ if ( get_next_posts_link() ){ $result = sprintf($formatlinsoo, next_posts(0,false)); } }else{ if ( get_previous_posts_link() ){ $result = sprintf($formatlinsoo, previous_posts(false)); } } } return $result; } //-------------------------------------------------------------------------- ?> <script language="JavaScript"> function movePage() { var EventStatus = event.srcElement.tagName; if(EventStatus!='INPUT'&&EventStatus!='TEXTAREA') { //이전글 if (event.keyCode=='65' || event.keyCode=='97'){ <?php echo linsoo_prev_next_url(false); ?> //다음글 S,s }else if (event.keyCode=='83' || event.keyCode=='115') { <?php echo linsoo_prev_next_url(true); ?> //관리자페이지 Q,q }else if (event.keyCode=='81' || event.keyCode=='113') { location.href="<?php echo get_admin_url(); ?>"; } } } document.onkeypress=movePage; </script> <?php } add_action('wp_footer', 'add_shortkey'); endif;
하단에 나오던 좌우 버튼은 그냥 워드프레스 기본으로 제공하는거 그대로 써도 된다.
답글 남기기