• Resolved pauro

    (@pauro)


    Hi,
    I have been a long time user of time-machine plugin, it works great until I found out that I have to exclude some post from some cats. I realize that by default this plugin does not have those function. I did a digging and found this (at line 233):

    $q = "SELECT ID, post_title, post_date, post_excerpt, comment_count FROM $wpdb->posts WHERE post_status='publish' AND post_type <> 'attachment' AND post_type <> 'revision' $tm_private $tm_pages AND $q_range $tm_current ORDER BYpost_dateLIMIT ".$options['posts'];

    I think this is the place to mess around to do what I want. But with my lacks of knowledge of sql’s, I need some help coding.
    Logically in human language it probably goes like this:

    get data FROM wpdb->post (like original code above) then cross the data with wpdb->tems NOT IN term ID ‘1,2,3’.

    Any suggestion appreciated

    pauro

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello Pauro. Here is dirty fix for this categoy excluding from Time Machine.

    Find line 250 in time-machine.php and replace this code:

    foreach ( $r as $post )
    {
    	// prepare excerpt
    	if ( $tm_excerpt == TRUE ) {
    		$tm_post_excerpt   = $post->post_excerpt;
    		if ( $tm_excerpt_cut == TRUE ) {
    			if ( $tm_excerpt_length && mb_strlen($tm_post_excerpt) > ($tm_excerpt_length+1) ) { $tm_post_excerpt = tm_substr_utf8($tm_post_excerpt, 0, $tm_excerpt_length)."&hellip;"; }
    		}
    	}
    
    	// print formated post line
    	if ( $options['display_commentnum'] == "1" ) { $pcount = ' (<span title="'.__("Number of comments", "tm").'">'.$post->comment_count.'</span>)'; } else { $pcount = ""; }
    	echo '<li>'.substr($post->post_date,0,4).': <a href="'.get_permalink($post->ID).'" title="'.__("Published at", "tm").' '.$post->post_date.'">'.$post->post_title.'</a>'.$pcount.' '.$tm_excerpt_before.$tm_post_excerpt.$tm_excerpt_after.'</li>';
    }

    with this code:

    foreach ( $r as $post )
    {
    	$pcats = get_the_category($post->ID);
    	$no_this = 0;
    	foreach ($pcats as $pcat) {
    		if ( preg_match("/(5|2)/", $pcat->cat_ID) ) { $no_this = 1; }
    	}
    	if ($no_this <> 1) {
    
    		// prepare excerpt
    		if ( $tm_excerpt == TRUE ) {
    			$tm_post_excerpt   = $post->post_excerpt;
    			if ( $tm_excerpt_cut == TRUE ) {
    				if ( $tm_excerpt_length && mb_strlen($tm_post_excerpt) > ($tm_excerpt_length+1) ) { $tm_post_excerpt = tm_substr_utf8($tm_post_excerpt, 0, $tm_excerpt_length)."&hellip;"; }
    			}
    		}
    
    		// print formated post line
    		if ( $options['display_commentnum'] == "1" ) { $pcount = ' (<span title="'.__("Number of comments", "tm").'">'.$post->comment_count.'</span>)'; } else { $pcount = ""; }
    		echo '<li>'.substr($post->post_date,0,4).': <a href="'.get_permalink($post->ID).'" title="'.__("Published at", "tm").' '.$post->post_date.'">'.$post->post_title.'</a>'.$pcount.' '.$tm_excerpt_before.$tm_post_excerpt.$tm_excerpt_after.'</li>';
    
    	} //no_this
    }

    And also replace in line if ( preg_match("/(5|2)/", $pcat->cat_ID) ) { $no_this = 1; } numbers 5|2 with category ID’s you wish to exclude, separated with pipe sign |.

    Thread Starter pauro

    (@pauro)

    Nicely done,perfect solution, thank you so much.

    swf2002

    (@swf2002)

    Hello great plugin. I want to show just one Category and to exlcude: 5,2,28,57,10,8,20,2,4,29,3,56

    How this must to look?

    if ( preg_match(“/(5|2|28|57|10|8|20|2|4|29|3|56)/”, $pcat->cat_ID) ) { $no_this = 1; }

    is not working

    Thanks

    swf2002

    (@swf2002)

    I want to use that plugin for a “On this day is happen:”. This data will be take from category with ID=58. I want to exclude all other categories. When I write all my categires instead of 58 … it is no work, when I take from the list just one of the category it is work but I want to show only CAT=58… and none from others. Can you help?

    Plugin Author Aleksandar Uro?evi?

    (@urkekg)

    Huh, w/o digging code again, instead of using if( preg_match… ) use exact match

    if ( $pcat->cat_ID != 58 ) { $no_this = 1; }

    Does this dirty hack works as U expected?

    swf2002

    (@swf2002)

    Work perfect. Thanks!

    swf2002

    (@swf2002)

    urkekg, just one simple question. What can be the reasson the changes of the plugin to show years ago events from can 58 to be change not in 00:00 my time, because in 1:30 AM they are stil from previos date. On the morning, about 7:00 AM they are with correct date. I assume is somthing with the time zone. My wordpress clock is correctly setup as our time in Bulgaria +3:00 GMT.

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘excluding post from certain category’ is closed to new replies.