Performancing Metrics

Posts Tagged ‘tutorial’

Display Upcoming Entries In Your Post With A WordPress Shortcode

Since some days several contacts have been considering the option to display upcoming posts on their site. WordPress offers a really simple solution for this in the form of the attribute post_status. The post_status is stored in the wp_post table and has generally the attributes: draft, private, publish or static for pages. There is one more attribute which we will use in this example: future.

It is now simple to create a list of the 5 upcoming entries and display this in your theme, fe. in your sidebar.

<?php
$my_query = new WP_Query('post_status=future&showposts=5');
?>
<div class="sidebar-box">
    <?php
    if ($my_query->have_posts()) : while ($my_query->have_posts()) :
        $my_query->the_post();
        ?>
        <ul>
          <li>
           <?php the_title(); ?>
          </li>
        </ul>
    <?php endwhile; else: ?>
        <div>
        <ul>
          <li><?php _e('No upcoming Posts'); ?></li>
        </ul>
        </div>
    <?php endif; ?>
</div>

You can now easily style this in your CSS.

Use A Shortcode To Display Upcoming Entries In A Post

First, what are shortcodes? I wrote a small intro to shortcodes on Devlounge yesterday with some examples of how to build a shortcode.

Why would you want to display a list of upcoming posts within an entry? You could be writing a series and want to use your upcoming entries as an additional teaser in the hope that the reader will subscribe or return to your site. You could use a post template for this but it is very simple to create a shortcode. Once you have created this shortcode it is then very simple to add the list of upcoming posts anywhere in an entry.

Building the shortcode

For this example we are going to build a shortcode [upcoming] and will use the tag series as selector. Doing this, it will avoid that scheduled entries not tagged Series will not be displayed. This can be handy on multi-authored blogs with a regular, scheduled posting rhythm.

Add the following code to your functions.php.

function upcom($atts, $content = null) {
       extract(shortcode_atts(array(
               "num" => '5'
               "tag" => 'series'
       ), $atts));
       global $post;
       $myposts = get_posts('numberposts='.$num.'&post_status=future&order=DESC&orderby=date&tag='.$tag);
       $retour='<ul class="upcoming">';
       foreach($myposts as $post) :
               setup_postdata($post);
            $retour.='<li><a href="'.get_permalink().'">'.the_title("","",false).'</a></li>';
       endforeach;
       $retour.='</ul> ';
       return $retour;
}
add_shortcode('upcoming', 'upcom');

All you have to do now to display this list in an entry is use the shortcode [upcoming] in the editor.

In this example I used <ul class="upcoming"> to easily style the output in your CSS.

Modifying The Shortcode Function

The shortcode function above can easily be modified.

- The example returns 5 posts, change the value in line 3 to display more or less entries
- Change the tag you want to use in the same way as you would change the number of displayed entries (line 4).

Categories: WordPress Tips, WordPress Tutorials
Tags: , , ,

Freelancing with WordPress – WPCandy

The past few days, WPCandy.com has been running some great articles about using WordPress for freelancing. From dealing with project management, to managing contacts, to setting up a portfolio, and (as of today) even invoicing.

If you’re doing much in the way of freelance blogging, or just want some ideas of how you might better organize your own projects using WordPress as a management tool, I highly suggest checking them out.

They each focus on a very specific set of needs and how WordPress might fill those needs (and at times suggests better options), so it’s pretty easy to mix and match a solution that could work for just about anyone.

Here’s a tidbit from the “project management” article to get things rolling…

After checking out all these options Iʼve found the “WordPress-as-Project-Management-System” experience to be extremely lacking. The options are either simple enough that they could be replaced with Google Docs or a simple notebook or so complex that trying to use them is nearly impossible. There simply is no killer project management plugin for WordPress… yet.

I think it is worth noting that the best replacement Iʼve found for Basecamp is an open source project called Project Pier which does almost everything Basecamp does. Itʼs even themeable and they have some pretty slick options. If you want a self-hosted project management solution, Project Pier is definitely the way to go.

Check out WPCandy.com for the original articles, and a pile of other fun stuff.

Categories: WordPress Tips, WordPress Tools, WordPress Tutorials
Tags: , , , , ,