Разные мобильные и основная версии сайта на WP

Last update: 22 Квітня, 2023

Category: PHP code examples

  • Папка темы
    • blog
      • images
      • initialization
      • blog.css
    • check_ip [мануал в архиве]
    • fonts
    • include
    • lp
      • lp_main
        • mobile
          • images
          • initialization
          • lp_main_mobile.css
        • classic
          • images
          • initialization
          • lp_main_classic.css
        • lp_main_mobile.php
        • lp_main_classic.php
    • universal
      • counter.php
      • consultant.php
    • footer.php
    • functions.php
    • header.php
    • index.php
    • lp_main.php
    • page.php
    • screenshot.php
    • sidebar.php
    • single.php
    • style.css

Дополнительные инструкции

Создание шаблона страницы landing page типа lp_main делается по:

Пример:

<?php /* Template Name: lp_main */?>

<?php $detect = new Mobile_Detect;
if ( $detect->isMobile() ) {
<!-- Код мобильной версии -->
<?php } else { ?>
<!-- Код стационарной версии -->
<?php } ?>

Или в нашем случае всё можно свести к коду:

<?php /* Template Name: lp_main */

$detect = new Mobile_Detect;
if ( $detect->isMobile() ) {
require( "lp/lp_main/lp_main_mobile.php" );
} else {
require( "lp/lp_main/lp_main_classic.php" );
} ?>

Также можно подключить в конце файлы счетчиков, консультанта, защиты от копирования контента:

<?php /* Template Name: lp_main */

$detect = new Mobile_Detect;
if ( $detect->isMobile() ) {
require( "lp/lp_main/lp_main_mobile.php" );
} else {
require( "lp/lp_main/lp_main_classic.php" );
};
require( "universal/counter.php" );
require( "universal/consultant.php" );
require( "check_ip/access_to_context_menu.php" );
?>