7

计划书之家主题ripro子主题导航菜单显示每日文章更新数量

作者 : 佩斯音频工作室 本文共2523个字,预计阅读时间需要7分钟 发布时间: 2023-04-9 共384人阅读

如果你的WordPress主题网站每天都更新大量的文章,而主页列表又不是类似于教程网那种小标题的列表,用户看上去就不知道每天到底更新了没有,更新了多少,这里我们给WordPress条件一个每日文章更新数量显示的功能,可以显示在导航栏或者其他地方,提示访客每日更新的内容。这个在网上教程集成到ripro主题,并在有更新时才提醒!

 操作步骤:

菜单 – 显示选项,勾出 “图像描述”,在项目的 “图像描述” 中添加需要显示更新数目的分类 id。

计划书之家主题ripro子主题导航菜单显示每日文章更新数量插图

 

网上教程:

// 注册菜单
register_nav_menus( array(
	'primary' => __( '我的菜单' ),
) );
// 强化菜单 调用代码 (php) wp_nav_menu( array( 'theme_location' => 'primary', 'walker' => new description_walker ) ); (/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        ) .'"' : '';
		$attributes .= ! empty( $item->url )        ? ' href="'%20%20%20. esc_attr( $item->url        ) .'"' : '';
 
		$prepend = '<span>';
		$append = '</span>';
		$description  = ! empty( $item->description ) ? '<span>'.esc_attr( $item->description ).'</span>' : '';
 
		if($depth != 0)
		{
			$description = $append = $prepend = "";
		}
 
		$item_output = $args->before;
		$item_output .= '<a'. $attributes .'>';
		$item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
		// seabye++
		if ( $item->description<=0 ) { $item_output .= $description; }
			else { $item_output .= '<span class="day">+'.get_this_week_post_count_by_category($item->description).'</span>'; }
		$item_output .= $args->link_after;
		// seabye++ end
		// $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 );
	}
}
// 强化菜单 代表时间
// 一日 today
// 一周 1 week ago
// 一年 1 year ago
// 千年 1000 year ago
function get_this_week_post_count_by_category($id) {
	$date_query = array(
		array(
			'after' => 'today'
			)
		);
	$tax_query = array(
		array(
			'taxonomy' => 'category',
				'field' => 'id',
				'terms' => $id
			)
		);
	$args = array(
		'post_type' => 'post',
		'post_status' => 'publish',
		'tax_query' => $tax_query,
		'date_query' => $date_query,
		'no_found_rows' => true,
		'suppress_filters' => true,
		'fields' => 'ids',
		'posts_per_page' => -1
		);
	$query = new WP_Query( $args );
	return $query->post_count;
}

如何调用代码如下,放在想要显示的页面位置即可。

<?php wp_nav_menu( array( 'theme_location' => 'primary', 'walker' => new description_walker ) ); ?>

 

如果要条件在菜单导航里面,红色加粗为需要添加的内容。

菜单 – 显示选项,勾出 “图像描述”,在项目的 “图像描述” 中添加需要显示更新数目的分类 id。

计划书之家主题ripro子主题导航菜单显示每日文章更新数量插图

 

支持技术 服务范围 1: 本网站名称:佩斯资源网
2: 本站永久网址:https://www.pstyw.com
3: 远程在线解决声卡各种问题排查/处理,各种声卡关联机架跳线,安装插件/机架/驱动,以及各种问题(20元起加一项加10元)QQ1943590279进行技术支持。
4: 在线一对一插件/机架/声卡跳线教学(50元起)。
5: 声卡效果调试,一对一根据人声声线精调,精调效果永久免费维护。不满意全额退款
注:免费维护,不再动效果。重装系统还原,修改效果参数,添加插件收费。一对一精调效果: 点击试听。
联系方式: 微信:CXY5520YP QQ:1943590279 QQ群:683643827 微信群:加微信,发会员帐号,佩斯邀请入群。
本站所有资源仅供学习与参考,请勿用于商业用途,如有侵犯版权,请及时联系1943590279@qq.com,我们将尽快删除处理。

佩斯资源网 » 计划书之家主题ripro子主题导航菜单显示每日文章更新数量


富强民主文明和谐自由平等公正 法制丨爱国敬业诚信友善

Copyright © 2021 佩斯音频网 All Rights Reserved
E-mail:1943590279@qq.com
安全运行
本站总访问量 本站访客数

在线人数:1人