简体   繁体   English

如何创建自定义wordpress幻灯片插件?

[英]How do I create a custom wordpress slideshow plugin?

How do I create a custom wordpress slideshow plugin? 如何创建自定义wordpress幻灯片插件? I've been looking for the tutorials on google but I couldn't find one, would you guys mind giving a tutorial here or link to some other custom slideshow plugin tutorials? 我一直在寻找谷歌的教程,但我找不到一个,你们介意在这里给一个教程或链接到一些其他自定义幻灯片插件教程?

If you don't mind using a jQuery plugin, rather than write it from scratch, might I suggest .cycle() . 如果您不介意使用jQuery插件,而不是从头开始编写,我可以建议使用.cycle()

I'm going to assume you are not familiar with the WP loop either. 我假设你不熟悉WP循环。 If you're not you really should check out the WP Codex ( here ). 如果你不是,你真的应该看看WP Codex( 这里 )。

PHP - (put this in functions.php) PHP - (把它放在functions.php中)

<?php add_action('wp_enqueue_scripts', 'my_scripts_method'); ?>
<?php function my_scripts_method() {
    wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js');
    wp_enqueue_script( 'jquery' );
    wp_deregister_script( 'jqueryui' );
    wp_register_script( 'jqueryui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js');
    wp_enqueue_script( 'jqueryui' );
    wp_register_script( 'slideshow', get_bloginfo('stylesheet_directory').'js/slideshow.js');
    wp_enqueue_script( 'jqueryui' );
} ?>

<?php add_action('hook_name', 'my_slideshow'); ?>
<?php function my_slideshow() { ?>
    <?php if(is_page('page_name')) : ?>
    <div id="SlideShow">
    <?php $my_query = new WP_Query('category_name=my-slideshow$post_per_page=5'); ?>
    <?php if ($my_query->have_posts()) : ?>
        <?php while ($my_query->have_posts()) : ?>
        <div id="slide">
            <div class="wrapper">
                         <?php if (has_post_thumbnail()) : ?>
                              <?php the_post_thumbnail() ?>
                         <?php else : ?>
                              <?php echo (get_bloginfo('stylesheet_directory').'/images/default.png'); ?>
                         <?php endif; ?>
            </div><!-- end .wrapper -->
        </div><!-- end #slide -->
        <?php endwhile; ?>
    <?php else : ?>
        <span>Sorry, there is no content at this time.</span>
    <?php endif; ?>
    <?php wp_reset_postdata(); ?>
    </div><!-- end #slideshow -->
    <?php endif; ?>
<?php } ?>

replace 'hook_name' with the hook where you want to plug in the slideshow. 将“hook_name”替换为要插入幻灯片的挂钩。 replace 'page_name' with the slug of the page where you want the slideshow to appear. 将'page_name'替换为您希望幻灯片显示的页面的slug。 If you want it to show up on all pages, remove the <?php if(is_page('page_name')) : ?> and the <?php endif; ?> 如果您希望它显示在所有页面上,请删除<?php if(is_page('page_name')) : ?><?php endif; ?> <?php endif; ?> at the end. <?php endif; ?>最后。 replace 'my-slideshow' in $my_query to the name of the category that you want in the slideshow. $my_query中的“my-slideshow”替换为幻灯片中所需类别的名称。 You can change '5' to any number of slides you want to show in the slideshow. 您可以将“5”更改为要在幻灯片中显示的任意数量的幻灯片。 the_post_thumbnail is the featured image of the post. the_post_thumbnail是帖子的精选图片。 It is checking if the post has a featured image, if not, it relys on default.png found in the theme's images folder. 它正在检查帖子是否有特色图像,如果没有,它依赖于主题图像文件夹中的default.png。

jQuery - (put this in its own file in the theme dir in a /js dir. Call the file slideshow.js) jQuery - (将它放在/ js目录中主题目录中的自己的文件中。调用文件slideshow.js)

var $j = jQuery.noConflict();

$j(document).ready(function() {
    $j('#slideshow').cycle({
        // options here.
    });
});

There are many options you can define found here . 您可以在此处找到许多选项。

This pretty much sums up the custom slideshow. 这几乎总结了自定义幻灯片。 If you want to package it up as a modularized plugin you will want to reference the Codex here . 如果您想将其打包为模块化插件,您可以在此处参考Codex。

我想如果你有wordpress知识,那么只需从你的模板文件夹中修改header.php文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM