0

I'm developing an responsive WordPress theme.

On a regular computer (full-size) a menu is visiblie like:

<div id="header-menu" role="complementary">    
     <ul>
         <?php wp_list_pages('title_li=&depth=1&link_before=<span>&link_after=</span>'); ?>
     </ul>
</div>

On a certain width (for mobile devices and tablets I'd like to replace this menu with a menu like this one:

<div id="header-menu-mobile" role="complementary">
       <form action="<?php bloginfo('url'); ?>" method="get">
       <?php

       $args1e = array(
        'depth'            => 1,
        'child_of'         => 0,
        'selected'         => 0,
        'echo'             => 1,
        'name'             => 'page_id');

        wp_dropdown_pages( $args1e ); ?>

       </form>
    <script type="text/javascript"><!--
    var dropdown = document.getElementById("page_id");
    function onCatChange()
    {
        if ( dropdown.options[dropdown.selectedIndex].value > 0 )
        {
            location.href = "<?php echo get_option('home');
            ?>/?page_id="+dropdown.options[dropdown.selectedIndex].value;
        }
    }
    dropdown.onchange = onCatChange;
    --></script>
</div>

I could in the css for a certain width set "header-menu" to hidden... and make "header-menu-mobile" set to visible. I'm kinda tired in my head and there's probably a better solution to make this work.

Any ideas on how?

Kind regards Johan

4

2 回答 2

0

你的CSS想法是对的。坚持下去。使用此标准 CSS 结构使您的网站具有响应性。

/* Large desktop */
@media (min-width: 1200px) { ... }

/* Portrait tablet to landscape and desktop */
@media (min-width: 768px) and (max-width: 979px) { ... }

/* Landscape phone to portrait tablet */
@media (max-width: 767px) { ... }

/* Landscape phones and down */
@media (max-width: 480px) { ... } 
于 2013-08-22T12:23:47.537 回答
0

尝试 $_SERVER['HTTP_USER_AGENT']; 它会告诉您有关用户操作系统和浏览器的信息。您可以相应地构建您的代码示例 -

if $_SERVER['HTTP_USER_AGENT'] == 'win 8'
echo $menu_for_windows ;
else if $_SERVER['HTTP_USER_AGENT'] =='opera mini'
echo $menu_for_mobile 

等等 ..

$browser = get_browser(null, true);
echo $browser['platform'] ; exit;

可以告诉你用户平台

于 2013-08-22T12:08:08.847 回答