I am trying to write a custom navigation menu for my custom wordpress theme.
<ul class="MainMenu nav navbar-nav ">
<li class="has-megamenu">
MENU
<div class="megamenu">
<ul class="container megamenu-background">
<li class="col-md-3 megamenu-column">
<h4>Column 1</h4>
<ul class="main-menu-ul">
<li>Menu Item</li>
<li>Menu Item</li>
<li>Menu Item</li>
</ul>
</li>
<li class="col-md-3 megamenu-column">
<h4>Column 2</h4>
<ul class="main-menu-ul">
<li>Menu Item</li>
<li>Menu Item</li>
<li>Menu Item</li>
</ul>
</li>
<li class="col-md-3 megamenu-column">
<h4>Column 3</h4>
<ul class="main-menu-ul">
<li>Menu Item</li>
<li>Menu Item</li>
<li>Menu Item</li>
</ul>
</li>
<li class="col-md-3 megamenu-column">
<h4>Column 4</h4>
<ul class="main-menu-ul">
<li>Menu Item</li>
<li>Menu Item</li>
<li>Menu Item</li>
</ul>
</li>
</ul>
</div>
</li>
<li class="dropdown">Contact</li>
<li class="dropdown">Our Story</li>
Problem is How Can I write this structure walker
This is how i manage to solve this using wordpress walker_nav_menu https://developer.wordpress.org/reference/classes/walker_nav_menu/
class Custom_Walker_Nav_Menu extends Walker_Nav_Menu {
/**
* Unique id for dropdowns
*/
public $submenu_unique_id = '';
/**
* Starts the list before the elements are added.
* #see Walker::start_lvl()
*/
public function start_lvl( &$output, $depth = 0, $args = array() ) {
if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
$t = '';
$n = '';
} else {
$t = "\t";
$n = "\n";
}
$indent = str_repeat( $t, $depth );
$before_start_lvl = '<div class="megamenu">';
if($depth==0){
$output .= "{$n}{$indent}{$before_start_lvl}<ul id=\"$this->submenu_unique_id\" class=\"container megamenu-background sub-menu dropdown-content\">{$n}";
}
else{
$output .= "{$n}{$indent}<ul id=\"$this->submenu_unique_id\" class=\"sub-menu dropdown-content\">{$n}";
}
}
/**
* Ends the list of after the elements are added.
* #see Walker::end_lvl()
*/
public function end_lvl( &$output, $depth = 0, $args = array() ) {
if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
$t = '';
$n = '';
} else {
$t = "\t";
$n = "\n";
}
$indent = str_repeat( $t, $depth );
$after_end_lvl = '</div>';
if($depth==0){
$output .= "$indent</ul>{$after_end_lvl}{$n}";
}
else{
$output .= "$indent</ul>{$n}";
}
}
/**
* #see Walker::start_el()
*/
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
$t = '';
$n = '';
} else {
$t = "\t";
$n = "\n";
}
$indent = ( $depth ) ? str_repeat( $t, $depth ) : '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$classes[] = 'menu-item-' . $item->ID;
// set active class for current nav menu item
if( $item->current == 1 ) {
$classes[] = 'active';
}
// set active class for current nav menu item parent
if( in_array( 'current-menu-parent' , $classes ) ) {
$classes[] = 'active';
}
/**
* Filters the arguments for a single nav menu item.
*/
$args = apply_filters( 'nav_menu_item_args', $args, $item, $depth );
// add a divider in dropdown menus
if ( strcasecmp( $item->attr_title, 'divider' ) == 0 && $depth === 1 ) {
$output .= $indent . '<li class="divider">';
} else if ( strcasecmp( $item->title, 'divider') == 0 && $depth === 1 ) {
$output .= $indent . '<li class="divider">';
} else {
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) );
//adding col-md-3 class to column
if( in_array('menu-item-has-children', $classes ) ) {
if( $depth === 1 ) {
$class_names = $class_names ? ' class="col-md-3 mega-menucolumn '.esc_attr( $class_names ) . '"' : '';
} else {
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
}
}else{
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
}
$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args, $depth );
$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
$output .= $indent . '<li' . $id . $class_names .'>';
$atts = array();
$atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : '';
$atts['target'] = ! empty( $item->target ) ? $item->target : '';
$atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
if( in_array('menu-item-has-children', $classes ) ) {
$atts['href'] = ' ';
$this->submenu_unique_id = 'dropdown-'.$item->ID;
} else {
$atts['href'] = ! empty( $item->url ) ? $item->url : '';
$atts['class'] = '';
}
$atts['class'] .= 'menu-item-link-class ';
$atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth );
$attributes = '';
foreach ( $atts as $attr => $value ) {
if ( ! empty( $value ) ) {
$value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
$attributes .= ' ' . $attr . '="' . $value . '"';
}
}
if( ! in_array( 'icon-only' , $classes ) ) {
$title = apply_filters( 'the_title', $item->title, $item->ID );
$title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth );
}
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
// set icon on left side
if( !empty( $classes ) ) {
foreach ($classes as $class_name) {
if( strpos( $class_name , 'fa' ) !== FALSE ) {
$icon_name = explode( '-' , $class_name );
if( isset( $icon_name[1] ) && !empty( $icon_name[1] ) ) {
$item_output .= '<i class="fa fa-'.$icon_name[1].'" aria-hidden="true"></i> ';
}
}
}
}
$item_output .= $args->link_before . $title . $args->link_after;
if( in_array('menu-item-has-children', $classes) ){
if( $depth == 0 ) {
$item_output .= ' <i class="fa fa-bolt" aria-hidden="true"></i>';
}
}
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
/**
* Ends the element output, if needed.
*
*/
public function end_el( &$output, $item, $depth = 0, $args = array() ) {
if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
$t = '';
$n = '';
} else {
$t = "\t";
$n = "\n";
}
$output .= "</li>{$n}";
}
} //
Rather than building this as one big Menu in the WordPress Admin, I'd suggest building a separate Menu for each column in the megamenu, and then one more for the Contact / About / Account links. The reason I'd do it that way is because you're including a Column Title for each megamenu column, and the WordPress Admin Menu UI doesn't include a way to add non-link items to menus out of the box. The easiest way to add the "Column Title" content and keep it editable would be to make individual Menus, and use the Menu Title as the Column Title.
For functions.php:
<?php
// Register the menus
add_action( 'after_setup_theme', 'register_menus' );
function register_menus() {
register_nav_menu( 'megamenu1', __( 'Megamenu Column 1', 'theme-text-domain' ) );
register_nav_menu( 'megamenu2', __( 'Megamenu Column 2', 'theme-text-domain' ) );
register_nav_menu( 'megamenu3', __( 'Megamenu Column 3', 'theme-text-domain' ) );
register_nav_menu( 'megamenu4', __( 'Megamenu Column 4', 'theme-text-domain' ) );
register_nav_menu( 'support', __( 'Support Menu', 'theme-text-domain' ) );
}
// Add the menu title
add_filter( 'wp_nav_menu_items', [ $this, 'include_menu_title' ], 10, 2 );
function include_menu_title( $nav_items, $args ) {
if ( ! isset( $args->show_title ) || false === $args->show_title ) {
return $nav_items;
}
if ( $args->theme_location && ( $locations = get_nav_menu_locations() ) && isset( $locations[ $args->theme_location ] ) ) {
$menu = wp_get_nav_menu_object( $locations[ $args->theme_location ] );
// Add the menu title. We add the UL element manually, because otherwise it would wrap AROUND the H4 later in execution of the wp_nav_menu function.
$nav_items = '<h4>' . $menu->name . '</h4><ul class="' . $args->menu_class . '">' . $nav_items . '</ul>';
}
return $nav_items;
}
// Add the dropdown class to support menu items.
add_filter('nav_menu_css_class', function($classes, $item, $args) {
if ( 'support' !== $args->theme_location ) {
return $classes;
}
$classes[] = 'dropdown';
return $classes;
}, 10, 3);
And then for header.php:
<ul class="MainMenu nav navbar-nav">
<li class="has-megamenu">
Megamenu
<div class="megamenu">
<div class="container megamenu-background">
<?php
$common_args = [
'show_title' => true, // This is a custom arg used to indicate we want the title included.
'items_wrap' => '%3$s', // Remove the UL element. We'll add it back at the right place in the filter.
'container_class' => 'col-md-3 megamenu-column',
'menu_class' => 'vpm-menu-ul',
];
wp_nav_menu( array_merge( ['theme_location' => 'megamenu1'], $common_args ) );
wp_nav_menu( array_merge( ['theme_location' => 'megamenu2'], $common_args ) );
wp_nav_menu( array_merge( ['theme_location' => 'megamenu3'], $common_args ) );
wp_nav_menu( array_merge( ['theme_location' => 'megamenu4'], $common_args ) );
?>
</div>
</div>
</li>
<?php
wp_nav_menu([
'theme_location' => 'support',
'items_wrap' => '%3$s', // Remove the UL element.
'container' => false, // Remove the container div.
]);
?>
</ul>
Related
I am developing Custom Theme and I want to display pagination in blog page.
Here's the wp_query:
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'posts_per_page' => 2,
'paged' => $paged
);
$the_query = new WP_Query( $args );
while ($the_query -> have_posts()) : $the_query -> the_post();
?>
The Code to display Title and Excerpt: and endwhile loop
<div class="titleline"><h2><?php the_title(); ?></h2></div>
<li><?php the_excerpt(__('(more…)')); ?></li>
<?php
endwhile;
wp_reset_postdata();
?>
And the Pagination Starts Here:
<div class="alignleft"><?php previous_posts_link('« Previous') ?></div>
<div class="alignright"><?php next_posts_link('More »') ?></div>
Am I missing anything here? Any suggestion will be appreciated..
Put this code in your template file
<?php
global $query_string;
query_posts($query_string . "post_type=post&post_status=publish&posts_per_page=2");
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h4><?php the_title(); ?></h4>
<h5>Posted By : <?php the_author(); ?> | Date : <?php echo the_date('d-m-y'); ?></h5>
<p><?php the_excerpt(); ?></p>
<?php endwhile;
endif; ?>
<?php pagination_numeric_posts_nav(); ?>
<?php wp_reset_query(); ?>
And put this function in functions.php file of theme
function pagination_numeric_posts_nav() {
if( is_singular() )
return;
global $wp_query;
/** Stop execution if there's only 1 page */
if( $wp_query->max_num_pages <= 1 )
return;
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$max = intval( $wp_query->max_num_pages );
/** Add current page to the array */
if ( $paged >= 1 )
$links[] = $paged;
/** Add the pages around the current page to the array */
if ( $paged >= 3 ) {
$links[] = $paged - 1;
$links[] = $paged - 2;
}
if ( ( $paged + 2 ) <= $max ) {
$links[] = $paged + 2;
$links[] = $paged + 1;
}
echo '<div class=""><ul class="pagination">' . "\n";
/** Previous Post Link */
if ( get_previous_posts_link() )
printf( '<li>%s</li>' . "\n", get_previous_posts_link() );
/** Link to first page, plus ellipses if necessary */
if ( ! in_array( 1, $links ) ) {
$class = 1 == $paged ? ' class="active"' : '';
printf( '<li%s>%s</li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
if ( ! in_array( 2, $links ) )
echo '<li>…</li>';
}
/** Link to current page, plus 2 pages in either direction if necessary */
sort( $links );
foreach ( (array) $links as $link ) {
$class = $paged == $link ? ' class="active"' : '';
printf( '<li%s>%s</li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
}
/** Link to last page, plus ellipses if necessary */
if ( ! in_array( $max, $links ) ) {
if ( ! in_array( $max - 1, $links ) )
echo '<li>…</li>' . "\n";
$class = $paged == $max ? ' class="active"' : '';
printf( '<li%s>%s</li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
}
/** Next Post Link */
if ( get_next_posts_link() )
printf( '<li>%s</li>' . "\n", get_next_posts_link() );
echo '</ul></div>' . "\n";
}
add this css in your style.css file
.navigation li a,
.navigation li a:hover,
.navigation li.active a,
.navigation li.disabled {
color: #fff;
text-decoration:none;
}
.navigation li {
display: inline;
}
.navigation li a,
.navigation li a:hover,
.navigation li.active a,
.navigation li.disabled {
background-color: #6FB7E9;
border-radius: 3px;
cursor: pointer;
padding: 12px;
padding: 0.75rem;
}
.navigation li a:hover,
.navigation li.active a {
background-color: #3C8DC5;
}
And check your reading setting
Change query_posts parameter if your blog page is not your static front page
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('posts_per_page'=>2,'paged'=>$paged);
query_posts($args);
I've changed my approach and edited the get_related_author fucntion, but its only bringing in 1 post can someone see where I'm going wrong?
function get_related_author_posts() {
global $authordata, $post;
$authors_posts = get_posts( array( 'author' => $authordata->ID,
'post__not_in' => array( $post->ID ), 'posts_per_page' => 5 ) );
foreach ( $authors_posts as $authors_post ) {
$output = '<div class="listio"><ul><li> <div class="author-post">';
$output .= '<div style="background: url(<?php echo $src[0]; ?> ) !important;
width: 80px; height: 50px; float: left; margin-right: 13px;
background-size: 80px 50px!important; background-color: pink;"></div>';
$output .= '<a href="' . get_permalink( $authors_post->ID ) . '">' .
apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) .
'</a>';
$output .= '</div></li></ul></div>';
}
return $output;
}
There you go:
function get_author_related_posts($author_id, $excluded_post){
global $wpdb;
$author_posts = $wpdb->get_results(
"
SELECT post_author, ID
FROM $wpdb->posts
WHERE post_author = '$author_id' and ID != '$excluded_post'
ORDER BY ID DESC
"
);
return $author_posts;
}
I found lots of methods to change the "sub-menu", but the problem is my friend coded a new Walker_Nav_Menu and here is the code.
All I want is:
to add a class in 3rd line where CLASS="ADD New HERE"
to change the class in 4th line, from <ul class="sub-menu"> to <ul class="dropdown">
again add a class in the 5th line, just like the 3rd line.
<ul id="menu-herid" class="nav navbar-nav" data-breakpoint="800">
<li id="menu-item-2821" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children">
<a CLASS="ADD New HERE" href="http://theme.dev/home/">Home</a>
<ul class="sub-menu">
<li id="menu-item-2838" class="menu-item menu-item-type-post_type menu-item-object-page">
Blog with Slideshow
</li>
</ul>
</li>
</ul>
// Navigation with description
if (! class_exists('hs_description_walker')) {
class hs_description_walker extends Walker_Nav_Menu {
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = 'class="dropdown"';
$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 ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
$description = ! empty( $item->description ) ? '<span class="desc">'.esc_attr( $item->description ).'</span>' : '';
if($depth != 0) {
$description = $append = $prepend = "";
}
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before;
if (isset($prepend))
$item_output .= $prepend;
$item_output .= apply_filters( 'the_title', $item->title, $item->ID );
if (isset($append))
$item_output .= $append;
$item_output .= $description.$args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
}
Now the thing is I wanted the sub-menu to be changed to ""
$defaults = array(
'theme_location' => '',
'menu' => 'menu-name',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'depth' => 0,
'walker' => new My_Walker_Nav_Menu() //call walker
);
//Add this in your theme functions.php file
class My_Walker_Nav_Menu extends Walker_Nav_Menu {
function start_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent<ul class=\"dropdown\">\n";
}
}
you try to this code...
HTML DEMO
Reference link
Wordress Code
<nav class="navbar-collapse collapse photoshoot-menu">
<?php wp_nav_menu(array('theme_location' => 'primary','container' => ' ')); ?>
</nav>
I am using wordpress and wants to add pagination to posts . code is ok bot ot is not working in chrome.When i am clicking on the pagination it goes to the current page and if i click on the next and previous link it goes to home url But in mozila and other browsers it is working fine . my code is
<?php
if ( !function_exists( 'appcara_pagination' ) ) {
function appcara_pagination($total) {
$prev_arrow = is_rtl() ? 'next' : 'prev';
$next_arrow = is_rtl() ? 'prev' : 'next';
global $wp_query;
//$total = $wp_query->max_num_pages;
//$total="10";
$big = 999999999; // need an unlikely integer
if( $total > 1 ) {
if( !$current_page = get_query_var('paged') )
$current_page = 1;
if( get_option('permalink_structure') ) {
$format = '/%#%/';
} else {
$format = '&paged=%#%';
}
echo paginate_links(array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => $format,
'current' => max( 1, get_query_var('paged') ),
'total' => $total,
'mid_size' => 3,
'type' => 'list',
'prev_text' => $prev_arrow,
'next_text' => $next_arrow,
) );
}
}
}
function appcara_paginate_links( $args = '' ) {
$defaults = array(
'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number
'total' => 1,
'current' => 0,
'show_all' => false,
'prev_next' => true,
'prev_text' => __('« Previous'),
'next_text' => __('Next »'),
'end_size' => 1,
'mid_size' => 2,
'type' => 'plain',
'add_args' => false, // array of query args to add
'add_fragment' => '',
'before_page_number' => '',
'after_page_number' => ''
);
$args = wp_parse_args( $args, $defaults );
extract($args, EXTR_SKIP);
// Who knows what else people pass in $args
$total = (int) $total;
if ( $total < 2 )
return;
$current = (int) $current;
$end_size = 0 < (int) $end_size ? (int) $end_size : 1; // Out of bounds? Make it the default.
$mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2;
$add_args = is_array($add_args) ? $add_args : false;
$r = '';
$page_links = array();
$n = 0;
$dots = false;
$prev_link = '<p class="prev-div" ><span class="prev-click"></span></p>';
if ( $prev_next && $current && 1 < $current ) :
$link = str_replace('%_%', 2 == $current ? '' : $format, $base);
$link = str_replace('%#%', $current - 1, $link);
if ( $add_args )
$link = add_query_arg( $add_args, $link );
$link .= $add_fragment;
/**
* Filter the paginated links for the given archive pages.
*
* #since 3.0.0
*
* #param string $link The paginated link URL.
*/
$prev_link = '<a class="prev-div" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '"><span class="prev-click"></span></a>';
endif;
for ( $n = 1; $n <= $total; $n++ ) :
if ( $n == $current ) :
$page_links[] = "<h3 class='page-numbers'>" . $before_page_number . number_format_i18n( $n ) . $after_page_number . "</h3>";
$dots = true;
else :
if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
$link = str_replace('%_%', 1 == $n ? '' : $format, $base);
$link = str_replace('%#%', $n, $link);
if ( $add_args )
$link = add_query_arg( $add_args, $link );
$link .= $add_fragment;
/** This filter is documented in wp-includes/general-template.php */
$page_links[] = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>" . $before_page_number . number_format_i18n( $n ) . $after_page_number . "</a>";
$dots = true;
elseif ( $dots && !$show_all ) :
$page_links[] = '<span class="page-numbers dots">' . __( '…' ) . '</span>';
$dots = false;
endif;
endif;
endfor;
$next_link = '<p class="next-div" ><span class="next-click"></span></p>';
if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) :
$link = str_replace('%_%', $format, $base);
$link = str_replace('%#%', $current + 1, $link);
if ( $add_args )
$link = add_query_arg( $add_args, $link );
$link .= $add_fragment;
/** This filter is documented in wp-includes/general-template.php */
//$page_links[] = '<a class="next page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $next_text . '</a>';
$next_link = '<a class="next-div" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '"><span class="next-click"></span></a>';
endif;
switch ( $type ) :
case 'array' :
return $page_links;
break;
case 'list' :
$r.='<div class="pagination">';
$r.=$prev_link;
$r .= "<ul class='page-numbers'>\n\t<li>";
$r .= join("</li>\n\t<li>", $page_links);
$r .= "</li>\n</ul>\n";
$r.=$next_link;
$r.='<div class="clear"></div></div>';
break;
default :
$r = join("\n", $page_links);
break;
endswitch;
return $r;
}
?>
calling this function
<?php
//WordPress loop for custom post type
$url=explode('/',$_SERVER['REQUEST_URI']);
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$my_query = new WP_Query('post_type=blogs&posts_per_page=10&paged='.$url['4']);
$total=wp_count_posts('blogs');
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div id="blogs">
<div class="content_blog custom_post" >
<h2><?php the_title(); ?></h2>
<i><?php echo get_the_date('', $post->ID).'-'.get_the_time('', $post->ID); ?></i>
<?php the_excerpt();
$term_list = wp_get_post_terms($post->ID, 'blog-cat');
echo "categories:-";
foreach($term_list as $key=>$cat)
{
echo "<a href='".get_term_link(intval($cat->term_id),'blog-cat')."'>".$cat->name.'</a>,';
}
?>
<?php ?>
</div>
</div>
<?php endwhile; wp_reset_query(); ?>
<?php appcara_pagination($total->publish/10);
?>
<style>
.pagination ul { list-style: none; border-left: 1px solid #d9d6d6; border-right: 1px solid #d9d6d6; float: left; width: 88%; }
.pagination ul li { display: inline-block; }
.pagination ul li a { display: block; font-size: 16px; font-weight: 600; color: #515050; padding: 6px 2px; }
.prev-div, .next-div { text-align: center; float: left; width: 68px; }
.prev-click, .next-click { display: inline-block; width: 10px; height: 16px; margin: 9px 0 0; }
.prev-click { background-position: -280px -311px; }
.next-click { background-position: -280px -331px; }
.prev-click:hover, .prev-div:hover .prev-click { background-position: -298px -311px; }
.next-click:hover { background-position: -301px -331px; }
.pagination ul li a:hover { color: #d75c43; }
</style>
You can use this code to functions.php file it's working fine..
/*************************************
* Wordpress pagination
**************************************/
function pagination($pages = '', $range = 3)
{
$showitems = ($range * 3)+1;
global $paged; if(empty($paged)) $paged = 1;
if($pages == '') {
global $wp_query; $pages = $wp_query->max_num_pages; if(!$pages)
{ $pages = 1; } }
if(1 != $pages)
{ echo "<div class='navigation'>";?>
<?php previous_posts_link();
echo "<div class='pagination'><ul>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<li><a rel='nofollow' href='".get_pagenum_link(1)."'>« First</a></li>";
if($paged > 1 && $showitems < $pages) echo "<li><a rel='nofollow' href='".get_pagenum_link($paged - 1)."' class='inactive'>‹ Previous</a></li>";
for ($i=1; $i <= $pages; $i++)
{ if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
{ echo ($paged == $i)? "<li class='current'><span class='currenttext'>".$i."</span></li>":"<li><a rel='nofollow' href='".get_pagenum_link($i)."' class='inactive'>".$i."</a></li>";
} } if ($paged < $pages && $showitems < $pages) echo "<li><a rel='nofollow' href='".get_pagenum_link($paged + 1)."' class='inactive'>Next ›</a></li>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a rel='nofollow' class='inactive' href='".get_pagenum_link($pages)."'>Last »</a>";
echo "</ul></div>";?>
<?php next_posts_link();
echo "</div>"; }
}
Use this on index file:
<?php pagination();?>
I am starting at WP theming, and it's been more than one day that I am looking to do the similar menu with the wp_nav_menu function :
<div class="ui simple dropdown item">
CATEGORY NAME WITH SUB-CATEGORIES
<i class="dropdown icon"></i>
<div class="menu">
<div class="item" >Sub Category 1</div>
<div class="item" >Sub Category 2</div>
</div>
</div>
Also, if there's no sub categories, the HTML output would be like this :
<div class="ui simple dropdown item">
CATEGORY NAME WITHOUT SUB-CATEGORY
</div>
What do I have to put in my functions.php ?
Any hint or any help would be very much appreciated !
Thanks.
Add next code to functions.php:
class SH_Nav_Menu_Walker extends Walker {
var $tree_type = array( 'post_type', 'taxonomy', 'custom' );
var $db_fields = array( 'parent' => 'menu_item_parent', 'id' => 'db_id' );
function start_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent";
$output .= "<i class=\"dropdown icon\"></i>\n";
$output .= "<div class=\"menu\">\n";
}
function end_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "$indent</div>\n";
}
function start_el(&$output, $item, $depth, $args) {
$value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$classes = in_array( 'current-menu-item', $classes ) ? array( 'current-menu-item' ) : array();
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
$class_names = strlen( trim( $class_names ) ) > 0 ? ' class="' . esc_attr( $class_names ) . '"' : '';
$id = apply_filters( 'nav_menu_item_id', '', $item, $args );
$id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';
$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 ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
$item_output = $args->before;
$item_output .= '<a'. $attributes . $id . $value . $class_names . '>';
$item_output .= '<div class="item">';
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= '</div>';
$item_output .= "</a>\n";
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
and call wp_nav_menu in the "right" place with next parameters:
wp_nav_menu(array('items_wrap' => '<div id="%1$s" class="%2$s ui simple dropdown item">%3$s</div>', 'theme_location' => 'sidebar_right_menu', 'walker' => new SH_Nav_Menu_Walker))