我已经在外观>菜单下创建了一个名为“侧边栏菜单集合”的菜单
这是他们的阶层
Material
- marble
- onyx
- slate
- granite
Applications
- benchtops
- floors
- walls
products
- Slab
- pavers
- cladding
因此,当我在“材料”页面上时,我只希望列出其子菜单(大理石,ony玛瑙,板岩,花岗岩)。
如果我在“应用程序”页面中,它将显示(便笺本,地板,墙壁)。依此类推,我想根据页面的特色图片在每个子列表中添加特色图片。
这也将仅适用于父菜单(“材料”,“应用程序”,“产品”),并且如果您在子菜单上未显示任何列表,则为
答案 0 :(得分:0)
下面的代码您好使用只会显示特定页面的子页面
wp_list_pages( $args = '' ) {
$defaults = array(
'depth' => 1,
'show_date' => '',
'date_format' => get_option( 'date_format' ),
'child_of' => $post->ID,
'exclude' => '',
'title_li' => __( 'Pages' ),
'echo' => 1,
'authors' => '',
'sort_column' => 'menu_order, post_title',
'link_before' => '',
'link_after' => '',
'item_spacing' => 'preserve',
'walker' => '',
);
答案 1 :(得分:0)
对此有一个答案,来自post。
这工作得很好,我现在唯一的问题是如何在每个链接上添加特色图片。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".SignUpFragment"
app:cardUseCompatPadding="true"
app:cardElevation="4dp"
app:cardCornerRadius="3dp"
android:layout_marginBottom="16dp"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="16dp">
<TextView
android:id="@+id/textViewname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="@string/name1"
android:textColor="@color/grey"
android:textSize="14sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/signup_name"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="32dp"
android:hint="@string/enter_your_name"
android:inputType="text"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/textViewname"
app:layout_constraintTop_toBottomOf="@+id/textViewname" />
<TextView
android:id="@+id/textViewemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/email2"
android:textColor="@color/grey"
android:textSize="14sp"
app:layout_constraintStart_toStartOf="@+id/textViewname"
app:layout_constraintTop_toBottomOf="@+id/signup_name" />
<EditText
android:id="@+id/signup_email"
android:layout_width="0dp"
android:layout_height="56dp"
android:layout_marginTop="8dp"
android:inputType="textEmailAddress"
android:hint="@string/enter_your_email"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="@+id/signup_name"
app:layout_constraintStart_toStartOf="@+id/signup_name"
app:layout_constraintTop_toBottomOf="@+id/textViewemail" />
<TextView
android:id="@+id/textViewpassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/password"
android:textColor="@color/grey"
android:textSize="14sp"
app:layout_constraintStart_toStartOf="@+id/textViewemail"
app:layout_constraintTop_toBottomOf="@+id/signup_email" />
<EditText
android:id="@+id/signup_password"
android:layout_width="0dp"
android:layout_height="56dp"
android:layout_marginTop="8dp"
android:inputType="textPassword"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="@+id/signup_email"
app:layout_constraintStart_toStartOf="@+id/signup_email"
app:layout_constraintTop_toBottomOf="@+id/textViewpassword" />
<TextView
android:id="@+id/textViewconfirmpassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/confirm_password"
android:textColor="@color/grey"
android:textSize="14sp"
app:layout_constraintStart_toStartOf="@+id/textViewpassword"
app:layout_constraintTop_toBottomOf="@+id/signup_password" />
<EditText
android:id="@+id/signup_confirmpassword"
android:layout_width="0dp"
android:layout_height="56dp"
android:layout_marginTop="8dp"
android:inputType="textPassword"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="@+id/signup_password"
app:layout_constraintStart_toStartOf="@+id/signup_password"
app:layout_constraintTop_toBottomOf="@+id/textViewconfirmpassword" />
<Button
android:layout_width="0dp"
android:layout_height="36dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:background="@color/colorPrimaryDark"
android:text="@string/sign_up"
android:textColor="@color/white"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="@+id/signup_confirmpassword"
app:layout_constraintStart_toStartOf="@+id/signup_confirmpassword"
app:layout_constraintTop_toBottomOf="@+id/signup_confirmpassword" />
</android.support.constraint.ConstraintLayout>
</ScrollView>
</android.support.v7.widget.CardView>
用法
// add hook
add_filter( 'wp_nav_menu_objects', 'my_wp_nav_menu_objects_sub_menu', 10, 2 );
// filter_hook function to react on sub_menu flag
function my_wp_nav_menu_objects_sub_menu( $sorted_menu_items, $args ) {
if ( isset( $args->sub_menu ) ) {
$root_id = 0;
// find the current menu item
foreach ( $sorted_menu_items as $menu_item ) {
if ( $menu_item->current ) {
// set the root id based on whether the current menu item has a parent or not
$root_id = ( $menu_item->menu_item_parent ) ? $menu_item->menu_item_parent : $menu_item->ID;
break;
}
}
// find the top level parent
if ( ! isset( $args->direct_parent ) ) {
$prev_root_id = $root_id;
while ( $prev_root_id != 0 ) {
foreach ( $sorted_menu_items as $menu_item ) {
if ( $menu_item->ID == $prev_root_id ) {
$prev_root_id = $menu_item->menu_item_parent;
// don't set the root_id to 0 if we've reached the top of the menu
if ( $prev_root_id != 0 ) $root_id = $menu_item->menu_item_parent;
break;
}
}
}
}
$menu_item_parents = array();
foreach ( $sorted_menu_items as $key => $item ) {
// init menu_item_parents
if ( $item->ID == $root_id ) $menu_item_parents[] = $item->ID;
if ( in_array( $item->menu_item_parent, $menu_item_parents ) ) {
// part of sub-tree: keep!
$menu_item_parents[] = $item->ID;
} else if ( ! ( isset( $args->show_parent ) && in_array( $item->ID, $menu_item_parents ) ) ) {
// not part of sub-tree: away with it!
unset( $sorted_menu_items[$key] );
}
}
return $sorted_menu_items;
} else {
return $sorted_menu_items;
}
}