Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tenman
Created March 5, 2014 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenman/9361514 to your computer and use it in GitHub Desktop.
Save tenman/9361514 to your computer and use it in GitHub Desktop.
WordPress theme Raindrops wp_nav_menu() show allways fixed page top.
<?php
/**
* Menu fixed
*
*
*
*/
define('NOBITA_QUERY', 'nobita_fixed_menu' );
define('NOBITA_VALUE_TYPE', 'js'); //または、css
$nobita_external_link_value =<<<SCRIPT
jQuery(function() {
jQuery(window).scroll(function () {
if (jQuery(this).scrollTop() > 100) {
jQuery('#access').css({'position':'fixed','top':'0','z-index':'999','margin':'0'});
jQuery('.logged-in #access').css({'position':'fixed','top':'29px','z-index':'999','margin':'0'});
} else {
jQuery('#access').css({'position':'static'});
jQuery('.logged-in #access').css({'position':'static'});
}
});
});
SCRIPT;
add_action( 'after_setup_theme', 'nobita_setup_theme' );
function nobita_setup_theme(){
add_filter('query_vars','nobita_extend_query');
add_action( 'wp_enqueue_scripts', 'nobita_add_style_link', 99 );
add_action( 'template_redirect', 'nobita_external_link_value' );
}
function nobita_extend_query( $vars ) {
$vars[] = NOBITA_QUERY;
return $vars;
}
function nobita_add_style_link() {
if( NOBITA_VALUE_TYPE == 'css' ){
wp_register_style( 'nobita-extend-style', sprintf('/?%1$s=1', NOBITA_QUERY ) );
wp_enqueue_style( 'nobita-extend-style' );
} elseif ( NOBITA_VALUE_TYPE == 'js' ) {
wp_register_script( 'nobita-extend-script', sprintf('/?%1$s=1', NOBITA_QUERY ) );
wp_enqueue_script( 'nobita-extend-script' );
}
}
function nobita_external_link_value( ) {
global $nobita_external_link_value;
if( intval( get_query_var( NOBITA_QUERY ) ) == 1 ) {
$mime_type = wp_get_mime_types( NOBITA_VALUE_TYPE );
if ( ! headers_sent( ) ) {
header( 'Content-type: '.$mime_type );
}
// add value check
if( NOBITA_VALUE_TYPE == 'css' ){
$nobita_external_link_value = strip_tags( $nobita_external_link_value );
} elseif ( NOBITA_VALUE_TYPE == 'js' ) {
$nobita_external_link_value = strip_tags( $nobita_external_link_value );
}
echo $nobita_external_link_value;
exit;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment