• I’m trying to get a list of recent posts in each category like your often see done on newspapers, instead of the more ‘blog looking’ list of recent posts. I’m trying to achieve this task with Customizable Post Listings plugin.

    When I put this code into the theme

    <?php c2c_get_recent_posts(5, "<li>%post_URL%", "4"); ?>

    I expected to get the 5 most recent posts for category #4, however I get just the 5 most recent posts regardless of category. Since I have one of these for each category, I just get 5 blocks of the latest posts.

    I’m fairly certain I’m using the right syntax because I’ve gotten it to work with this plugin on previous projects.

    I’m wondering if it has something to do with the loop. On this project I’m leaving the loop in place because I also want to have a preview of the most recent post displayed at the top first, where as in the last project I completely took the loop out of index.php.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Hi darintenb – I’ve been having a similar problem with calling ‘Recent Posts’, with certain attributes (excerpts, images), outside of the Loop. I found that if I wanted to call up some recent posts, each with an excerpt, I had to call them in a second Loop, rather than just using a query – otherwise the main Loop on the page would replace the post excerpts with that of the post from within the main Loop. So calling a second ‘recent posts’ Loop fixed my problem (you could pull out and put in any post attributes that you wish to call);

    <?php
    					$recentposts = new WP_Query('showposts=3&offset=1');
    					if($recentposts->have_posts()) : while($recentposts->have_posts()) : $recentposts->the_post(); ?>
    
    					<div class="post" id="post-<?php the_ID(); ?>">
    						<div class="posttitle">
    				 			<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    							<p class="meta">
    								<?php the_time('F'); ?> <?php the_time('jS Y'); ?> under <?php the_category(' &amp; ') ?> <?php edit_post_link(); ?></p>
    						</div>
    						<div class="postcontent">
    							<?php the_excerpt(); ?>
    						</div>
    						<div class="postfeedback">
    							<?php wp_link_pages(); ?>
    							<?php comments_popup_link('Comments (0)', 'Comments (1)', 'Comments (%)', 'commentlink', ''); ?>
    						</div>
    					</div>
    
    					<?php endwhile; endif; ?>

    Using the above method of calling the ‘Recent Posts’ might work in combination with the ‘Categories’ syntax that you are trying to use, because it appears as though some post attributes are only called properly when they are called from within the Loop – otherwise anything the Loop does will just override what happens in simple queries to the database.

    Hope that helps in some way. I’m still trying to work out a problem with using the ‘Post Images’ script in combination with this Loop – the guff plugin doesn’t seem to pull up the image that is tied to each post *unless* the post is also being displayed on the same page in the first Loop, i.e. reading a post, on it’s permalink URL, will show the ‘post image’ in the Loop *and* in the Recent Posts Loop (if the post in question is in fact a recent post), but if the post isn’t in the first Loop, but *is* in the recent posts Loop, then the image won’t show next to the post in the recent posts Loop…..confusing huh!

    neilcauldwell: Do you think this would work for my problem as well? I’m looking to list a set of the most recent posts within one category, and as you can see, no one has been able to solve that issue for me.

    Hi LynneLiL – I don’t see any reason why it wouldn’t work if you just slide the right attribute (i.e. category) in the second line;

    $recentposts = new WP_Query(‘showposts=3&offset=1’);

    I don’t know how you call a specific category using WordPress, but if someone can tell you that, it should just fit into the above script. Worth a try at least!

    Lynne – I discovered this last night. The problem with is with WordPress 2.2 and beyond where the MySql table post2cat no longer exists and was replaced with two “taxonomy” tables.

    To fix the Customizable Post Listings plugin, you just need to change three lines.

    I’m by no means a PHP guru, so if this is hard to follow I apologize.

    Here’s the changes you need to make:

    Starting in LINE 44:

    global $wpdb, $tablecomments, $tableposts, $tableterm_relationships, $tableterm_taxonomy;
    if ($add_recent_comment_to_sql && !isset($tablecomments)) $tablecomments = $wpdb->comments;
    if (!isset($tableterm_relationships)) $tableterm_relationships = $wpdb->term_relationships;
    if (!isset($tableterm_taxonomy)) $tableterm_taxonomy = $wpdb->term_taxonomy;
    if (!isset($tableposts)) $tableposts = $wpdb->posts;

    Starting in LINE 59:

    if ($categories) {
    $sql .= “LEFT JOIN $tableterm_taxonomy ON ($tableterm_relationships.term_taxonomy_id = $tableterm_taxonomy.term_taxonomy_id) LEFT JOIN $tableterm_relationships ON ($tableposts.ID = $tableterm_relationships.object_id)”;
    $cats = explode(‘ ‘, $categories);
    }

    In LINE 75:

    $sql .= “$tableterm_relationships.term_taxonomy_id = ‘$cat’ “;

    and that is it. That’ll update the former post2cat SQL database to the current WordPress’s taxonomy system.

    I’ve tried this with two categories on the blog I’m designing and started jumping and shaking because I was so shocked. Let me know if it works for you.

    Man, I’ve tried and I’m still getting an error.

    WordPress database error: [Unknown column ‘wp_term_relationships.term_taxonomy_id’ in ‘on clause’]
    SELECT DISTINCT * FROM wp_posts LEFT JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)WHERE wp_posts.post_date <= ‘2007-11-15 11:07:51’ AND ( wp_posts.post_status = ‘publish’ OR wp_posts.post_status = ‘sticky’ ) AND wp_posts.post_password = ” AND ( wp_term_relationships.term_taxonomy_id = ’16’ ) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10

    This is driving me nuts. Using WP 2.3.1

    Just to be clear, you’re talking about updating version 1.1 of the plugin, correct? not the 1.5 version that seems to be floating around out there.

    Thanks for any insight anyone might have.

    Anekola,

    Could you please make the entire php file available? I’ve done as you suggested, to version 1.1 of the plugin. Based on your instructions, it didn’t make sense to make the changes to version 1.5 of the plugin.

    I’m using WP2.3.1 and am only getting SQL errors. For example, when I’ve used:

    <?php c2c_get_random_posts(1, "%post_content%", "74"); ?>

    (ie to get one random post from category 74, showing the post’s content), I get:

    WordPress database error: [Unknown column 'wp_term_relationships.term_taxonomy_id' in 'on clause']
    SELECT DISTINCT * FROM wp_posts LEFT JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)WHERE wp_posts.post_date <= '2007-11-19 16:55:55' AND ( wp_posts.post_status = 'publish' OR wp_posts.post_status = 'sticky' ) AND wp_posts.post_password = '' AND ( wp_term_relationships.term_taxonomy_id = '74' ) GROUP BY wp_posts.ID ORDER BY rand() DESC LIMIT 0, 1

    (I’ve never posted code before so hopefully that worked).

    Again, maybe seeing the full, altered file will reduce confusion?

    Thanking you heaps in advance!

    I’ve got a problem in modifyng the plugin with the instructions given by Adam on Lorelle’s blog on WordPress.com

    ” Unknown column ‘wp_term_relationships.term_taxonomy_id’ in ‘on clause’] ”

    because the 2 LEFT JOIN in a bad order.
    The LEFT JOIN correct syntax is

    SELECT fields FROM first_table LEFT JOIN second_table ON first_table.primary_key = second_table_external_key

    And so the correct LINE 59 is:

    if ($categories) {
    $sql .= "LEFT JOIN $tableterm_relationships ON ($tableposts.ID = $tableterm_relationships.object_id) LEFT JOIN $tableterm_taxonomy ON ($tableterm_relationships.term_taxonomy_id = $tableterm_taxonomy.term_taxonomy_id)";
    $cats = explode(' ', $categories);
    }

    Everything works correctly with this line for me.

    anekola, your fix worked for me. You rock! ??

    Please note that the term_taxonomy_id does not necessarily represent the category ID so you must check the wp_term_taxonomy table to get the correct number for the category. The term_id is the old category number but you must use the term_taxonomy_id number as your $category.

    This plugin needs to be rehashed a bit. ??

    Hello I am new to all of this and was wondering how I can find out what the wp_term_taxonomy table is to get the correct number for the category? I am running WP2.3 and Customizable Post Listings Version: 1.1 I hope someone can help me so I can show the recent posts in a specific category with a short excerpt or if there is a plugin that will work with the latest version of WordPress. Thanks in advance!!!

    There’s a new version out! Thanks to Matt from https://abstractgourmet.com for providing it.

    You can see a detailed post about Customizable Post Listings here (The fix is available and listed in the comments, way down near the bottom): https://lorelle.wordpress.com/2007/02/14/customizable-post-listings-wordpress-plugin/

    Link to the new version 1.6: https://docs.google.com/View?docid=df6d4qr5_2hj5zwnfm

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘List of recent posts (Plugin: Customizable Post Listings)’ is closed to new replies.