Displaying Recent Posts in Wordpress Without Widgets

As you may know, older versions of Wordpress do not support the use of widgets. So if you needed to design a theme for someone with an older version of Wordpress this method would be perfect. For me, I needed to place the recent posts in a place where it just wouldn’t make sense to use widgets because the only widget I would need was the recent post widget. It would also take a lot of extra effort.

I figured there had to be an easier way to display the recent posts. I looked through Wordpress’ website and searched Google, but I came up empty handed. So I took it upon myself to write the code for this apparently easy task.

<ul>
<?php
global $post;
$posts = get_posts(’numberposts=5&offset=0′);
foreach($posts as $post) :
setup_postdata($post);
?>
<li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li>
<?php endforeach; ?></ul>

Feel free to use this if you want.
-Greg

EDIT: I have been alerted that there is a VERY similar code. I’m sorry if you have something similar, but this is 100% original.


Read More...

Position:fixed Fix for IE6 (without javascript)

Here is the code:

#theDiv
{
position:absolute;
left: 25px;
top: 25px;
}
body > #theDiv
{
position:fixed;
}

Please let me know what you think of this fix, thanks ;).


Read More...

Printing all elements in an array

In php it may sometimes be important to print all of the elements contained inside of an array. In most instances you need to print them out forwards, starting with the element stored in the first array key, but sometimes you may need to print out the contents backwards. This process can be tricky and hard to understand for a lot of people so I tried to simplify it by making a function that will print out all the elements for you. Here it is:

function printAllArray($name,$action){
if($action == “foreward” || $action == NULL || $action == “”){
$amountIn = count($name);
for($x = 0; $x <= $amountIn;$x++){
print($name[$x]);
}
}
if($action == “backward”){
$amountIn = count($name);
for($x = $amountIn; $x >= 0;$x–){
print($name[$x]);
}
}
}


Read More...