Show WordPress Primary Menu in Zurb Foundation header [_s theme ] - wordpress

I am creating a theme based on _s & Zurb's Foundation.
I have pretty much got everything set up and ready to start into the CSS, but I am having issues getting the 'primary menu' to show on the top bar.
I want to leave the 'left nav button' where it is, for a highlighted link (possibly contact us or similar), but I want to replace the current content in ul class="right" for the WordPress Primary Menu.
Here is what I have in the current header id="masthead"
<header id="masthead" class="site-header" role="banner">
<div class="row">
<div class="site-branding">
<h1 class="site-title">
<?php bloginfo( 'name' ); ?></h1>
<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
</div>
<div class="contain-to-grid sticky">
<nav id="site-navigation" class="top-bar" data-topbar data-options="sticky_on: large" role="navigation">
<ul class="title-area">
<li class="name">
<h4><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
<?php bloginfo( 'name' ); ?></a></h4>
</li>
<li class="toggle-topbar menu-icon">Menu</li>
</ul>
<section class="top-bar-section">
<!-- Right Nav Section -->
<ul class="right">
<li class="active">Right Button Active</li>
<li class="has-dropdown">
Right Button Dropdown
<ul class="dropdown">
<li>First link in dropdown</li>
</ul>
</li>
</ul>
<!-- Left Nav Section -->
<ul class="left">
<li>Left Nav Button</li>
</ul>
</section>
</nav><!-- #site-navigation -->
</div>
</div> <!-- row -->
</header><!-- #masthead -->

You need to use wp_nav_menu().
http://codex.wordpress.org/Function_Reference/wp_nav_menu
You will also need to use a walker which customises the output of wp_nav_menu() to match that of Foundation's top bar.
You can add this to your funtions.php
class guts_top_bar_walker extends Walker_Nav_Menu {
function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) {
$element->has_children = !empty($children_elements[$element->ID]);
$element->classes[] = ( $element->current || $element->current_item_ancestor ) ? 'active' : '';
$element->classes[] = ( $element->has_children ) ? 'has-dropdown' : '';
parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
}
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$item_html = '';
parent::start_el( $item_html, $item, $depth, $args, $id );
$output .= ($depth == 0) ? '<li class="divider"></li>' : '';
$classes = empty($item->classes) ? array() : (array) $item->classes;
if ( in_array( 'section', $classes ) ) {
$output .= '<li class="divider"></li>';
$item_html = preg_replace('/<a[^>]*>(.*)<\/a>/iU', '<label>$1</label>', $item_html);
}
$output .= $item_html;
}
function start_lvl( &$output, $depth = 0, $args = array() ) {
$output .= "\n<ul class=\"sub-menu dropdown\">\n";
}
}
You specify the walker within wp_nav_menu(). Replace the section area of the top bar in your header with the following;
<section class="top-bar-section">
<?php wp_nav_menu(array('container' => false, 'menu_class' => 'left', 'theme_location' => 'primary-left', 'fallback_cb' => false, 'walker' => new guts_top_bar_walker() )); ?>
<?php wp_nav_menu(array('container' => false, 'menu_class' => 'right', 'theme_location' => 'primary', 'walker' => new guts_top_bar_walker() )); ?>
</section>
Even if you want a highlighted link to remain in the left section, I'd recommend setting up another menu so that you can make future changes directly through the wordpress dash, instead of requiring edits to your theme.
You can register a new menu area like this in functions.php:
register_nav_menu( 'primary-left', __( 'Left Navigation Menu', 'guts' ) );
more info here: http://codex.wordpress.org/Function_Reference/register_nav_menus

Related

How to change Wordpress logo when scrolling (understrap-child theme)

I'm building a website using understrap-child theme.
What I would like to achieve is my navbar logo (added through Appearance -> Customize) to change into another one when scrolling the page.
In functions.php I've already added a section in order to be able to add a second logo, which I've successfully added in the Appearance -> Customize section.
Here's the code in functions.php:
//ADDING NEW LOGO FIELD
function your_theme_customizer_setting($wp_customize) {
// add a setting
$wp_customize->add_setting('your_theme_hover_logo');
// Add a control to upload the hover logo
$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'your_theme_hover_logo', array(
'label' => 'Upload Hover Logo',
'section' => 'title_tagline', //this is the section where the custom-logo from WordPress is
'settings' => 'your_theme_hover_logo',
'priority' => 8 // show it just below the custom-logo
)));
}
add_action('customize_register', 'your_theme_customizer_setting');
get_theme_mod( 'your_theme_hover_logo' );
Now that I have two logos set, I would like to know how to replace the first logo with the second one when scrolling my page.
Here's my header.php section with the navbar:
<!-- ******************* The Navbar Area ******************* -->
<div id="wrapper-navbar">
<a class="skip-link sr-only sr-only-focusable" href="#content"><?php esc_html_e( 'Skip to content', 'understrap' ); ?></a>
<nav id="main-nav" class="navbar navbar-expand-md navbar-dark fixed-top" aria-labelledby="main-nav-label">
<h2 id="main-nav-label" class="sr-only">
<?php esc_html_e( 'Main Navigation', 'understrap' ); ?>
</h2>
<?php if ( 'container' === $container ) : ?>
<div class="container">
<?php endif; ?>
<!-- Your site title as branding in the menu -->
<?php if ( ! has_custom_logo() ) { ?>
<?php if ( is_front_page() && is_home() ) : ?>
<h1 class="navbar-brand mb-0"><a rel="home" href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" itemprop="url"><?php bloginfo( 'name' ); ?></a></h1>
<?php else : ?>
<a class="navbar-brand" rel="home" href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" itemprop="url"><?php bloginfo( 'name' ); ?></a>
<?php endif; ?>
<?php } else {
the_custom_logo();
} ?><!-- end custom logo -->
Please notice that I've already added a Query in order to change the navbar background color when scrolling...and that works!
</script>
<script>jQuery(window).scroll(function(){
jQuery('nav').toggleClass('scrolled', jQuery(this).scrollTop() > 80);
});</script>
with its CSS rules:
#media (min-width: 992px) {
.navbar.scrolled {
background-color: $secondary;
border-bottom: solid rgba(37, 36, 36, 0.055);
I really hope you can help me solve my problem!
THANK YOU SO MUCH!!

How to link pagination results with Bootstrap nav tabs

I have 3 nav tabs (created using bootstrap) for sorting results using wp_query on my Library page.
The pagination works well, the problem I have is: when i click next or second on my pagination the active tab on Library page reverts to the first default sorting tab (recent).
My code is:
<?php
/**
* displays archive Library page
*/
get_header();
?>
<div id="page-header">
<section class="wrapper">
<div class="breadcrumbs">
You are here: Home / <span class="current">Library</span>
</div>
<h1 class="page-title half">Library</h1>
<div id="item-nav">
<div id="object-nav" class="item-list-tabs" role="navigation">
<ul class="tabs-nav tabs">
<li class="nav-three " data-tab="origin">Book origin</li>
<li class="nav-two " data-tab="year">Book release date</li>
<li class="nav-one current" data-tab="recent">Recent </li>
</ul>
</div><!-- /.item-list-tabs -->
</div><!-- /#item-nav -->
<div class="clear"></div>
</section>
</div><!-- /#page-header -->
<section class="wrapper">
<main class="tab-content current vocab-container" id="recent">
<ul class="blog-1 blog-1-full-width col-3 list-unstyled">
<div class='row'>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'library',
'post_type' => 'library',
'orderby' => 'meta_value',
'posts_per_page' => 9,
'paged' => $paged
);
$wp_query = new WP_Query( $args );
if ($wp_query->have_posts() ) : while( $wp_query->have_posts() ) : $wp_query->the_post();
get_template_part( 'template-parts/content/content', 'lib' );
endwhile; else:
// nothing was found
endif;
wp_reset_postdata(); /* Restore original Post Data */
twentynineteen_the_posts_navigation();
?>
</div>
</ul>
</main>
<main class="tab-content vocab-container" id="year">
<ul class="blog-1 blog-1-full-width col-3 list-unstyled">
<div class='row'>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_status' => 'published',
'post_type' => 'library',
'orderby' => 'meta_value_num',
'meta_key' => 'year',
'posts_per_page' => 9,
'paged' => $paged
);
$wp_query = new WP_Query( $args );
if ($wp_query->have_posts() ) : while( $wp_query->have_posts() ) : $wp_query->the_post();
get_template_part( 'template-parts/content/content', 'lib' );
endwhile; else:
// nothing was found
endif;
wp_reset_postdata(); /* Restore original Post Data */
twentynineteen_the_posts_navigation();
?>
</div>
</ul>
</main>
<main class="tab-content vocab-container" id="origin">
<ul class="blog-1 blog-1-full-width col-3 list-unstyled">
<div class='row'>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_status' => 'published',
'post_type' => 'library',
'orderby' => 'meta_value',
'meta_key' => 'origin',
'posts_per_page' => 9,
'paged' => $paged
);
$wp_query = new WP_Query( $args );
if ($wp_query->have_posts() ) : while( $wp_query->have_posts() ) : $wp_query->the_post();
get_template_part( 'template-parts/content/content', 'lib' );
endwhile; else:
// nothing was found
endif;
wp_reset_postdata(); /* Restore original Post Data */
twentynineteen_the_posts_navigation();
?>
</div>
</ul>
</main>
</section><!-- /.wrapper -->
<?php
get_footer();
?>
Link to my website Library page is: http://elluse.com/library/
I really appreciate you help. Lana :)
If someone has similar issue I found similar answered question on stackexchange website. Here is link.
https://wordpress.stackexchange.com/questions/151596/sorting-custom-posts-on-archive-page-with-pagination?newreg=a1f2074307b347d5aecc0b666dcff3be
<script>
function submitform(val) {
document.getElementById('sort-option').value = val;
document.getElementById('form-sort').submit();
}
</script>
<form id="form-sort" action="<?php echo get_permalink(); ?>" method="post">
<ul>
<li>Sort By:</li>
<li>Newest rating
</li>
<li>Highest rating
</li>
<li>Lowest rating
</li>
</ul>
<input type='hidden' id='sort-option' name='sort-option' value=''>
</form>
_____________________________________________________________________________
if($wp_query->get('page') == 0 && empty($_POST) && !empty($_SESSION)) session_unset();
if(!empty($_POST) || !empty($_SESSION)) {
switch($_POST['sort-option']) {
case 'newest':
$_SESSION["sort"] = SORT_DESC;
$_SESSION["sort_by"] = 'review_date';
break;
case 'highest':
$_SESSION["sort"] = SORT_DESC;
$_SESSION["sort_by"] = 'rating';
break;
case 'lowest':
$_SESSION["sort"] = SORT_ASC;
$_SESSION["sort_by"] = 'rating';
break;
}
foreach($reviews as $k => $v) {
$column_id[$k] = $v[$_SESSION["sort_by"]];
}
array_multisort($column_id, $_SESSION["sort"], SORT_NUMERIC, $reviews);
}

Show parent child taxonomy in nested tabs with its post

I want to show parent taxonomy in tab section and the under parent taxonomy i want to display child taxonomy in nested tab. On selection of child taxonomy i want to show its post. I am getting every time child taxonomy with with its post which i don't want.
Here is what i want:
TAB1(parent active) TAB2(parent)
ALL_TAB1(child active) SUB1_TAB1 SUB2_TAB1
(posts for all, sub1_tab1, sub2_tab1 and respectively whichever is active)
What i tried
<?php
/*
Template Name: Prac
*/
get_header();
// Get list of 'categories' for tabs -->
$args = array(
'hide_empty' => false,
'parent' => 0
);
$preferences = get_terms( 'preferences', $args );
?>
<div class="row">
<div class="col-md-12">
<?php
while ( have_posts() ) : the_post();
the_content();
endwhile; ?>
<ul class="nav nav-tabs" id="myTab" role="tablist">
<!-- Create the tabs -->
<?php
// Use counter so that 'active' class is only applied to first tab
$counter = 0;
foreach ($preferences as $preference) { ?>
<li class="nav-item">
<a class="nav-link <?= ($counter == 0) ? 'active' : '' ?>" id="<?php echo $preference->slug;?>-tab" data-toggle="tab" href="#<?php echo $preference->slug; ?>" role="tab" aria-controls="<?php echo $preference->slug;?>" aria-selected="<?= ($counter == 0) ? 'true' : 'false' ?>"><?php echo $preference->name; ?></a>
</li>
<?php $counter++; } ?>
</ul>
<div class="tab-content" id="nav-tabContent">
<!-- Get the content for each tab -->
<?php
$counter2 = 0;
foreach ($preferences as $preference) { ?>
<div role="tabpanel" class="tab-pane fade <?= ($counter2 == 0) ? 'show active' : '' ?>" id="<?php echo $preference->slug; ?>" aria-labelledby="<?php echo $preference->slug; ?>-tab">
<div class="row">
<?php
$args = array(
'post_type' => 'project',
'tax_query' => array(
array(
'taxonomy' => $preference->taxonomy,
'field' => $preference->slug,
'terms' => $preference->term_id
)
)
);
$loop = new WP_Query( $args );
?>
<div class="col-md-6" id="<?php echo $preference->slug . '-clauses' ?>">
<?php
?>
<?php
if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php
//Do something if a specific array value exists within a post
$term_list = wp_get_post_terms($post->ID, $preference->taxonomy, array("fields" => "all"));
?>
<?php foreach($term_list as $term_single) {
$category_children = get_terms(array(
'parent' => $term_single->term_id,
'hide_empty' => false
) );
$category_children_count = count($category_children);
?>
<?php } ?>
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<?php echo $term_single->name; ?>
</li>
</ul>
<a class="col-md-6" href="<?php echo the_permalink();?>"><?php the_post_thumbnail();?><?php echo the_title(); ?></a>
<?php endwhile; endif; wp_reset_query(); ?>
</div>
</div> <!-- end row -->
</div> <!-- end tab-pane -->
<?php $counter2++; } ?>
</div> <!-- end tab-content -->
</div> <!-- end col -->
</div> <!-- end row -->
<!-- end content -->
<?php get_footer(); ?>
I am getting like this
TAB1 TAB2
SUB1_TAB1
post
SUB1_TAB1
post
SUB1_TAB2
Can anyone help ? Thanks.

wordpress primary and secondary navigation

The below is my landing page "Products". it will display 2 columns, in the left is the secondary navigation and the right is the content. i want that if someone click in the primary navigation "Products". In second navigation the first item will in bold and will display the content.
<?php
/*
Template Name: Product Navigation Page
*/
?>
<?php get_header(); ?>
<div class="container page-border-top">
<div id="product-navigation" class="col-md-3" style="border: 1px solid green;">
<div id="navbar" class="navbar-collapse collapse">
<?php
$args2 = array(
'menu' => 'product-menu',
'menu_class' => 'nav navbar-nav',
'theme_location' => 'product-menu',
'container' => 'false'
);
wp_nav_menu( $args2 );
?>
</div><!--/.navbar-collapse -->
</div>
<div class="col-md-9" style="border: 1px solid red;">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
</div>
</div>
<?php get_footer(); ?>
If your landing page "Products" has no parent, and if all products child pages of "Products", then you can use this template file for the landing page and for all child pages (products):
<?php
/*
Template Name: Product Navigation Page
*/
$redirect = false;
$parent_id = wp_get_post_parent_id( $post->ID );
if ( ! $parent_id ) {
$redirect = true;
$parent_id = $post->ID;
}
// get all child's
$all_wp_pages = $wp_query->query(array(
'post_type' => 'page',
'order' => 'ASC',
'orderby' => 'menu_order',
'post_status' => 'publish'
));
$childs = get_page_children( $parent_id, $all_wp_pages );
if ( $redirect ) {
wp_redirect( get_permalink( $childs[0]->ID ) );
exit;
}
$current_page_id = $post->ID;
?>
<?php get_header(); ?>
<div class="container page-border-top">
<div id="product-navigation" class="col-md-3" style="border: 1px solid green;">
<div id="navbar" class="navbar-collapse collapse">
<ul class="menu">
<?php foreach ( $childs as $child ): ?>
<li class="<?php if ( $current_page_id == $child->ID ): ?>current-menu-item<?php endif; ?>"><?php echo $child->post_name; ?></li>
<?php endforeach; ?>
</ul>
</div><!--/.navbar-collapse -->
</div>
<div class="col-md-9" style="border: 1px solid red;">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
</div>
</div>
<?php get_footer(); ?>
You dont't have to create a menu for the products, it just list all child pages, and you can sort the products by the Order field (Page Attributes).
Step by Step:
Create a page "Products" and select the template file above for it (Product Navigation Page)
Create some product pages as childs of "Products" and select also the template file above for it (Product Navigation Page).
The template file will automaticly create the desired secondary navigation on the left side. The current product has a css class current-menu-item, so you can style it in bold.
This part generates the second nav:
<ul class="menu">
<?php foreach ( $childs as $child ): ?>
<li class="<?php if ( $current_page_id == $child->ID ): ?>current-menu-item<?php endif; ?>"><?php echo $child->post_name; ?></li>
<?php endforeach; ?>
</ul>

wordpress shortcode for tab

i added this by custom post type. but i want to create this by shortcode method with the conditional statement. how to do this ? please anyone ans this ?
<?php
$args = array( 'posts_per_page' => 4, 'post_type'=> 'tab-items');
$myposts = get_posts( $args );
?>
<!--nab section date content area-->
<div class="date_section_area">
<!-- Nav tabs -->
<div class="date_section_list">
<ul>
<?php foreach( $myposts as $post ) : setup_postdata($post); ?>
<li><?php the_title(); ?></li>
<?php endforeach;
wp_reset_postdata(); ?>
</ul>
</div>
<!-- Tab panes -->
<div class="date_section_content">
<?php foreach( $myposts as $post ) : setup_postdata($post); ?>
<div class="single_date_section_content tab-pane fade" id="<?php the_ID(); ?>">
<?php the_post_thumbnail('tab-image'); ?>
<?php the_content(); ?>
</div>
<?php endforeach;
wp_reset_postdata(); ?>
</div>
</div>
As far as i understand your question,
i have an idea that you can do like this:-
add_shortcode('my_post_shorcode', 'my_shortcode_function');
function my_shortcode_function($attr, $content)
{
extract(
shortcode_atts( array(
'posts_per_page' => '4',
'post_type' => 'tab-items',
'style' => 'default'
), $atts)
);
if($style == 'style-1')
{
//Add Your Style-1
} else if($style == 'style-2') {
//Add Your Style-2
} else {
$args = array( 'posts_per_page' => $posts_per_page, 'post_type'=> $post_type);
$myposts = get_posts( $args );
$tab_title = "";
$tab_content = "";
foreach ($myposts as $post)
{
setup_postdata($post);
$tab_title .= '<li>'.the_title().'</li>';
$tab_content .= '<div class="single_date_section_content tab-pane fade" id="tab-post-'.the_ID().'>
' . the_post_thumbnail('tab-image') . the_content() . '
</div>';
wp_reset_postdata();
}
?>
<!--nab section date content area-->
<div class="date_section_area">
<!-- Nav tabs -->
<div class="date_section_list">
<ul>
<?php echo $tab_title;?>
</ul>
</div>
<!-- Tab panes -->
<div class="date_section_content">
<?php echo $tab_content;?>
</div>
</div>
<?php
}
}
And shortcode will be like this:-
[my_post_shorcode posts_per_page="4" post_type="tab-items" style="default"]
Hope this will help you.

Resources