Skip to content

Instantly share code, notes, and snippets.

View funteractive's full-sized avatar

Keisuke Imura funteractive

View GitHub Profile
var Request = require('request');
var Moment = require('moment');
var FeedParser = require('feedparser')
// config
var username = process.argv[2];
var baseUrl = 'http://b.hatena.ne.jp/' + username + '/';
var rssUrl = 'rss';
var baseYear = parseInt(process.argv[3]);
@funteractive
funteractive / functions.php
Created November 7, 2013 08:25
外部jsファイルの読み込み
<?php
function print_my_scripts(){
if( !is_admin() ){
wp_enqueue_script( 'script', get_stylesheet_directory_uri() . '/shared/js/script.js' );
}
}
add_action( 'wp_footer', 'print_my_scripts' );
@funteractive
funteractive / functions.php
Created November 7, 2013 08:24
組み込みのjQueryを外してGoogle APIのjQueryを読み込む
<?php
function load_cdn() {
if ( !is_admin() ) {
wp_deregister_script( 'jquery' );
wp_enqueue_script( 'jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', 'jquery' );
}
}
add_action( 'init', 'load_cdn' );
@funteractive
funteractive / header.php
Created November 6, 2013 18:16
一般的なWordPressの<title>タグ
<title><?php echo( wp_title( ' | ', true, 'right' ) ); bloginfo( 'name' );?></title>
@funteractive
funteractive / functions.php
Created October 31, 2013 00:54
pre_get_postsでクエリーを変更するひな形
<?php
function custom_query( $wp_query ){
if( !is_admin() && $wp_query->is_main_query() && $wp_query->is_post_type_archive( 'title' ) ){
$wp_query->set( 'posts_per_page', 12 );
}
}
add_filter( 'pre_get_posts', 'custom_query' );
@funteractive
funteractive / functions.php
Created October 30, 2013 07:36
スラッグからpostオブジェクトを取得
<?php
function get_post_by_slug( $post_name, $post_type = 'post' ){
$args = array(
'name' => $post_name,
'post_type' => $post_type,
'posts_per_page' => 1
);
$the_post = get_posts( $args );
$the_post = $the_post[0];
@funteractive
funteractive / functions.php
Created October 29, 2013 09:29
読み込むテンプレートを変える。例は著者ページでhome.phpを読み込む場合。
<?php
function change_default_template( $template ){
if( is_author() ){
$template = get_home_template();
}
return $template;
}
add_filter( 'template_include', 'change_default_template' );
@funteractive
funteractive / functions.php
Created October 25, 2013 05:59
管理画面で設定した日付+時刻のフォーマットを取得
<?php
function get_option_datetime_format(){
$date_format = get_option( 'date_format' );
$time_format = get_option( 'time_format' );
$format = $date_format . ' ' . $time_format;
return $format;
}
@funteractive
funteractive / script.js
Created June 8, 2013 09:37
On jQuery like "foreach".
$.each(object, function(index, value) {
console.log(value);
});
@funteractive
funteractive / functions.php
Created June 7, 2013 22:16
Display template name on front page of WordPress
<?php
add_filter( 'template_include', 'template_debug' );
function template_debug( $template ){
var_dump( $template );
exit;
}