Skip to content

Instantly share code, notes, and snippets.

<?php
function antispambot_short($atts) {
extract(shortcode_atts(array(
'mail' => '',
'text' => 'クリックしてメーラーを起動',
), $atts));
$mail = antispambot($mail);
return '<a href="mailto:' .$mail . '">' .$text .'</a>';
}
add_shortcode('maillink', 'antispambot_short');
<?php $posts = get_posts('numberposts=10&order=desc&orderby=rand'); ?>
<ul>
<?php foreach($posts as $post): ?>
<li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php echo get_the_post_thumbnail($post->ID, 'thumbnail'); ?></a></li>
<?php endforeach; ?>
</ul>
<?php
$api_key = "APIキー";
wp_enqueue_script("twitter-anywhere",
"http://platform.twitter.com/anywhere.js?id={$api_key}&v=1");
add_action("wp_head", "twitter_anywhere");
function twitter_anywhere()
{
echo '<script type="text/javascript">';
echo 'twttr.anywhere(onAnywhereLoad);';
<?php
function related_posts_shortcode( $atts ) {
extract(shortcode_atts(array(
'limit' => '5',
), $atts));
global $wpdb, $post, $table_prefix;
if ($post->ID) {
$retval = '<ul>';
<?php
function getCatItems($atts, $content = null) {
extract(shortcode_atts(array(
"num" => '5',
"cat" => ''
), $atts));
global $post;
$oldpost = $post;
$myposts = get_posts('numberposts='.$num.'&order=DESC&orderby=post_date&category='.$cat);
$retHtml='<ul>';
<?php
function slt_PHPErrorsWidget() {
$logfile = '/path/logs/error.log'; // エラーログのパス
$displayErrorsLimit = 100; // 最大エラー件数
$errorLengthLimit = 300; // 最大文字数
$fileCleared = false;
$userCanClearLog = current_user_can( 'manage_options' );
// Clear file?
if ( $userCanClearLog && isset( $_GET["slt-php-errors"] ) && $_GET["slt-php-errors"]=="clear" ) {
$handle = fopen( $logfile, "w" );
<?php
function feedonly_shortcode( $atts, $content = null) {
if (!is_feed()) return "";
return $content;
}
add_shortcode('feedonly', 'feedonly_shortcode');
?>
/*記事内で以下のショートコードで囲ったコンテンツはフィード内でのみ閲覧可能になる*/
[feedonly]RSSフィード登録者にだけ公開します。[/feedonly]
<?php
function is_old_post($post_id=null){
$days = 90;//日数
global $wp_query;
if(is_single() || is_page()) {
if(!$post_id) {
$post_id = $wp_query->post->ID;
}
$current_date = time();
$offset = $days *60*60*24;
<?php
$related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'numberposts' => 5, 'post__not_in' => array($post->ID) ) );
if( $related ) foreach( $related as $post ) {
setup_postdata($post); ?>
<ul>
<li>
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</li>
</ul>
/*タグ名でタームの数を取得*/
<?php $tag_properties = get_term_by( 'name', 'foo', 'post_tag' ); echo $tag_properties->count; ?>
/*スラッグ名でタームの数を取得*/
<?php $tag_properties = get_term_by( 'slug', 'foo', 'post_tag' ); echo $tag_properties->count; ?>