Archive for the ‘Code Snippets’ Category
Monday, October 29th, 2007
<?php$postlist = get_posts('category=6&numberposts=5');
foreach ($postlist as $post) :?><li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li><?php endforeach; ?>
Use this in the sidebar to display a defined number of posts from a specified category. Where it says “category=6″ replace the 6 with the relevant category ID number, and where it says “numberposts=5″ replace the 5 with the number of posts that you want to appear.
Update Nov. 7, 2007:
The above code snippet can also be used to display a page in the sidebar. This is is handy if you want to create an editable chunk of text in the sidebar without using widgets. So, for example, if you want to show an excerpt of your About page in your sidebar, use the following code:
<?php$postlist = get_posts('id=54');
foreach ($postlist as $post) :?><?php the_excerpt(); ?>
<a href="<?php the_permalink(); ?>">read more</a>
Where it says id=54, replace 54 with the id number of the page you want to display.
Posted in Code Snippets | 14 Comments »
Wednesday, February 21st, 2007
To show a different sidebar on different pages, replace the standard call for the sidebar:
<?php get_sidebar(); ?>
with the following code:
<?php include ('sidebar2.php'); ?>
The same can be done to call different headers, i.e. instead of <?php get_header(); ?> use <?php include ('header2.php'); ?>For more information, see Different Sidebars Anyone? on the WordPress codex.
Posted in Code Snippets, Tips | 1 Comment »