在使用自定义页面模板创建SPASH简介页面方面需要帮助

时间:2016-02-15 作者:Dee

我正在尝试使用wordpress主题中的自定义页面模板创建启动/介绍页面。我试着跟随tutplus。com指南,它工作完美。但我想要一些现代的网页设计,并提前一步,使用第三方网站设计工具并创建了示例页面,现在我正试图将其添加为自定义页面模板,但无法使其工作。缺少样式,仅显示文本。

我附加了使用设计工具创建的自定义页面文件,并将文件夹结构的图像与我的wordpress主题内容进行比较。

Folder Structure

我不专业,所以请详细解释我,这样我就可以自己做了。

回复@dingo\\u d函数中使用的代码。php

<?php
if (is_page_template(\'pageintro.php\')) {
    add_action( \'wp_enqueue_scripts\', \'splash_intro_scripts\');
}

if ( ! function_exists( \'splash_intro_scripts\' ) ){
    function splash_intro_scripts() {
        wp_enqueue_script( \'bootstrap\', get_stylesheet_directory_uri() . \'/javascript/bootstrap.js\', array( \'jquery\' ),\'\', true );
        wp_enqueue_script( \'jquerymin\', get_stylesheet_directory_uri() . \'/javascript/jquery-2.1.0.min.js\', array( \'jquery\' ),\'\', true );
        wp_enqueue_script( \'blocs\', get_stylesheet_directory_uri() . \'/javascript/blocs.js\', array( \'jquery\' ),\'\', true );
        wp_enqueue_style( \'bootstrap_css\', get_stylesheet_directory_uri() . \'/stylesheet/bootstrap.css\', array( ),\'\');
        wp_enqueue_style( \'fontawesome_css\', get_stylesheet_directory_uri() . \'/stylesheet/font-awesome.min.css\', array( ),\'\');
        wp_enqueue_style( \'stylesplash_css\', get_stylesheet_directory_uri() . \'/stylesheet/style-splash.css\', array( ),\'\');

    }
}
野狗,谢谢你帮助我。这些步骤和代码对我真的很有帮助。但它仍然不完美,还缺少一些东西。我不得不改变飞溅的风格。css和img文件夹的根目录,使其工作。虽然现在非常接近完美,但我认为有些脚本没有加载或主题问题。以下是网页截图,它是如何处理新更改的。

enter image description here

1 个回复
最合适的回答,由SO网友:dingo_d 整理而成

让我们从头开始。

首先,我将引导您了解风格和脚本的归属。在您的functions.php 文件添加:

add_action( \'wp_enqueue_scripts\', \'splash_intro_scripts\');

if ( ! function_exists( \'splash_intro_scripts\' ) ){
    function splash_intro_scripts() {
        if (is_page_template(\'page-intro.php\')) {
            wp_enqueue_style(\'google_font_1\', \'https://fonts.googleapis.com/css?family=Arvo&subset=latin,latin-ext\');
            wp_enqueue_style(\'google_font_2\', \'https://fonts.googleapis.com/css?family=Josefin+Sans&subset=latin,latin-ext\');
            wp_enqueue_style(\'google_font_3\', \'https://fonts.googleapis.com/css?family=Josefin+Slab&subset=latin,latin-ext\');

            wp_enqueue_script( \'bootstrap\',  get_stylesheet_directory_uri().\'/js/bootstrap.js\', array( \'jquery\' ),\'\', false );
            wp_enqueue_script( \'blocs\',  get_stylesheet_directory_uri().\'/js/blocs.js\', array( \'jquery\' ),\'\', false );

            wp_enqueue_style( \'bootstrap_css\', get_stylesheet_directory_uri() . \'/css/bootstrap.css\', array( ),\'\');
            wp_enqueue_style( \'fontawesome_css\', get_stylesheet_directory_uri() . \'/css/font-awesome.min.css\', array( ),\'\');
            wp_enqueue_style( \'stylesplash_css\', get_stylesheet_directory_uri() . \'/css/style-splash.css\', array( ),\'\');
        }
    }
}
或者,也可以找到add_action( \'wp_enqueue_scripts\',...); 位于functions.php 文件,并添加if 此处的声明。

现在,字体是通过google加载的,所以您只需在wp_enqueue_style.

你会注意到我的目录和你的有点不同。你有/javascript/ 我有/js/; 你有/stylesheet/ 我有/css/. 只需更改它以适合您的主题(文件结构)。然后放置除jquery, 因为它是由wordpress加载的,不需要将自己的文件排队。这就是为什么我添加了bootstraparray(\'jquery\').

您还需要将fontawesome字体文件夹放在主题根文件夹中。

还有/img 文件夹必须转到/stylesheet 文件夹,因为您的style-splash.css 在里面/stylesheet 文件夹(因此它正在查看该文件夹中的图像)。

blocks.js 需要修改才能工作。

你需要把所有东西都包起来

jQuery(function($){ });
因此:

jQuery(function($){

    // Loading page complete
    $(window).load(function()
    {
        checkHero(); // Check hero height is correct
        animateWhenVisible();  // Activate animation when visible
    });

 ... all the way down ...

    $(document).on(\'click\', \'.next-lightbox, .prev-lightbox\', function(e)
        {
            e.preventDefault();
            var idx = $(\'a[data-lightbox]\').index(targetLightbox);
            var next = $(\'a[data-lightbox]\').eq(idx+1) // Next

            if($(this).hasClass(\'prev-lightbox\'))
            {
                next = $(\'a[data-lightbox]\').eq(idx-1) // Prev
            }
            $(\'#lightbox-image\').attr(\'src\',next.attr(\'data-lightbox\'));
            $(\'.lightbox-caption\').html(next.attr(\'data-caption\'));
            targetLightbox = next;

            // Handle navigation buttons (next - prev)
            $(\'.next-lightbox, .prev-lightbox\').hide();

            if($(\'a[data-lightbox]\').index(next) != $(\'a[data-lightbox]\').length-1)
            {
                $(\'.next-lightbox\').show();
            }
            if($(\'a[data-lightbox]\').index(next) > 0)
            {
                $(\'.prev-lightbox\').show();
            }
        });
    }

});
否则您将出现错误。以及page-intro.php

模板文件只是:

<?php

/*
Template Name: Splash Intro
*/

get_header();

?>

<div class="page-container">

<!-- Hero Bloc -->
<div id="hero-bloc" class="bloc hero bgc-white bg-walkway d-bloc">
    <div class="container bloc-sm hero-nav">
        <nav class="navbar row">
            <div class="navbar-header">
                <a class="navbar-brand" href="index.html">Company</a>
                <button id="nav-toggle" type="button" class="ui-navbar-toggle navbar-toggle" data-toggle="collapse" data-target=".navbar-1">
                    <span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
                </button>
            </div>
            <div class="collapse navbar-collapse navbar-1">
                <ul class="site-navigation nav navbar-nav pull-right">
                    <li>
                        <a id="pl-undefined" href="#">Home</a>
                    </li>
                </ul>
            </div>
        </nav>
    </div>
    <div class="v-center">
        <div class="vc-content row">
            <div class="col-sm-12">
                <div class="row">
                    <div class="col-sm-12 col-md-6 col-md-offset-3">
                        <div class="embed-responsive embed-responsive-4by3">
                            <iframe src="https://player.vimeo.com/video/106743683" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
                        </div>
                    </div>
                </div>
                <h1 class=" mg-lg text-center">
                    It\'s all about the big hero strapline.
                </h1>
            </div>
        </div><a id="scroll-hero" class="btn-dwn" href="#"><span class="fa fa-chevron-down"></span></a>
    </div>
</div>
<!-- Hero Bloc END -->

<!-- Bloc Group -->
<div class=\'bloc-group\'>

<!-- bloc-2 -->
<div class="bloc bgc-white bloc-tile-2 bg-citysky d-bloc" id="bloc-2">
    <div class="container bloc-lg">
        <div class="row">
            <div class="col-sm-12">
                <h3 class="mg-md text-justify ">
                    <strong>BENEFITS</strong>
                </h3>
                <p class="text-justify ">
                    Cras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus, tellus ac cursus commodo.Cras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus, tellus ac cursus commodo.Cras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus, tellus ac cursus commodo.Cras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus, tellus ac cursus commodo.Cras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus, tellus ac cursus commodo.Cras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus, tellus ac cursus commodo.Cras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus, tellus ac cursus commodo.Cras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus, tellus ac cursus commodo.Cras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus, tellus ac cursus commodo.
                </p>
            </div>
        </div>
    </div>
</div>
<!-- bloc-2 END -->

<!-- bloc-3 -->
<div class="bloc bgc-white bloc-tile-2 bg-citysky d-bloc" id="bloc-3">
    <div class="container bloc-lg">
        <div class="row">
            <div class="col-sm-12">
                <h3 class="mg-md ">
                    <strong>COLLABORATION</strong>
                </h3>
                <p class=" text-justify">
                    Cras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus, tellus ac cursus commodo.Cras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus, tellus ac cursus commodo.Cras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus, tellus ac cursus commodo.Cras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus, tellus ac cursus commodo.Cras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus, tellus ac cursus commodo.Cras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus, tellus ac cursus commodo.Cras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus, tellus ac cursus commodo.Cras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus, tellus ac cursus commodo.Cras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus, tellus ac cursus commodo.Cras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus, tellus ac cursus commodo.
                </p>
            </div>
        </div>
    </div>
</div>
<!-- bloc-3 END -->
</div>
<!-- Bloc Group END -->

<!-- Footer - bloc-4 -->
<div class="bloc bgc-white bg-walkway d-bloc" id="bloc-4">
    <div class="container bloc-lg">
        <div class="row">
            <div class="col-xs-12 col-md-8 col-md-offset-2">
                <div class="col-sm-3 text-center">
                    <a class="social-lg" href="#" target="_blank"><span class="fa fa-twitter icon-lg"></span></a>
                </div>
                <div class="col-sm-3 text-center">
                    <a class="social-lg" href="#" target="_blank"><span class="fa fa-facebook icon-lg"></span></a>
                </div>
                <div class="col-sm-3 text-center">
                    <a class="social-lg" href="#" target="_blank"><span class="fa fa-dribbble icon-lg"></span></a>
                </div>
                <div class="col-sm-3 text-center">
                    <a class="social-lg" href="#" target="_blank"><span class="fa fa-instagram icon-lg"></span></a>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- Footer - bloc-4 END -->
</div>
<!-- Main container END -->

<?php get_footer();
基本上所有的html都只是粘贴在里面。就这样。

如果你不想让页眉或页脚显示出来,你必须对其进行一些修改。通过更改header.phpfooter.php 或者用css隐藏它们。

就是这样。我已经把我在2016年考试主题中描述的所有东西都放好了,效果很好。

enter image description here

相关推荐