【问题标题】:Different header.php for mobile devices on wordpress?wordpress 上移动设备的不同 header.php?
【发布时间】:2015-02-26 05:09:35
【问题描述】:

首先:抱歉我的英语不好,我来自德国。

我的 wordpress 主页在移动设备上的标题存在很大问题。 网址是:www.hd-sign.de

如果您在计算机上打开该页面,一切看起来都很好,但如果我在移动设备上打开该页面,左侧的文本框在“HD - Sign”文本上方,看起来很糟糕。

你可以在“am i responsive”上看到我的意思。

我将移动设备检测插件安装到 Wordpress 并将其添加到我的 custom.css 文件中:

include Mobile_Detect.php;
$detect = new Mobile_Detect;
if( ! $detect->isMobile() {
include "mobile_header.php";
}

else {
include "header.php";
}

但它不会工作。当然,我已将 header.php 和 mobile_header.php(不带盒装文本)安装到我的主主题文件夹中。

我在过去 5 小时内尝试了许多不同的方法,但仍然无法解决此问题。

非常感谢您的每一个回答!

编辑:

感谢您的每一个回答,实际上我得到了以下代码:

include Mobile_Detect.php;
$detect = new Mobile_Detect;
if( ! $detect->isMobile() ) : {
function get_header( 'mobile' );
}
else : {
function get_header();
endif;
}

我不确定这段代码是否正确,也不确定我是否必须将代码放在“general-template.php”或我的自定义 css 中。抱歉这个愚蠢的问题,但我刚刚开始使用 html 和 css。 如果有人能告诉我我必须把(正确的?)代码放在哪里,那就太好了!

谢谢!

【问题讨论】:

    标签: css wordpress mobile


    【解决方案1】:

    这样命名你的文件:

    header.php
    header-mobile.php
    

    并使用 WordPress 约定来调用您的标题,如下所示:

    // default
    get_header();
    
    // mobile
    get_header( 'mobile' );
    

    除此之外,我强烈建议您研究响应式网页设计和媒体查询。当页面首次加载时,您的标题将加载一次。当您使用此技术调整浏览器窗口大小时,它不会改变。

    资源:

    get_header() - http://codex.wordpress.org/Function_Reference/get_header 的 WordPress 函数参考

    【讨论】:

    • 谢谢!我这样命名文件并尝试了这段代码:include Mobile_Detect.php; $detect = new Mobile_Detect; if( ! $detect->isMobile() { include "mobile_header.php"; } else { include "header.php"; } 但它似乎仍然不起作用,我在general-template.php中编写了这段代码,我希望这是正确的。
    • 这完全不是我上面写的。你需要调用像get_header();get_header('mobile');这样的标题
    • 对不起,我复制了错误的代码,我的意思是:include Mobile_Detect.php; $detect = new Mobile_Detect; if( ! $detect->isMobile() ) : { function get_header( 'mobile' ); } else : { function get_header(); endif; }
    【解决方案2】:

    试试这个。

    if(!preg_match('/(iPhone|iPod|iPad|Android|BlackBerry)/i', $_SERVER['HTTP_USER_AGENT']))
    {
    include "mobile_header.php";
    }
    else
    {
    include "header.php";
    }
    

    【讨论】:

    • 非常感谢,但是没有用。我在custom.css和general-template.php中试过这段代码,好像不行。
    • 包含此代码并检查您的设备(手机或 iPad)。不要签入您的系统
    • 我做了,但它不起作用。如果我将代码包含到 general-template.php 中,则整个站点将不再加载。如果我把它放到 custom.css 文件中,什么也不会发生。你有想法吗?谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-23
    • 2023-03-06
    • 2020-03-08
    • 2018-11-12
    • 1970-01-01
    • 1970-01-01
    • 2013-03-11
    相关资源
    最近更新 更多