如何在标题中显示Wordpress滑块代码仅在主页中显示

时间:2017-07-21 03:25:54

标签: php jquery wordpress slider nivo-slider

嗨我是wordpress自定义中的新蜜蜂,这里是滑块代码,我想将此代码插入到标题中并仅显示在主页上请healp me

 <?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;
?>

3 个答案:

答案 0 :(得分:0)

您可以尝试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
}

在此处查看referenceis_home
在这里查看referenceis_front_page

答案 1 :(得分:0)

//使用以下代码,is_front_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;
    } ?>

答案 2 :(得分:0)

创建(如果你没有)一个“HOME”页面模板会简单得多,这是一个带有特定HEADING的相当简单的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(); ?>

请参阅这个简单的教程,以帮助您熟悉自己:https://www.cloudways.com/blog/creating-custom-page-template-in-wordpress/

WP指出: https://developer.wordpress.org/themes/template-files-section/page-template-files/#creating-page-templates-for-specific-post-types