ホーム » WordPress

Customizable Post Listingsで新着にNEWをつける

Submitted by on 2009年2月28日 – 14:13コメントはありません。

表示させることができたので覚書 :shock:
Customizable Post Listings Version:3.0.1 Last update:03 April 2008
http://coffee2code.com/wp-plugins/#customizablepostlistings

うちのは
CPL日本語版 ver 2.0.1
http://hsuzuki.ddo.jp/weblog/?p=2339

参考HP ともかめ亭 WordPress Hacks : New / Up マーク :twisted:
http://tomokame.moo.jp/archives/614

サンプルコード

function new_up() {
	$display = '';
	$newmark = '<span style="color: maroon;">NEW!</span>';
	$upmark = '<span style="color: blue;">UP!</span>';
 
	$pos_time = get_the_time('U');
	$mod_time = get_the_modified_time('U');
 
	if ((time() - $mod_time) / (60*60*24) <3) {
		if (($mod_time - $pos_time) / (60*60*24) <1) {
			$display = "$newmark";
		} else {
			$display = "$upmark";
		}
	}
	return "$display";
}

CPL日本語版 ver 2.0.1
/wp-content/plugins/customizable-post-listings/customizable-post-listings.php

// ************************ START TEMPLATE TAGS ******************************************************************
//  以下に挿入
function new_up() {
	$display = '';
	$newmark = '<span style="color: maroon;">NEW!</span>';
	$upmark = '<span style="color: blue;">UP!</span>';
 
	$pos_time = get_the_time('U');
	$mod_time = get_the_modified_time('U');
 
	if ((time() - $mod_time) / (60*60*24) <3) {
		if (($mod_time - $pos_time) / (60*60*24) <1) {
			$display = "$newmark";
		} else {
			$display = "$upmark";
		}
	}
	return "$display";
} //ここまで
 
function c2c_get_recent_posts( $num_posts = 5,
	$format = "<li>%post_date%: %post_URL%</li>",

1176行目挿入

//Modified by H.Suzuki--End
				case '%post_URL%':
				case '%post_URL_short%':
					if (!$title) { $title = the_title('', '', false); }
					if ('%post_URL_short%' != $tag)
						$ntitle = $title;
					else {
						$ntitle = strip_tags($title);
						if ($post_URL_short_words) {
							$words = explode(' ', $ntitle);
							$ntitle = join(' ', array_slice($words, 0, $post_URL_short_words));
							if (count($words) > $post_URL_short_words) $ntitle .= "...";
						} elseif ($post_URL_short_length) {
							if (strlen($ntitle) > $post_URL_short_length) $ntitle = substr($ntitle,0,$post_URL_short_length) . "...";
						}
					}
					$new = '<a href="'.get_permalink().'" title="この記事の内容を表示">'.$ntitle.'</a>';//translated by H.Suzuki
					$new .= new_up(); //挿入
					break;
				case '%trackbacks_count%':
					if (!$trackback_count) { $trackback_count = c2c_comment_count($post->ID, 'trackback'); }
					$new = $trackback_count;
					break;
				case '%trackbacks_fancy%':
					if (!$trackback_count) { $trackback_count = c2c_comment_count($post->ID, 'trackback'); }
					if ($trackback_count < 2) $new = $trackback_fancy[$trackback_count];
					else $new = str_replace('%trackbacks_count%', $trackback_count, $trackback_fancy[2]);
					break;
			}
			$text = str_replace($tag, $new, $text);
		}
		if ($echo) echo $text . "\n";
	}
	$post = $orig_post; $authordata = $orig_authordata; $comment = $orig_comment;
	return ($echo ? count($posts) : $text);
} // end function c2c_get_recent_tagmap()
 
function c2c_get_recent_handler( $posts, $format = '', $date_format = '', $echo = true ) {
	if (!$format) { return $posts; }
	if (!is_array($posts)) $posts = array($posts);

Customizable Post Listings Version:3.0.1
/wp-content/plugins/customizable-post-listings/customizable-post-listings.php

// ************************ START TEMPLATE TAGS ******************************************************************
// 以下に挿入
function new_up() {
	$display = '';
	$newmark = '<span style="color: maroon;">NEW!</span>';
	$upmark = '<span style="color: blue;">UP!</span>';
 
	$pos_time = get_the_time('U');
	$mod_time = get_the_modified_time('U');
 
	if ((time() - $mod_time) / (60*60*24) <3) {
		if (($mod_time - $pos_time) / (60*60*24) <1) {
			$display = "$newmark";
		} else {
			$display = "$upmark";
		}
	}
	return "$display";
} //ここまで
 
function c2c_get_recent_posts( $num_posts = 5,
	$format = "<li>%post_date%: %post_URL%</li>",

1128行目挿入

			case '%post_URL%':
			case '%post_URL_short%':
				if (!$title) { $title = the_title('', '', false); }
				if ('%post_URL_short%' != $tag)
					$ntitle = $title;
				else {
					$ntitle = strip_tags($title);
					if ($post_URL_short_words) {
						$words = explode(' ', $ntitle);
						$ntitle = join(' ', array_slice($words, 0, $post_URL_short_words));
						if (count($words) > $post_URL_short_words) $ntitle .= "...";
					} elseif ($post_URL_short_length) {
						if (strlen($ntitle) > $post_URL_short_length) $ntitle = substr($ntitle,0,$post_URL_short_length) . "...";
					}
				}
				$new = '<a href="'.get_permalink().'" title="View post '.wp_specialchars(strip_tags($title), 1).'">'.$ntitle.'</a>';
				$new .= new_up(); //挿入
				break;
			case '%trackbacks_count%':
				if (!$trackback_count) { $trackback_count = c2c_comment_count($post->ID, 'trackback'); }
				$new = $trackback_count;
				break;
			case '%trackbacks_fancy%':
				if (!$trackback_count) { $trackback_count = c2c_comment_count($post->ID, 'trackback'); }
				if ($trackback_count < 2) $new = $trackback_fancy[$trackback_count];
				else $new = str_replace('%trackbacks_count%', $trackback_count, $trackback_fancy[2]);
				break;
		}
		$text = str_replace($tag, $new, $text);
	}
	if ($echo) echo $text . "\n";
}
$post = $orig_post; $authordata = $orig_authordata; $comment = $orig_comment;
return ($echo ? count($posts) : $text);
} // end function c2c_get_recent_tagmap()

こんな感じで出力
CPL.jpg

ご参考まで….

人気度: 6% [?]