Skip to content

Instantly share code, notes, and snippets.

<?php
function additional_post_classes( $classes ) {
global $wp_query;
if( $wp_query->found_posts < 1 ) {
return $classes;
}
if( $wp_query->current_post == 0 ) {
$classes[] = 'post-first';//ループ内の最初の投稿にpost-firstというclass名を与える
<?php
function future_posts_in_feed($query) {
if ($query->is_feed) {
$query->set('post_status','publish,future');
}
return $query;
}
add_filter('pre_get_posts','future_posts_in_feed');
?>
<?php
add_action( 'init', 'my_custom_menus' );
function my_custom_menus() {
register_nav_menus(
array(
'primary-menu' => __( 'Primary Menu' ),
'secondary-menu' => __( 'Secondary Menu' )
)
);
}
<?php
function oddeven_post_class ( $classes ) {
global $current_class;
$classes[] = $current_class;
$current_class = ($current_class == 'odd') ? 'even' : 'odd';
return $classes;
}
add_filter ( 'post_class' , 'oddeven_post_class' );
global $current_class;
$current_class = 'odd';
<?php
query_posts('showposts=5&category_name=foo');
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_content(); ?>
<?php
endwhile; else:
// No posts.
endif;
wp_reset_query();
<?php
if (strpos($_SERVER[HTTP_REFERER], "twitter.com") == true) {
echo "Hello Twitter User!";
}
?>
<?php add_filter('login_errors', create_function('$a', "return null;")); ?>
<?php define('EMPTY_TRASH_DAYS', 5 ); ?>
<ul>
<li><h2>ランダム記事</h2>
<ul>
<?php
$rand_posts = get_posts('numberposts=5&orderby=rand');
foreach( $rand_posts as $post ) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
<a href="http://twitter.com/share" class="twitter-share-button" data-url="<?php the_permalink() ?>" data-count="vertical" data-via="<?php bloginfo('name') ?>">Tweet</a>
<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>