Categories
Package/plugin/module WordPress

Plugin: Customizable Post Listings

This plugin has been updated! Comments to this post are now closed. For the latest download, documentation, and link for posting new comments related to this plugin, visit the plugin’s new homepage at:
coffee2code.com/wp-plugins/customizable-post-listings
Name:
Customizable Post Listings
Author:
Scott Reilly
Version:
1.1
Last updated:
27 September 2004
Description:

Display Recent Posts, Recently Commented Posts, Recently Modified Posts, Random Posts, and other post listings using the post information of your choosing in an easily customizable manner. You can narrow post searches by specifying categories and/or authors, among other things.

Notes:

List of percent substitution tags supported:

%comments_count% // Number of comments for post %comments_fancy% // Fancy reporting of comments: (see get_recent_tagmap()) %comments_url% // URL to top of comments section for post %comments_URL% // Post title linked to the top of the comments section on post's permalink page %last_comment_date% // Date of last comment for post %last_comment_id% // ID for last comment for post %last_comment_URL% // URL to most recent comment for post %last_commenter% // Author of last comment for post %last_commenter_URL // Linked (if author URL provided) of author of last comment for post %post_author% // Author for post %post_author_count% // Number of posts made by post author %post_author_posts% // Link to page of all of post author's posts %post_author_url% // Linked (if URL provided) name of post author %post_content% // Full content of the post %post_date% // Date for post %post_excerpt% // Excerpt for post %post_excerpt_short% // Customizably shorter excerpt, suitable for sidebar usage %post_id% // ID for post %post_modified% // Last modified date for post %post_title% // Title for post %post_url% // URL for post %post_URL% // Post title linked to post's permalink page

Installation:
  1. Download the file customizable-post-listings.zip and unzip it into your /wp-content/plugins/ directory.
    -OR-
    Copy and paste the the code ( customizable-post-listings.phps ) into a file called customizable-post-listings.php, and put that file into your /wp-content/plugins/ directory. Please ensure you do not introduce any spaces or other characters before the <?php or after the ?>
  2. Optional: Change configuration options in the file to your liking. In-code comments should help you there.
  3. Activate the plugin from your WordPress admin ‘Plugins’ page.
  4. Include one or more of the templates defined below into a template file (most likely sidebar.php)
Functions:

function c2c_get_recent_posts ($num_posts = 5, $format = "<li>%post_date%: %post_URL%</li>", $categories = '', $orderby = 'date', $order = 'DESC', $offset = 0, $date_format = 'm/d/Y', $authors = '', $include_passworded_posts = false)

function c2c_get_random_posts($num_posts = 5, $format = "<li>%post_date%: %post_URL%</li>", $categories = '', $order = 'DESC', $offset = 0, $date_format = 'm/d/Y', $authors = '', $include_passworded_posts = false)

function c2c_get_recently_commented ($num_posts = 5, $format = "<li>%comments_URL%<br />%last_comment_date%<br />%comments_fancy%</li>", $categories = '', $order = 'DESC', $offset = 0, $date_format = 'm/d/Y h:i a', $authors = '', $include_passworded_posts = false)

function c2c_get_recently_modified ($num_posts = 5, $format = "<li>%post_URL%<br />Updated: %post_modified%</li>", $categories = '', $order = 'DESC', $offset = 0, $date_format = 'm/d/Y', $authors = '', $include_passworded_posts = false)

  • $num_posts : The number of posts to return; default is 5
  • $format : A string that uses percent substitution tags to define the data you want displayed for each listing and how you want it displayed;set it to ” (two single-quotes) to return an array of the requested post objects without outputting anything.
  • $categories : A space separated list of category IDs to match against; leave empty to consider posts from any category
  • $order : The order with which the post listing should be sorted, either ‘ASC’ (for ascending) or ‘DESC’ (for descending); default is ‘DESC’
  • $offset : The number of posts to skip; default is 0
  • $date_format : Date format string, PHP-style, if different from the blog’s default date-format string
  • $authors : A space separated list of author IDs to match against; leave empty to consider posts from any blog author
  • $include_passworded_posts : A boolean value, either ‘true’ or ‘false’, indicating if passworded posts should be considered in the post search
Tips & Examples:

The “Recent” listings on the sidebar of this site all use this plugin.

The simplest examples would be the following (for brevity’s sake, in the examples I’m going to specify 3 as the number of posts I want returned):

<ul> Recent Posts <?php c2c_get_recent_posts(3); ?> </ul>

Would output something like:


<ul>Recently Commented <?php c2c_get_recently_commented(3); ?> </ul>

Would output something like:


<ul>Recently Updated <?php c2c_get_recently_modified(3); ?> </ul>

Would output something like:


But what you may really want is to run the Recent Posts/Recently Commented Posts/Recently Updated Posts/Random Posts calls and customize the listing output. That’s where the percent substitution tags come into play. The second argument to each of the three functions above is the $format argument. $format is a string that represents how each post found by the function should be output. Any percent tags (as listed and defined above) will be replaced with the appropriate data.

So, let’s say you want a list of recent posts, to include the post author’s name linked to the archive of all of that author’s posts, plus a short excerpt of the post. And let’s say you only want posts from category ’34’. You’d do this:

<ul> <?php c2c_get_recent_posts(3, "<li>%post_date%: %post_URL%<br />by: %post_author_posts%<br />%post_excerpt_short%</li>", "34"); ?> </ul>

Which would output something like:

Release Log:
  • 27 Sep 2004 : v1.2 —
    • Added the ability to get random posts, and added the convenience function c2c_get_random_posts() to get them
    • Functions will now consider sticky posts (those in which ‘post_status’ gets set to ‘sticky’) in addition to published posts
    • Changed license from BSD-new to MIT
  • 05 Sep 2004 : v1.02 — Bugfix to immediately return if no posts match criteria
  • 03 Sep 2004 : v1.01 — Bugfix for when $authors has more than one author
  • 27 Aug 2004 : v1.0 — Released to the public
Copyright & Disclaimer:

Copyright (c) 2004 by Scott Reilly (aka coffee2code)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Acknowledgements:
N/A

234 replies on “Plugin: Customizable Post Listings”

It might be interesting to add the ability to get the active plugins. I’ve been messing around a bit and I’m just not good enough to make it work. It seems to me that the only table that contains that info is wp_options under ‘active_plugins’ but I don’t know if it’s possible to get more info about the plugin itself – url, author, etc from the sqldb. Even so, it would be cool to add the ability to show which plugins are active.

Thanks for the great tool!

Hello Scott!

Wow, wonderful plugin! Thanks a lot!

I wonder if it could be implemented a %comment_excerpt_short% tag! It would be nice to display the beggining of the comments on the side bar!

Keep on the great work!!

Cheers,

oculos

hi scott!

a few months ago i asked for something like this. now you’ve made this! it works great! thanks for all your efforts.

i have one question. it seems that your plugin is the only one i know of its kind that can pull up all of the entries by one author. do you know how i can embed this into the loop? for example, i have a photoblog of multiple authors on my site. the photographer (or author) of each post is included at the end of each entry (within the loop). is it possible to make it so that if i click on the author’s name, it brings up all the entries by that author and filter out all the other authors? wordpress has a author_post_link, but that only brings up the most recent entries.

Great plugin. Thank you very much!

But I have some problem. With function:
<?php c2c_get_recent_posts(10,"<li><span class="recent-post-date">%post_date%</span>: %post_URL%<br />by: %post_author_posts%</li>",'','date','DESC','10','d F Y',''); ?>

In database table wp_users, the authors that didn’t have “user_nicename” column, will not show up their URL. Instead, will show something like:
some.site.com/berita/arsip/author// for, example, user with ID =7

How do geet I show those author that didn’t have nice name? is it my blog configuration?

I don’t know if anyone else have had this problem with the recent version, but it screws up the header informations in wp-login.php saying that the headers were already sent by the plugin. Any say on this?

Excellent plugin. I had written my own to do similar things, but with some added functionality. I’ve since modified yours to add the functionality I desired. You are welcome to roll these mods in if you wish.

* Added support for excluding categories. As in the rest of WordPress, simply provide a list of negative categories separated by commas (e.g. ‘-27,-28’) for the $categories parameter.
* Added support for listing of post categories as well as links to category archives (with customizable delimiter).
* Added support for links to comments section for fancy comments.

Hopefully someone will find it useful. To see them in action, hit the website link above: the sidebar displays the 5 most recent entries that aren’t in my ‘Asides’ or ‘Currently’ categories and the bottom of the index uses new category links and fancy comment links.

Here’s a link to the updated code.

Thanks again for the good code to add on to.

First off, thanks everyone for the kind words. Now on to the answers:

amory: There are two things you would need to address in the examples you provided. The second argument lets the plugin know how to output the text from the posts once it has found them (i.e. did you want to show the post’s date, content, excerpt, etc). The third argument is where you specify the category(ies). But instead of using the category name you have to use the category id (you can find the category id in the “categories” page of the admin section of your blog). Assuming photography had an id of 3, here is an example to list the post titles of the 5 most recent posts in the photography category:
<ul><?php c2c_get_recent_posts(5, "<li>%post_URL%</li>", '5'); ?>

Paul Hoch: You might want to check out the Plugins Used plugin, which allows you to display info about the plugins driving your blog.

Stefan Liden: I haven’t looked at Exhibit Engine so I can’t say what is involved in adding thumbnails from it as a percent substitution string, but I’ll keep it in mind for possible future inclusion.

oculos: Great suggestion! I’ll see about including it in the next version of the plugin.

Tin: I’ll have to take a look at the WP code to see if there are already provisions to do what you want. My guess is that WP allows for what you want.

Gede Wijaya: I’ll have to look into your issue farther. As far as I know, the user_nicename database field is supposed to be auto-generated by WP. If it isn’t, I’ll have to take it into account in a subsequent release of this plugin.

Mi: Getting errors about header information already being sent is usually a result of the plugin file having a space or other characters before the <?php at the start of the file or after the ?> at the end of the file.

ColdForged: Thanks for the code contribution! I haven’t had a chance to look at the code yet, but it sounds like you’ve addressed some of the areas I’ve targeted for future releases. I’ll definitely credit you for whatever code I use.

I’m curious to see how you did category exclusions; it’s been awhile, but I recall there seeming to be something tricky about it… maybe it was my SQL skillz weren’t good enough to construct a single query to simultaneously handle category inclusions and exclusions.

You’re welcome. Take a gander… I essentially reused the ideas from the WordPress exclusion code.

I’m still working on things… this is a very fresh project (this morning) as I add functionality like the Asides to my site. Hence, it’s sort of a moving target. I’ve already added another replacement (%comment_number_url%) and I’m now returned the actual number of posts returned so that people that need to know that can get that information easily.

Again, nice plugin… saved me some work!

Another thing you may want to think about… the way you’re handling %post_content% using the “apply_filters” causes the content to always be surrounded by paragraph tags. If you instead use:

$new = wptexturize($post->post_content);

It’ll apply the filters but not surround it in paragraph tags. The tags are problematic in an “asides” situation where you want the content inline. Just a thought.

Hi, I love your plug in, but am having a slight problem.

I am trying to display most recent posts (without dates), most recent comments & most commented. In your blog these all seem to lay out consistently, i.e. there is the same amount of space between the title ‘most recent posts’ and the content below it, as there is between ‘links’ and the stuff below it. On mine this does not happen – there is no space beneath ‘most recent posts’ etc.

Also, while everything looks consistent in internet explorer, in every other browser, the title text i.e. ‘most recent posts’ displays in a different font, at a different size, in a different colour and the text below it keeps the style sheet style, but displays without the same indent.

Any suggestions???

I’m curious to see how you did category exclusions…

To be honest, I only tested it with a single exclusion. When I went to add the second exclusion is when the problems cropped up :).

Updated to handled multiple exclusions. Note that to really support multiple exclusions at the core “loop” level, the core code has to change too. The file “classes.php” has the handling for constructing the appropriate select statement, and that has to be tweaked a bit.

I had to do this because — as of today — I have two categories that are meant to be “out of the loop”: the asides and a “currently reading” category. As of now the code handles it fine. You can see it in action at my homepage: the currently reading section in the sidebar, the “Last Five Entries” in the sidebar, the “asides” sections between main posts and the “More Recent Entries” at the bottom of the main page all use the c2c…() function with inclusions and exclusions.

Latest code with working exclusions is here.

Paul,

Any way you could provide a link?

This almost certainly sounds like a CSS issue. This plugin merely outputs the information extracted from the database in whatever format you specify. It’s up to your CSS to style it appropriately.

Well, another day another version :D. This time I’ve added support for keeping track of the number of times a post is viewed, sorting by that column (for “Most Popular Posts” kind of lists), and displaying the count of pageviews. This one requires a modification of the WordPress posts table to add a field to keep track of the number of views. Details on installation can be found in this post.

The current version of the code can be found here.

I would like to use c2c_get_recent_posts on two different pages for two different sets of categories and two different offset values. It seems I’m not able to do this because the config is done in the plugin itself, rather than by passing arguments in the page. It looks like the only argument you allow for within the page itself is the number of entries. Would be great if things were handled in an array on the page itself like…

[?php c2c_get_recently_modified(num_posts=5&
categories=21,23,34&offset=2); ?]

That way this could be used in a lot of different ways on different pages. Or maybe that’s already possible and I’m missing something? Thank you…

ColdForged: I still haven’t had the time to meaningfully look at your contributions, but will do so soon. Thanks again!

Ryan: I think you are overlooking in the instructions the other arguments to the various Customizable Post Listings functions. What you ask for (listing only posts in certain categories and using an offset) are supported, among other things (i.e. only gettings posts posted by certain author(s), customizing the output string, etc). Note that I define the arguments one to a line in the instructions above, like so:

function c2c_get_recent_posts ($num_posts = 5,
 $format = "<li>%post_date%: %post_URL%</li>",
 $categories = '',
 $orderby = 'date',
 $order = 'DESC',
 $offset = 0,
 $date_format = 'm/d/Y',
 $authors = '',
 $include_passworded_posts = false)

pps – Actually, it looks like get_posts won’t do what I want, because it doesn’t provide a way to filter posts by category. I hope WP developers will come up with a solution for a future release that expands the functionality of get_posts by incorporating features of the customizable-post-listings & showcategories plugins.

More specifically, here is the call you’d do based on your example:

<?php c2c_get_recently_modified(5, "<li>%post_URL%<br />Updated: %post_modified%</li>", "21 23 34", "DESC", 2); ?>

Hope that helps!

ps – Upon further review I don’t think I like the whole idea behind [!–more–] because it’s too jarring to the user to land on another page halfway down the page. So I don’t think I’ll use [!–more–]

What I really want to do is display %post_content% if no excerpt is present in the db. But if an excerpt is present in the db — because an author filled out that part of the post form — then I want to display %post_excerpt% and %post_url%

That’s asking a lot. I’m guessing I won’t be able to run PHP within $format to check if a db field is empty.

Actually, though, [!–more–] would be a good solution if it just landed the user on the permalink, at the top of the page, and I’m guessing that’s something I could do with a hack… or maybe within the parameters for the_content()

Hmm… I guess my question about compatiblity with [!–more–] remains an issue… I can’t get [!–more–] to work with this plugin.

pps – Now I see how I can run some PHP to display excerpt or content based on conditions… I just have to do something like:

all is well!

Here’s the code I omitted from the comment above:

[?php
if [ some conditional thingy here ] {
$formatting = [ sundry code and formatting right here ];
} else {
$formatting = [ sundry code and formatting right here ];
}
c2c_get_recent_posts (9999, “$formatting”, ’10’, ‘date’, ‘DESC’, 2, ‘F Y’, ”, false); ?]

So you can see there’s an effort there to perform some tests and provide something different for the second parameter in c2c_get_recent_posts depending on conditions. But I’m not having success because the code above is executed outside the context of c2c_get_recent_posts(), so if I want to test whether there’s an excerpt for a particular post, that doesn’t really work.

So I’m kind of back to square one, wondering if [!–more–] is the answer, and, if so, whether there’s any way to use it with this plugin. Another possible solution would be if customizable-post-listings performed a test for the excerpt and then passed some value to my PHP page that I can use to toggle things in the format parameter.

Or, if there was an additional percent tag like %post_excerpt_or_content% that would display excerpt if one is present in the db or content if no excerpt is present. Even if that kind of percent tag were available there ‘s still a need for other contingencies such as: What if I want to do [a href=”%post_url”]%post_excerpt_or_content%[/a]
if there’s an excerpt but omit the link anchor if there’s no excerpt (because then I wouldn’t be linking to another page for the rest of the post.)

My problem, just to clarify, is that I want to display excerpt + permalink for longer posts, and the entire content (and no permalink) for shorter posts. In other words, if my post is three sentences long, it doesn’t make sense to provide a one sentence excerpt and a link to my three-sentence post. But for longer posts, I want to use the excerpt/link approach. From the content-author perspective, it would be nice to leave the excerpt field blank as my way of indicating that the entire post body should be displayed on the index — hence my desire to test for the presence of an excerpt in the db. But the next best thing would be to use something like [!–more–] when I want excerpt + link… if no [!–more–] is found in the post, then full content should be displayed and no link or link text.

OK, I don’t mean to turn this page into my personal journal, but here’s how to test for an excerpt, for what it’s worth… put this function in template-functions-post.php:

function get_excerpt_status() { // don’t forget to mark your hack
global $id, $post;
global $test_for_excerpt;
$output = ”;
$output = trim(stripslashes($post->post_excerpt));
if ($output != ”) {
$test_for_excerpt = ‘pos’; // no excerpt
} else {
$test_for_excerpt = ‘neg’; // there’s an excerpt
}
}

…then on your web page you can do something like this…

[?php
get_excerpt_status();
if ($test_for_excerpt == ‘pos’) {
$formatting = blahblahblah;
} else {
$formatting = blahblahblah;
}
c2c_get_recent_posts (9999, “$formatting”, ’10?, ‘date’, ‘DESC’, 2, ‘F Y’, ”, false);
?]

This is a great plug in which I’ve been using for a while for my ‘most recent comments’ sidebar section. Everything works as advertised, but I’m having a problem which by reading comments of others I think may not have come up yet, but I can’t image why — or maybe I just missed it.

On my site I restrict comments to registered users and have a few regular readers give me insightful comments once in a while. Every time I post however I normally will link back to previous articles — creating a pickback comment. eg. […] re going for the sealed temperature controlled house you might opt for something like this energy efficient sealed house The basement with glass to th […]

What I want to do is to omit these pingbacks from the most recently commented list — since now someone who really wanted to see what is drawing comments will pull up a lot of posts which just have my own ping backs.

Can you advise the best way to accomplish this (eliminate the pingbacks from the most recent comments)?

Thanks for a great job and great hack!

Hello Scott, I want to thank you for an incredible plugin that makes so many things so much simpler!

I actually have a question (to actually anyone who knows), is there a way that I can display all the posts only within one given month? It doesn’t matter whether or not it outputs code with a sequential ordering of months rather than just outputting one month per “get_recent_post”.

IE

March 2001
date/post
date/post

vs

April 2001
date/post
date/post
<br/>
March 2001
date/post
date/post

and so on and so forth

Also, has anyone attempted the “%comment_excerpt_short%” tag yet? I would be very interested to hear of any developments!

Sorry for the inane questions, php is most definately not a strong point!

Thanks.

Ryan: I’ll add a tag to the next version that indicates the excerpt, if present, should be shown, otherwise the post content will be shown. No worries about posting ideas/suggestions/solutions here, I appreciate the input. Hope you can hold out to the next release.

dozer: Nice suggestion. I’ll include more pingback and trackback stuff in the next release. In the meantime, if you wanted to try a hack to keep pingbacks from being seen as comments by this plugin, do the following in the plugin file:

In the function c2c_get_recent_posts, at line 65 you should see this:

if ($add_recent_comment_to_sql) $sql .= "AND $tableposts.ID = $tablecomments.comment_post_ID AND $tablecomments.comment_approved = '1' ";

Change it to this:

if ($add_recent_comment_to_sql) $sql .= "AND $tableposts.ID = $tablecomments.comment_post_ID AND $tablecomments.comment_approved = '1' AND $tablecomments.comment_content NOT LIKE '%&lt&;pingback />%'";

Line 139 was this:

return $wpdb->get_var("SELECT COUNT(*) FROM $tablecomments WHERE comment_post_ID = '$post_id'");

Change it to this:

return $wpdb->get_var("SELECT COUNT(*) FROM $tablecomments WHERE comment_post_ID = '$post_id' AND comment_content NOT LIKE '%&lt&;pingback />%'");

Line 171 was this:

$comment = $wpdb->get_row("SELECT * FROM $tablecomments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' ORDER BY comment_date DESC LIMIT 1");

Change it to this:

$comment = $wpdb->get_row("SELECT * FROM $tablecomments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' AND comment_content NOT LIKE '%&lt&;pingback />%' ORDER BY comment_date DESC LIMIT 1");

So 3 lines that need changing. If that looks daunting, you can wait until the next release, but it really isn’t that much for you to change if you were so inclined. The official version will have easy options to control whether pingbacks and trackbacks should be considered or not.

Alan: For listing the posts by month, what you probably want is the Sortable Nicer Archives plugin.

As for the %comment_excerpt_short% tag, in the next release of the plugin I’ll include a tag that does just that (though likely named different).

Scott,
I went ahead and took a stab at writing a plugin that conditions formatting based on whether an excerpt is present in the database. It also does enough of what your plugin does to solve my current problem, though overall it’s a more limited plugin and lacks a system of percent tags for now, so formatting must be done in the plugin itself.
If interested see here.
Gracias,
Ryan

Scott, thanks for the hack. I had already done something similar, but didn’t catch all the changes, so the comment counter wasn’t consistant. Anyway, reistalled it per your instructions and it works great. Now pingbacks are excluded……

I was using this plugin withd 1.5 and nightly from 2005-01-12 and it works great! I had used it wih 1.2 and wanted to make sure it worked with 1.5 before I switched. Two quick questions:

Is there a way to have most recent static pages (as there are in 1.5)?

I was playing with the Way Too Clean template which has the ‘Featured Story’ block. Is there a way to have ‘Recent Posts’ exclude the last post from the list?

Thanks!

Jascha: I’ll include the ability to include static pages in the plugin’s various functions in the next release. If you want to be able to do this in the meantime, you’ll have to change a few lines in the plugin file. To minimize the number of code changes I tell you (if you want to pursue it), what exactly did you want to be able to do (just a “most recent static pages” listing)?

As for excluding the most recent post from the list, that is achieved by setting the $offset argument to any of the plugin’s functions. The value for offset indicates how many posts to skip. Set it to 1 and it’ll skip the most recent post.

Yes, I was wanting to have a listing of the most recent static sub-pages. So for example if you had a main page called ‘Editorials’ with all the actual editorials as sub-pages you could list them. Or just list the main pages. It was more a feature enhancement idea. I can wait for the next release to try it out. 😉

I will give the $offset a try. Thanks for the help and plugin.

I’m having issues using the $categories tag with the $offset tag.

Code looks a-like this:

Error is:

Database error: [Unknown column ‘wp_testposts.post_2’ in ‘order clause’]
SELECT DISTINCT * FROM wp_testposts LEFT JOIN wp_testpost2cat ON (wp_testposts.ID = wp_testpost2cat.post_id) WHERE wp_testposts.post_date <= '2005-01-13 12:59:35' AND ( wp_testposts.post_status = 'publish' OR wp_testposts.post_status = 'sticky' ) AND wp_testposts.post_password = '' AND ( wp_testpost2cat.category_id = '1' ) GROUP BY wp_testposts.ID ORDER BY wp_testposts.post_2 DESC LIMIT 0, 1 My intention is to use your plugin function in a loop, so I can do some more specific formatting (within table cells, etc.). To do this, I intend on setting $num_posts to one, $categories to whichever category the "index" is for, and $offset to an incremented variable within the loop. Of course, I can't get this to work from the singular instance I have at the top.

Huh. My first post got cut off.

I’m having issues using the $categories tag with the $offset tag.

Code looks a-like this:


<?php c2c_get_recent_posts($num_posts=1,
$format = "%post_excerpt%",
$offset = 1,
$categories = 2); ?>

Error is:


Database error: [Unknown column 'wp_testposts.post_2' in 'order clause']
SELECT DISTINCT * FROM wp_testposts LEFT JOIN wp_testpost2cat ON (wp_testposts.ID = wp_testpost2cat.post_id) WHERE wp_testposts.post_date <= '2005-01-13 12:59:35' AND ( wp_testposts.post_status = 'publish' OR wp_testposts.post_status = 'sticky' ) AND wp_testposts.post_password = '' AND ( wp_testpost2cat.category_id = '1' ) GROUP BY wp_testposts.ID ORDER BY wp_testposts.post_2 DESC LIMIT 0, 1

My intention is to use your plugin function in a loop, so I can do some more specific formatting (within table cells, etc.). To do this, I intend on setting $num_posts to one, $categories to whichever category the “index” is for, and $offset to an incremented variable within the loop.

Of course, I can’t get this to work from the singular instance I have at the top.

Thomas: In order to specify the value for a function’s argument, you must also specify the values for arguments that appear before that argument. You must also specify the arguments in the order they were defined by function.

Here is probably what you wanted to use:

<?php c2c_get_recent_posts(1, "%post_excerpt%", "2", "date", "DESC", 1); ?>

I’m getting an error when I save posts:

Warning: Cannot modify header information – headers already sent by (output started at /usr/home/spitf10/www/htdocs/wp-content/plugins/customizable-post-listings.php:306) in /usr/home/spitf10/www/htdocs/wp-admin/post.php on line 340

I checked to make sure there’s no leading or trailing white space in the plugin file. I also re-copied your source from this page (v 1.1) into the file and uploaded. When I deactive the plugin, problem disappears. Reactivate, it’s back.

Ryan: Try downloading the zip for the plugin, unzipping that, and uploading the file you extracted. As far as I know, 99.9% of the “Cannot modify header information…” errors are a result of leading and/or trailing white space (or other characters).

Scott, I’m using your plugin to pull up dinamic content for my site, but its not a blog, so I had no need for “the loop” showing the rest of the posts. But by removing “the loop” from index.php and using your functions exclusively, disables alot of functions such as search, post popups, and coments. Any sugestions on how to retain all the functionality of “the loop” without showing all the posts?

Great plug-in. One question, though: Is there an easy way to request recent posts that are in BOTH category A and category B? Right now, if I put two category IDs separated by a space, your recent_posts function returns posts that are in EITHER category A OR category B.

I’d like to return only posts that are in both. Is this possible?

Just another request for a %comment_excerpt_short% function.
This would be particularly useful for the author and I think enticing to those reading and already aware of recent post titles which often are present already on the page.

Great plug in thank you!

Comments are closed.