如何为仅移动设备加载特定的Slider Revolution? [英] How to load a specific Slider Revolution for mobile-only?

查看:366
本文介绍了如何为仅移动设备加载特定的Slider Revolution?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道

.

It depends on how you are setting your revslider in your pages.

我认为,实现您真正想要的(需求)的最佳方法是使用带有条件规则的php:

I think that the best way to achieve what you really want (need) is using php with conditional rules:

1)在您的模板中有条件地基于移动检测.这样,您将避免同时加载2个时间.

1) In your templates with conditional based on mobile detection. This way you will avoid loading 2 revslider at the same time.

为此,您可以使用wp_is_mobile()有条件的wordpress功能:

You could use wp_is_mobile() conditional wordpress function for this purpose:

<?php
    if ( !wp_is_mobile() ) {
        echo do_shortcode('[rev_slider alias="my_desktop_slider"]');
    } 
    else
    {
        // mobile devices
        echo do_shortcode('[rev_slider alias="my_mobile_slider"]');
    }
?>

2)在具有该条件的自定义简码中:

2) In a custom shortcode with that conditional:

if( !function_exists('rev_slider_detection') ) {

    function rev_slider_detection( $atts ) {

        extract(shortcode_atts(array(
            'alias' => '' // the alias name of your desktop rev-slider
        ), $atts));

        $output = '[rev_slider alias="';

        if ( !wp_is_mobile() ) {
            // For desktop only
            $output .= $alias . '"]';
        } else {
            // For mobile only
            $output .= $alias . '_mob"]';
        }

        return $output;
        // or (because untested)
        // return do_shortcode('" . $output . "');
    }

    add_shortcode('my_rev', 'rev_slider_detection');
}

您将以这种方式使用它:[my_rev alias="my_revslider_alias_slug"],您将需要有2个rev滑块实例,第一个实例用于具有别名的台式机(例如home),第二个实例用于具有相同别名的移动设备别名 +"_mob" (例如home_mob).

You will use it this way: [my_rev alias="my_revslider_alias_slug"] and you will need to have 2 instance of a rev slider, the first one for desktop with some alias name ( home for example) and the second one for mobile with same alias name + "_mob" ( home_mob for example).

参考:

  • WP codex wp_is_mobile
  • WP codex do_shortcode
  • Shortcode Generator

您还可以精心设计更准确的脚本来检测平板电脑和手机,然后将其用作针对不同设备类型的条件.

You can also elaborate a more accurate script to detect tablets and phones, then use it as a conditional for different devices types.

这篇关于如何为仅移动设备加载特定的Slider Revolution?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆