Archive for WordPress

Whiskey Air Dark New Index Template

4 February 2010

Like I promised in a previous post, here is the code required to show latest 5 posts followed by 15 more, like on my homepage. You need to edit the index.php template and add 2 sub-loops separated by wp_reset_query(). Simple as that. Here is the entire index.php code (you should be able to pull the entire loop from there):


<?php get_header();?>
<div id="content">

<br clear="all" /><br />
<?php if(have_posts()) : ?>
 <?php
 query_posts('posts_per_page=5&offset=0');
 while(have_posts()) : the_post();
 ?>
 <div id="post-<?php the_ID();?>" <?php post_class();?>>
 <h2><a href="<?php the_permalink();?>" rel="bookmark" title="Permanent link to <?php the_title();?>"><?php the_title();?></a></h2>
 <small><?php the_time('j F Y');?> by <?php the_author();?></small>
 <div>
 <div style="float:left; margin-right:8px"><?php echo get_the_image_link(array('Thumbnail','My Thumbnail'),'thumbnail');?></div>
 <?php the_excerpt('Read more &raquo;');?>
 </div>
 <div style="clear:both"></div>
 <p>Category: <?php the_category(', ');?> | <?php comments_popup_link('No comments &#187;', '1 comment &#187;', '% comments &#187;');?><br /><?php the_tags(); ?></p>
 </div>
 <?php endwhile;?>

 <?php wp_reset_query();?>

 <h2>More recent articles</h2>
 <br /><br />
 <?php
 query_posts('posts_per_page=15&offset=6');
 while (have_posts()) : the_post();
 ?>
 <div id="post-<?php the_ID();?>" <?php post_class();?>>
 <p>
 <strong><a href="<?php the_permalink();?>" rel="bookmark" title="Permanent link to <?php the_title();?>"><?php the_title();?></a></strong><br />
 <small><?php the_time('j F Y');?> by <?php the_author();?></small>
 </p>
 </div>
 <?php endwhile;?>

 <div>
 <div><?php next_posts_link(__('&laquo; Older Entries','whiskey'));?></div>
 <div><?php previous_posts_link(__('Newer Entries &raquo;','youdrunk'));?></div>
 </div>

 <?php else : ?>
 <h2>Not found</h2>
 <p>No results found.</p>
 <?php endif;?>
</div>
<?php get_sidebar();?>
<?php get_footer();?>

Download index.php here.

You may have noticed that I’m using an unsanitized function, get_the_image_link, to show a thumbnail next to each excerpt. I noticed it when copying the code. Still waiting for a new version of Whiskey Air?

WordPress 2.9 Has Finally Arrived

20 December 2009

During the weekend I updated no less than 15 WordPress blogs. The operation went as smooth as a baby’s butt, and hours later, plugin updates starting pouring in. Thanks to the mass updater feature, I was able to install them all at once.

If you’re a developer and you’re interested in what’s new when a plugin updates, check out Changelogger, a plugin which:

[...] shows the latest changelog right on the plugin listing page, whenever there’s a plugin ready to be updated.

The changelog on a plugin update is being shown if the plugin author added a changelog section based on the new readme.txt example file to their plugin.

If you need to optimize your database before updating, but you don’t have access to a phpMyAdmin interface, use Portable phpMyAdmin plugin.

I’m sure a maintenance release will follow in January, perhaps to improve the new features (I still don’t like the post thumb feature and I still use the Get the Image plugin), or to fix the omnipresent bugs. Don’t get me wrong, but new releases always bring new and fresh bugs.

Happy 2.9.

How To Style WordPress Categories Into 2 Columns

7 December 2009

categories

I was doing some research the other day to minimize the space occupied by my single-worded categories, and I found a nice way to do it.

Add the following to your CSS stylesheet:

.right {float:left; width:160px;}
.left {float:left; width:160px;}

Add the following to your sidebar, making sure you respect the widget styles:

<div class="widget_box">
<h3>Categories</h3>
<?php
$cats = explode('<br />', wp_list_categories('title_li=&echo=0&show_count=1&depth=1&style=none'));
$cat_n = count($cats) - 1;

for($i=0;$i<$cat_n;$i++):
	if($i<$cat_n/2):
		$cat_left = $cat_left.'<li>'.$cats[$i].'</li>';
	elseif($i>=$cat_n/2):
		$cat_right = $cat_right.'<li>'.$cats[$i].'</li>';
	endif;
endfor;
?>

<ul class="left">
	<?php echo $cat_left;?>
</ul>
<ul class="right">
	<?php echo $cat_right;?>
</ul>
</div>

That’s it! Test it and tell me how it works.

How To Extract Latest Posts From An External WordPress Blog

6 December 2009

RSS

First of all you need the Simplepie library. You only need the simplepie.inc file included in the archive.

My example extracts 5 items from a recipe blog:

<div class="block">
	<h2>Latest Culinary Recipes</h2>
	<div class="content">
		<?php $feed = new SimplePie('http://www.wordpress-site.com/feed');?>
		<ul>
			<?php foreach ($feed->get_items(0, 5) as $item): ?>
				<li>&raquo; <a href="<?php print $item->get_permalink();?>"><?php print substr(($item->get_title()),0,23);?> [...]</a></li>
			<?php endforeach; ?>
		</ul>
	</div>
</div>

I have also included a substr() function to show only the first 23 characters in the title. It fitted my web site better.

Don’t forget to have the simplepie library included at the top:

include('includes/simplepie.inc');

First WordPress Plugin: Portable phpMyAdmin

2 December 2009

portable-phpmyadmin

I just launched my first WordPress plugin. I needed an easy way to access the MySQL database without going to cPanel for each of my clients’ blogs. So I developed a wrapper for phpMyAdmin, and you can now access it straight from your WordPress Dashboard.

Read more and download Portable phpMyAdmin plugin here.

Stay tuned for more portable plugins!

Get Adobe Flash playerPlugin by wpburn.com wordpress themes