다른 메뉴 스타일링을 앞 페이지에 적용하는 방법은 무엇입니까?
-
21-12-2019 - |
문제
fullpage.js 을 사용하는 WordPress 사이트에서 두 번째 menustyling 을 얻는 방법을 알아 내려고합니다.
사용자 정의 워커가 있고 메뉴는 앵커 링크 에서 슬라이드로 작동합니다.나는 슬라이드에 대한 메뉴에서 스타일링을 변경하는 방법을 알아려고 노력하고 있으므로 프론트 페이지는 자체적으로 있습니다.
사이트 : http://www.svenssonsbild.se/svenssonsbild2
루프 :
<?php
if (($locations = get_nav_menu_locations()) && $locations['slides'] ) {
$menu = wp_get_nav_menu_object( $locations['slides'] );
$menu_items = wp_get_nav_menu_items($menu->term_id);
$pageID = array();
foreach($menu_items as $item) {
if($item->object == 'page')
$pageID[] = $item->object_id;
}
query_posts( array( 'post_type' => 'page','post__in' => $pageID, 'posts_per_page' =>
count($pageID), 'orderby' => 'post__in' ) );
}
while(have_posts() ) : the_post();
?>
<!-- <div id="<?php echo $post->post_name;?>" class="section"> -->
<div id="pageSlide-<?php echo $post->post_name;?>" class="section" data-anchor="<?php echo $post->post_name;?>">
.
워커 :
<?php
class description_walker extends Walker_Nav_Menu {
function start_el(&$output, $item, $depth, $args) {
global $wp_query;
$indent = ($depth)?str_repeat("\t", $depth):'';
$class_names = $value = '';
$classes = empty($item->classes)?array():(array) $item->classes;
$class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item));
$class_names = ' class="'.esc_attr($class_names).'"';
$output .= $indent.'<li id="menu-item-'.$item->ID.'"'.$value.$class_names.'>';
$attributes = !empty($item->attr_title)?' title="'.esc_attr($item->attr_title).'"':'';
$attributes .= !empty($item->target)?' target="'.esc_attr($item->target).'"':'';
$attributes .= !empty($item->xfn)?' rel="'.esc_attr($item->xfn).'"':'';
if($item->object == 'page') {
$varpost = get_post($item->object_id);
if(is_home()) {
$attributes .= ' href="#'.$varpost->post_name.'"';
}
else {
$attributes .= ' href="'.home_url().'/#'.$varpost->post_name.'"';
}
}
else
$attributes .= !empty($item->url)?' href="'.esc_attr($item->url).'"':'';
$item_output = $args->before;
$item_output .= '<a'.$attributes.'>';
$item_output .= $args->link_before.apply_filters('the_title', $item->title, $item->ID);
$item_output .= $args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
}
}
?>
. 해결책
슬라이드, 슬라이드가 아닌 첫 번째 섹션 (슬라이드가 아님)에 다른 스타일을 적용하려면 afterLoad
또는 onLeave
와 같은 플러그인 콜백을 사용하여 수행하려는 작업을 수행 할 것입니다.
같은 것 :
$.fn.fullpage({
slidesColor: ['red', 'blue'],
afterLoad: function (anchorLink, index) {
//if it is not in the 1st section, we apply sectionMenu class
if (index !=1 ) {
$('.demo').addClass('sectionMenu');
}
//otherwise, we remove it
else{
$('.demo').removeClass('sectionMenu');
}
}
});
.
다른 팁
WordPress 바디 클래스 사용
홈페이지에서 Body 태그는 <body class="home">
홈페이지에 대상 메뉴가 있음 :
.home .your-menu-selector
. 제휴하지 않습니다 StackOverflow