Sivel.net  Throwing Hot Coals


Shadowbox JS WordPress Plugin v2.0.3 Released

The Shadowbox JS WordPress Plugin has been updated to version 2.0.3. Don’t be fooled by the version number. This is a big update. New to this update, by popular request, is an admin interface among other updates. See the Change Log for all changes. Enjoy!

Asides CoolStuff News Plugins WordPress

Moderate Select Posts Updated to 1.2

The Moderate Selected Posts WordPress plugin has been updated to version 1.2. New to this version are 2.7 enhancements, admin styling enhancements and localization support. Enjoy!

Asides News Plugins WordPress

Separating Pings from Comments in WordPress 2.7

WordPress 2.7 has introduced many new features surrounding comments. Of these is AJAX commenting and threaded comments. To take advantage of the later, you must use a function wp_list_comments instead of the old way of looping through the comments array with a foreach. Weblog Tools Collection has a good how to on the old way that can be found here.

I wanted to get this hashed out before 2.7 goes live so that theme designers and anyone else can implement this in time for the release.

I’ll be referencing the default theme from 2.7 in this how to. If you are interested in adding the new commenting features to your current pre 2.7 theme see this how to by Otto.

wp_list_comments is not documented yet on the WordPress codex. But some feature that are worth mentioning are the ability to specify the comment type to display and a callback so that you can decide how to structure the output.

Let us start by taking a look at the new comments “loop”:

<?php if ( have_comments() ) : ?>
    <h3 id="comments">

<?php comments_number('No Responses', 'One Response', '% Responses' );?> to &#8220;

<?php the_title(); ?>&#8221;</h3>

    <ol class="commentlist">


<?php wp_list_comments(); ?>
    </ol>
    <div class="navigation">
        <div class="alignleft">

<?php previous_comments_link() ?></div>
        <div class="alignright">

<?php next_comments_link() ?></div>
    </div>


<?php else : // this is displayed if there are no comments so far ?>



<?php if ('open' == $post->comment_status) : ?>


<!-- If comments are open, but there are no comments. -->



<?php else : // comments are closed ?>


<!-- If comments are closed. -->
        <p class="nocomments">Comments are closed.</p>



<?php endif; ?>


<?php endif; ?>

As you can see it is much simpler than the old comments “loop”. The majority of everything that is happening is now done via the function wp_list_comments.

To remove pings (pingbacks and trackbacks) we only need to make a few small changes. First open up your themes single.php:

Find the following code:

<?php comments_template(); ?>

And change it to:

<?php comments_template('', true); ?>

The above change tells comments_template to create a global array $comments_by_type that we will use later on.

First open up comments.php.

Look for the following code:

<?php if ( have_comments() ) : ?>

Directly below this add:

<?php if ( ! empty($comments_by_type['comment']) ) : ?>

Change this:

<?php wp_list_comments(); ?>

To this:

<?php wp_list_comments('type=comment'); ?>

Directly below the wp_list_comments function we modified is:

</ol>

Directly below this add:

<?php endif; ?>

The if statement prevents the comments heading and ol tags from displaying if you only have trackbacks and pingbacks on this post.

Much easier so far, right?

To display the pings we need to insert the following code beneath the endif we just added:

<?php if ( ! empty($comments_by_type['pings']) ) : ?>
<h3 id="pings">Trackbacks/Pingbacks</h3>

<ol class="commentlist">


<?php wp_list_comments('type=pings'); ?>
</ol>


<?php endif; ?>

The comments “loop” should now look like this:

<?php if ( have_comments() ) : ?>


<?php if ( ! empty($comments_by_type['comment']) ) : ?>
    <h3 id="comments">

<?php comments_number('No Responses', 'One Response', '% Responses' );?> to &#8220;

<?php the_title(); ?>&#8221;</h3>

    <ol class="commentlist">


<?php wp_list_comments('type=comment'); ?>
    </ol>


<?php endif; ?>



<?php if ( ! empty($comments_by_type['pings']) ) : ?>
    <h3 id="pings">Trackbacks/Pingbacks</h3>

    <ol class="commentlist">


<?php wp_list_comments('type=pings'); ?>
    </ol>


<?php endif; ?>

    <div class="navigation">
        <div class="alignleft">

<?php previous_comments_link() ?></div>
        <div class="alignright">

<?php next_comments_link() ?></div>
    </div>


<?php else : // this is displayed if there are no comments so far ?>



<?php if ('open' == $post->comment_status) : ?>


<!-- If comments are open, but there are no comments. -->



<?php else : // comments are closed ?>


<!-- If comments are closed. -->
        <p class="nocomments">Comments are closed.</p>



<?php endif; ?>


<?php endif; ?>

Now the pings are displayed below the comments. The above code will show the pings in full comment boxes. I personally like a simple ordered list with a link and title of the ping. To achieve this without a foreach (Thanks Ryan Boren for the tip!)

Open your themes functions.php file and create a callback function for wp_list_comments. The following code should be inserted:

<?php

function list_pings($comment, $args, $depth) { $GLOBALS[‘comment’] = $comment; ?> <li id=“comment-

<?php comment_ID(); ?>">

<?php comment_author_link(); ?>


<?php } ?>

Replace this:

<ol class="commentlist">
<?php wp_list_comments('type=pings'); ?>

With this:

<ol class="pinglist">
<?php wp_list_comments('type=pings&callback=list_pings'); ?>

If your theme doesn’t have a functions.php just create it and include the above code.

In this case our full comment “loop” should now look like:

<?php if ( have_comments() ) : ?>


<?php if ( ! empty($comments_by_type['comment']) ) : ?>
    <h3 id="comments">

<?php comments_number('No Responses', 'One Response', '% Responses' );?> to &#8220;

<?php the_title(); ?>&#8221;</h3>

    <ol class="commentlist">


<?php wp_list_comments('type=comment'); ?>
    </ol>


<?php endif; ?>



<?php if ( ! empty($comments_by_type['pings']) ) : ?>
    <h3 id="pings">Trackbacks/Pingbacks</h3>

    <ol class="pinglist">


<?php wp_list_comments('type=pings&callback=list_pings'); ?>
    </ol>


<?php endif; ?>

    <div class="navigation">
        <div class="alignleft">

<?php previous_comments_link() ?></div>
        <div class="alignright">

<?php next_comments_link() ?></div>
    </div>


<?php else : // this is displayed if there are no comments so far ?>



<?php if ('open' == $post->comment_status) : ?>


<!-- If comments are open, but there are no comments. -->



<?php else : // comments are closed ?>


<!-- If comments are closed. -->
        <p class="nocomments">Comments are closed.</p>



<?php endif; ?>


<?php endif; ?>

One last (optional) task is to modify the comment counts to only reflect the number of comments minus pings.

Open your themes functions.php and add the following code:

<?php
add_filter('get_comments_number', 'comment_count', 0);
function comment_count( $count ) {
    if ( ! is_admin() ) {
        global $id;
        $comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));
        return count($comments_by_type['comment']);
    } else {
        return $count;
    }
}
?>

Again if your theme doesn’t have a functions.php just create it and include the above code.

There you have it. If you have any questions let me know.

HowTo PHP Plugins WordPress

Changes Coming for Shadowbox JS

With the last release of Shadowbox JS I added the functionality to add Shadowbox to all image links automatically.

With the next release the following features will be added:

  • Admin settings page for configuration.
  • Advanced configuration options to tweak most Shadowbox initialization options.
  • Automatically add Shadowbox to movie links.
  • Automatically add Shadowbox to audio links.
  • Automatically add Shadowbox to YouTube and Google Video links.
  • WordPress 2.7 uninstall compatibility.
  • Enqueue JavaScript and CSS files
  • Move Initialization JavaScript to the footer

The admin page is something I have been debating for a while. And with the list of configuration options growing, I figured it best to give users an easier way to configure the plugin, rather than having to edit the variables in the source. The admin page will match the styling of the other pages by using the WordPress admin CSS which isn’t something many plugins do.

As for the additional automation, I had already written the code to add the rel attribute to image links so figured why not re-use it and give users an easy way to show all of their media using Shadowbox.

Anyway…I have some testing to do. Hopefully should be releasing within the next several weeks.

Anyone wishing to test out the development version can download it from the WordPress Plugins Repository.

CoolStuff News Plugins WordPress

Gallery Shortcode Style to Head WordPress Plugin v1.1 Released

The Gallery Shortcode Style to Head WordPress Plugin has been updated to version 1.1. New to this update is the addition of the gallery_style filter so that the default gallery styles can be overridden. See the Change Log for all changes. Enjoy!

Asides Plugins WordPress

Shadowbox JS WordPress Plugin v2.0.2 Released

The Shadowbox JS WordPress Plugin has been updated to version 2.0.2. New to this update is the automatic addition of the rel attribute to image links, including those generated by the [ gallery] shortcode. See the Change Log for all changes. Enjoy! UPDATE: I found a typo in a variable name that was causing issues. The plugin has now been updated to 2.0.2.1.

Asides Plugins WordPress

Page Restrict and Moderate Select Posts Plugins Updated

The Page Restrict and Moderate Selected Posts WordPress plugins have been updated. See their respective change logs for, what other than, changes. Page Restrict Change Log - Moderate Select Posts Change Log.

Asides Plugins WordPress

Page Restrict WordPress Plugin Updated to v1.4.1

I am releasing a minor update to the Page Restrict plugin. Version 1.4.1 resolves a duplicate add_action and restores a missing add_action that occurred in the admin functionality separation.

Asides Plugins WordPress

August 25 Plugin Updates

Today I am releasing updated versions of my Page Restrict, Lightview JS and Shadowbox JS WordPress plugins.

New to the Page Restrict plugin is moving the content required for the admin pages into another file and including it only when in the admin portion of your site so that it isn’t even loaded into memory during normal site views.

New to the Lightview JS plugin is support for the [ gallery] shortcode.

New to the Shadowbox JS plugin is support for the [ gallery] shortcode.

Enjoy!

Asides Plugins WordPress

Shadowbox and Lightview Plugins Question

I have a question for all of the users out there who are using the Shadowbox JS and Lightview JS WordPress plugins.

Would you prefer the plugin to automatically add the activator attributes to the links for Shadowbox and Lightview respectively, rather than having to manually add it to your links?

I am one of those people who believe that more flexibility is a better feature than ease of use by less typing.

With that being said I could see a situation where one would simply want to use Shadowbox or Lightview for all of their image links and where adding the activator attributes to the links would become tiresome.

Perhaps a good compromise would be to add functionality to either enable or disable global activation on image links? Perhaps making global activation the default would be beneficial?

I think I have already talked myself into adding this functionality but I would still like to hear some user feedback, so tell me what you think.

Plugins Questions WordPress