WP Greet Box autohide featureВсякий раз, коли ви досягнете цього сайту за допомогою пошукових систем або популярних соціальних закладок або веб-сайт, дружнє вітання буде радий вітати Вас і, можливо, запропонувати кілька інших статей на основі пошуку ключових слів. Це ввічливості РГ Вітайте Box плагін для WordPress, розроблені Thaya Kareeson.

Інтерфейс адміністрування для цього плагіна є достатньо інтуїтивним, і це дасть адміністратору кілька варіантів, коли і як часто показувати повідомлення. Наприклад, Ви можете налаштувати його, щоб показати привітання прибувають з Google і максимальну кількість часу тільки.

Якщо включено, відвідувач сайту може також закрити вікно привітання вручну, і тим самим може змінити максимальну кількість часу, встановленого в адміністрації.

На жаль, привітання буде залишатися на своєму місці безліч тих пір, поки сторінка видно або поки користувач не закриє його вручну. Щоб уникнути того, щоб відвідувачі вручну закривати те, що вони не хочуть бачити, Я впровадив функцію автоматичного приховування.

What it does

This additional feature works seamlessly with the plug-in. Once the greeting has been shown, it will wait a few seconds before it starts to fade away. If the visitor does not take any action, the greeting will eventually disappear altogether and the space it used will be reclaimed by sliding the rest of the website in its place. If before or during fading the visitor moves the mouse over the area, any fading will be returned to normal and the user can click any of the links the greeting might be showing.

It’s not unlike some of the message balloons we have become accustomed to from Windows Vista or Ubuntuif you’re not interested, it’ll the message balloon will fade away without your interaction.

How to implement it

It involves a few rather small changes to your website. To begin with, the WP Greet Box plug-in should be set to NOT automatically display a greeting (Uncheck  both Automatically show greeting message on posts / Сторінки”).

PHP Portion

Now you need to edit the WordPress theme’s file template(З) where you would like to display the greeting. For example with this website, I am using the theme’s header.php файл. It involves inserting a tiny bit of PHP code as following:

<div style="clear:both"><?php if(function_exists('wp_greet_box')){wp_greet_box();} ?></div>

At your discretion, you may or may not wish to enclose it within these <div></div> statements and it will depend on where you locate the code as well as your template.

CSS Portion

You can continue to use the CSS stylesheet included with the plug-in (or your own if you have implemented one). Однак, there’s one entry that you will need to include specific for Microsoft Internet Explorer:

#greet_block {
*background:#fff;
}

It does not particularly have to be this color (so it can match the rest of your theme), but the importance is that a background color is included.  If this isn’t there, Internet Explorer will do some strange things to the greeting while it is fading. It’s a known issue.

You may place this in your own stylesheet or use use the theme’s stylesheet, generally named style.css.

JavaScript portion

Most of the legwork is done by JavaScript and it requires that jQuery is loaded with your theme. Many popular themes already include this, but if yours does not, simply add the following line (before the wp_head(); statement):

<?php wp_enqueue_script('jquery'); ?>

Next you can either create a new JavaScript file or use an existing one that will be loaded with your theme, and include the following code:

jQuery(document).ready(function( $ ){
    /* Greetbox Autohide */
    var _greeting_box_vars = {
        init_timeout: 15000,
        timeout: 3000,
        block: '#greet_block',
        _timer: 0
    };

    jQuery.fn.fadeThenSlide = function() {
        return this.fadeTo(4500, 0).slideUp(500);
    };

    if (!$(_greeting_box_vars.block).css("display") !== "none") {
        _greeting_box_vars._timer = setTimeout("jQuery(function($){$('"+_greeting_box_vars.block+"').fadeThenSlide()});", _greeting_box_vars.init_timeout);
    }

    $(_greeting_box_vars.block).hover(
        function () {
            if ($(this).css("opacity") !== "0") {
                // It's not sliding yet, so give the user a chance to extend his period.
                clearTimeout(_greeting_box_vars._timer);
                $(_greeting_box_vars.block).stop().stop().fadeTo(300,1);
            }
        },
        function () {
            _greeting_box_vars._timer = setTimeout("jQuery(function($){$('"+_greeting_box_vars.block+"').fadeThenSlide()});", _greeting_box_vars.timeout);
        }
    );
});

This code has not been highly optimized so it will be easier for you to understand what is happening and make any modifications if you wish. If you are uncomfortable with JavaScript in general, then the portion immediately following the Greetbox Autohide comment will be of interest to you. конкретно:

var _greeting_box_vars = {
 init_timeout: 15000,
 timeout: 3000,
 block: '#greet_block',
 _timer: 0
 };

The init_timeout variable specifies how long the greeting will be visible before it starts fading and the visitor has not move his mouse over it. У наведеному вище прикладі, this is 15 seconds (15000 milliseconds). The timeout value that follows you can specify how long the greeting will remain visible after the mouse has been over it. In the above example this is 3 seconds.

The block variable specified the ID of the <div></div> section that contains the actual greeting. За замовчуванням, the WP Greet Box uses the provided name (#greet_block) but this may be different if you have made any modifications to the default settings.

The _timer should not be changed and is internally used to keep track of the timeout timer.

A function in the script, jQuery.fn.fadeThenSlide, simply fades the greeting and if it is no longer visible will slide it out of the way. Anything that follows below the greeting will then be gradually moved in its place so you are not left with a large blank area.

If you are implementing this script in a separate file, make sure the script will be called with the theme’s template. Наприклад,, add to the header.php файл:

<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/my-greetbox-autohider.js"></script>

After this has all been implemented, you may wish to enable the default greeting if it was disabled before. Then visit your website to check if everything is working as expected and in the proper location. If you run into any issues, feel free to post a comment or contact me directly.

Відповідні посади:

  1. Fancy WordPress переклади
  2. РГ Flickr фону в альфа-тестування
  3. Додати Hashtags підтримки WordTwit
  4. Швидше WP Super Кеш з Nginx
  5. Myatu є мобільним