Welcome to SameCat

A basic, easy system for listing posts of the same category.

 

PLEASE Help CHAITGEAR

If you find this code useful, please give us a link back from your site.
Go to the About CHAITGEAR pages, grab one of the cool link graphics and
sample title/alt text, and link to us!

Thanks!
 

INSTALLING SameCat

As a plugin, just drop it into your wp-content/plugins directory and activate it.
As a hack, put it in the wp folder (or cg-plugins) and include() it in index.php
or my-hacks.php.

 


USING SameCat

Add to your index.php something like:

<?php echo list_posts_of_cat(get_the_category(), 5, 5); ?>

The first entry gets the array of categories for the current post (i.e., this can
be used within the $posts main loop, which certain other solutions can’t)

It also be used outside the posts loop with a fixed single number, to show some posts
from a specific cat in the menu/sidebar, like:

<?php echo list_posts_of_cat('2', 5, 5); ?>

The second number in the tag/call is the maximum total links that should be output.

The third number is how many to pick randomly. If the random count is zero, just takes the first MAX posts in the ordered query results – ordering respects post date, but also respects Sticky posts. If the random count equals the max, it generates completely random picks. If the random count is non-zero, it increases the total query result limit by a factor, in order to grab more from the database than it will need, in order to then pick some ordered, then some random, total number of entries.

 


Function Parameters

Further details on the function call follow:

function list_posts_of_cat($cats, $max = 8, $randomize = 0, $not_post = 0, $orderby='date',
$doecho=0, $format='html', $before = "", $after = "")

The first three parameters were described above. Here's the rest:

$not_post
- use $post->ID to exclude the current post ID from the results

$orderby
- can be any post field, though currently tested as 'date' and 'title'. date is descending,
title is ascending (only title currently is ascending).

$doecho
- echo the results automatically, so you don't need to put an echo before the function call.

$format, $before, $after
- the link stylings. look at the WP core function get_archives_link() for details.

 
 
©Copyright 2003-2005, David Chait. All rights reserved.
  
 

 

NO WARRANTY

This library is free for use, WITH NO WARRANTY:
 

THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE
LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.