Wordpress

本文档展示了如何修改WordPress二级菜单类名,将默认的子菜单类名改为'submenu'和'san-ul'。同时,列举了调用当前栏目子分类、上一篇/下一篇文章标题及链接,以及分类名称和图片的方法。此外,提到了使用AdvancedCustomFields插件实现相册功能,展示了相册图片和相关元数据的输出方式。
摘要由CSDN通过智能技术生成

修改二级菜单类名

wp-includes/class-walker-nav-menu.php  42-103行

修改后 

	/**
	 * Starts the list before the elements are added.
	 *
	 * @since 3.0.0
	 *
	 * @see Walker::start_lvl()
	 *
	 * @param string   $output Used to append additional content (passed by reference).
	 * @param int      $depth  Depth of menu item. Used for padding.
	 * @param stdClass $args   An object of wp_nav_menu() arguments.
	 */
	public function start_lvl( &$output, $depth = 0, $args = array() ) {
		if( $depth == 0 ){
			$output .= '<ul class="submenu">';
		}else{
			$output .= '<ul class="san-ul">';
		}
	}

	/**
	 * Ends the list of after the elements are added.
	 *
	 * @since 3.0.0
	 *
	 * @see Walker::end_lvl()
	 *
	 * @param string   $output Used to append additional content (passed by reference).
	 * @param int      $depth  Depth of menu item. Used for padding.
	 * @param stdClass $args   An object of wp_nav_menu() arguments.
	 */
	public function end_lvl( &$output, $depth = 0, $args = array() ) {
		if( $depth == 0 ){
			$output .= "</ul>";
			}else{
			$output .= '</ul>';
			}
	}

 修改前

 调用当前栏目子分类

<?php
                $categories = get_categories($args);
                foreach ($categories as $category) { ?>
                    <?php
                    $argszi = array(
                        'child_of' => $category->term_id,
                        'parent' => $category->term_id,
                        'hide_empty' => '0',
                        'orderby' => 'ID',
                        'order' => 'ASC',
                    );
                    $categorieszi = get_categories($argszi);
                    foreach ($categorieszi as $categoryzi) {
                    ?>

                        <div class="col-md-4 lpcol1">
                            <a href="<?php echo get_category_link($categoryzi->term_id); ?>">
                                <?php echo $categoryzi->name; ?>
                            </a>
                        </div>

                <?php }
                }
                ?>

 调用上一篇下一篇标题和链接

<?php
$prev_post = get_previous_post(true, '', 'category');

if (!empty($prev_post)) : ?>

    <a href="<?php echo get_permalink($prev_post->ID); ?>">
        <div class="zb">
            <div class="circle">
                <i class="iconfont icon-zuojiantou"></i>
            </div>
        </div>
        <div class="nytxt">
            <?php echo $prev_post->post_title; ?>
        </div>
    </a>
<?php endif; ?>
</div>
<div class="fr">
    <?php

    $next_post = get_next_post(true, '', 'category');

    if (!empty($next_post)) : ?>
        <a href="<?php echo get_permalink($next_post->ID); ?>">
            <div class="nytxt">
                <?php echo $next_post->post_title; ?>
            </div>
            <div class="zb">
                <div class="circle">
                    <i class="iconfont icon-youjiantou"></i>
                </div>
            </div>
        </a>
    <?php endif; ?>

调用分类名称和图片

    <img src="<?php $thiscat = get_category($cat); if (function_exists('z_taxonomy_image_url')) echo z_taxonomy_image_url(salong_category_top_parent_id ($thiscat)); ?>" alt="" class="w100">



<?php $thiscat = get_category($cat);
                echo $thiscat->name;
                ?>

 相册功能:插件Advanced Custom Fields 专业版

字段-相册功能

<?php
                $photolist = get_post_meta($post->ID, 'imglist1', true);
                ?>
                <ul class="clearfix proul">
                    <?php if ($photolist) { ?>
                        <?php foreach ($photolist as $v) { ?>
                            <li class="fl proli">
                                <div class="cont">
                                    <img src="<?php echo wp_get_attachment_url($v); ?>" alt="" class="w100">
                                    <div class="content">
                                        <div class="name">
                                        
                                        <?php echo wp_get_attachment_caption($v); ?>
                                        <!-- 调用图片的说明文字 caption-->
                                        
                                        </div>
                                        <!-- <div class="circle">
                                            <i class="iconfont icon-youjiantou"></i>
                                        </div> -->
                                    </div>
                                </div>
                            </li>
                        <?php } ?>
                    <?php } ?>
                </ul>

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值