Php 如何在页眉中显示Wordpress滑块代码仅在主页中显示

Php 如何在页眉中显示Wordpress滑块代码仅在主页中显示,php,jquery,wordpress,slider,nivo-slider,Php,Jquery,Wordpress,Slider,Nivo Slider,您好,我是wordpress定制中的新蜜蜂,这是滑块代码,我想将此代码插入到标题中并仅显示在主页上,请帮助我 <?php $slider_option = get_theme_mod('wp_store_homepage_setting_slider_option',0); if ($slider_option == '1'): do_action('wp_store_slider_section'); // Slider section- this function is i

您好,我是wordpress定制中的新蜜蜂,这是滑块代码,我想将此代码插入到标题中并仅显示在主页上,请帮助我

 <?php

$slider_option = get_theme_mod('wp_store_homepage_setting_slider_option',0);
if ($slider_option == '1'):
    do_action('wp_store_slider_section'); // Slider section- this function is in wp-store-function.php
endif;
?>

您可以尝试
is_home()
is_front_page()
,这将确定它是否为主页

if ( is_home() || is_front_page() ) {
    $slider_option = get_theme_mod('wp_store_homepage_setting_slider_option',0);
     if ($slider_option == '1'):
     do_action('wp_store_slider_section'); // Slider section- this function is in wp-store-function.php
     endif;
} else {
    // Display what you want if not home
}
在这里查找:
是否在家


在此处查找:
is\u front\u page

//使用以下代码,is\u front\u page()在查看站点首页时返回true

 <?php if(is_front_page()) { 
        $slider_option = get_theme_mod('wp_store_homepage_setting_slider_option',0);
        if ($slider_option == '1'):
        do_action('wp_store_slider_section'); // Slider section- this function is in wp-store-function.php
        endif;
    } ?>

只创建(如果您没有)一个“主页”模板会简单得多,这是一个具有特定标题的相当简单的PHP页面,因此您可以在创建/编辑页面时选择该模板

然后在代码中添加希望滑块显示的部分,可以轻松绕过这些“is_home”或“is_frontpage”子句

例如:

<?php
/*
Template Name: NAME-OF-TEMPLATE
Author: NAME OF AUTHOR
Web Site: author url
Contact: author email
*/
get_header(); ?>
<!-- Get nav bar -->
<?php get_template_part( 'navigation', 'default' ); ?>
<!-- Start of page content -->
<div id="primary" class="site-content">
    <div id="content" role="main">
        <article id="post-0" class="post">
            <header class="entry-header">
<!-- Page Title/head if needed -->
            <!-- <h1 class="entry-title"><?php echo get_the_title(); ?></h1> -->
<!-- Your Code snippet -->
<?php
$slider_option = get_theme_mod('wp_store_homepage_setting_slider_option',0);
if ($slider_option == '1'):
    do_action('wp_store_slider_section'); // Slider section- this function is in wp-store-function.php
endif;
?>
            </header>
<!-- Main content -->
            <div class="entry-content">
<!-- Rest of your content and page structure -->
            </div><!-- .entry-content -->
        </article><!-- #post-0 -->
    </div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>

和WP参考:

我已经用css.home.myslide{display:block;}.myslide{display:none;}完成了这项工作