使用Customizr主题woocommerce的菜单栏wordpress中的搜索框

时间:2014-11-18 03:27:25

标签: php html html5 wordpress

Hello Guys我试图在我的菜单栏中放一个搜索框,我能够做到但是我怎样才能使用woocommerce搜索产品?

继承我在function.php中的当前代码:

add_filter( 'wp_nav_menu_items','add_search_box', 10, 2 );
function add_search_box( $items, $args ) {
$items .= '<li>' . get_search_form( false ) . '</li>';
    return $items;
}

我想将Woocommerce_product_search放入我的MENUBAR,任何人都可以帮助我。

对于英格兰人而言,我真的不太好。

1 个答案:

答案 0 :(得分:0)

在Functions.php中注册补充工具栏,然后将侧边栏添加到您希望显示搜索框的容器中。然后将Woocommerce搜索小部件添加到Wordpress管理界面内的侧边栏。

将此添加到Functions.php:

register_sidebar(array(
      'id' => 'search-widget',
      'name' => __('Search Widget'),
      'description' => __('Drag search widget to this container'),
      'before_widget' => '<article id="%1$s" class="widget %2$s">',
      'after_widget' => '</article>',
      'before_title' => '<h6>',
      'after_title' => '</h6>'      
  ));
}

将此添加到您的Header.php或包含搜索框需要的代码的文件中:

<?php dynamic_sidebar("search-widget"); ?>