Skip to content

Instantly share code, notes, and snippets.

View ShinichiNishikawa's full-sized avatar
🏠
Working from home

Shinichi Nishikawa ShinichiNishikawa

🏠
Working from home
View GitHub Profile
@ShinichiNishikawa
ShinichiNishikawa / gist:11371541
Last active August 29, 2015 14:00 — forked from wokamoto/gist:11365599
おかもとさんより
<?php
add_filter( 'the_content', 'my_pre_shortcode', 7 );
function my_pre_shortcode( $content ) {
global $shortcode_tags;
$shortcode_tags_org = $shortcode_tags;
remove_all_shortcodes();
add_shortcode( 'code', 'code_shortcode_handler' );
$content = do_shortcode( $content );
@ShinichiNishikawa
ShinichiNishikawa / add_body_class_locale.php
Last active August 29, 2015 14:02
Add locale to body_class
// add locale such as locale_ja, locale_en_US to body class
add_filter( 'body_class', 'add_body_class_locale' );
function add_body_class_locale( $classes ) {
$classes[] = 'locale_' . sanitize_html_class( get_bloginfo('language') );
return $classes;
}
@ShinichiNishikawa
ShinichiNishikawa / functions.php
Created March 12, 2012 17:17
カスタム投稿タイプmenuを登録して、カスタムタクソノミgohantypeを紐付けるfunctions.php
<?php
add_action( 'init', 'create_customeposttype_menu' );
function create_customeposttype_menu() {
$label_arr = array(
'name' => 'メニュー',
'singular_name' => 'メニュー',
'search_items' => 'メニューを検索する',
// 'parent_item_colon' => '' //非階層タイプでは利用しない
);
@ShinichiNishikawa
ShinichiNishikawa / parameters.php
Created March 22, 2012 07:37
Prime Strategy Bread Crumb
<?
$args = array(
'type' => 'string',
'home_label' => 'HOME',
);
if ( function_exists( 'bread_crumb' ) ) { bread_crumb($args); }
?>
@ShinichiNishikawa
ShinichiNishikawa / wp_list_custompost_posts.php
Last active October 2, 2015 03:28
カスタム投稿タイプの投稿一覧で現在表示にcurrentを持たせる
<ul>
<?php
$current_page_id = $wp_query->get_queried_object_id();
$args = array(
'post_type' => 'yourcustomposttype',
);
$your_posts = get_posts($args);
foreach ( $your_posts as $post ) {
setup_postdata($post);
$current_class = null;
@ShinichiNishikawa
ShinichiNishikawa / get_custom_taxonomy_list.php
Created March 22, 2012 20:10
特定のカスタム投稿タイプの記事の一覧を取得する
<ul>
<?php
$args = array(
'post_type' => 'my_posttype',
'taxonomy' => 'my_taxonomy',
'term' => 'my_term',
'numberposts' => '-1',
);
$my_posts = get_posts($args);
foreach ( $my_posts as $post ) {
@ShinichiNishikawa
ShinichiNishikawa / hoshino-goroku.php
Created March 30, 2012 15:23
hoshino-goroku.php
<?php
/*
Plugin Name: Hoshino Goroku
Description: これはただのプラグインではありません。Kunitoshi Hoshino によって発言/ツイートされた最も有名な二つの言葉、「なんとー」、「なるほどですね」 に要約されたWordPressが好きな人々の希望と情熱を象徴するものです。このプラグインが有効にされると、すべての管理画面の右上に <cite>またお会い出来ますことを楽しみにしています</cite> などの言葉がランダムに表示されます。
Author: Friends of @khoshino
Version: 0.1
*/
function hossy_words() {
$words = "ほほう。
@ShinichiNishikawa
ShinichiNishikawa / gist:4108737
Created November 19, 2012 03:08 — forked from gatespace/gist:4108710
最強のテンプレートタグ get_the_khoshino()
<?php
function get_the_khoshino($destination == null, $username == null) {
if ( $destination ) {
return 'というわけで、' . $destination . 'に向かっています';
} else {
if (!empty($username)) {
return 'いやいや'.$username.'さんほどでは。';
} else {
return 'やはりですか。なるほどですね。';
}
@ShinichiNishikawa
ShinichiNishikawa / gist:4139337
Created November 24, 2012 11:51
カテゴリ/タクソノミをGETで受け取った時のバリデーション。Validate GET values against cattegories / taxonomies the site has.
<?php
// example.com?what=abc&where=xyz
// category
$what = $_GET['what'];
$okCats = get_categories();
foreach ( $okCats as $oks ) {
$okCatsArr[] = $oks->name;
}
$ifWhat = in_array($what, $okCatsArr);
@ShinichiNishikawa
ShinichiNishikawa / gist:4139916
Created November 24, 2012 14:36
こっちでよかった。カテゴリ/タクソノミをGETで受け取った時のバリデーション。Validate GET values against cattegories / taxonomies the site has.
<?php
// category の場合
$what = get_term_by( 'name', $_GET['what'], 'category', 'ARRAY_A' );
// district というタクソノミの場合
$where = get_term_by( 'name', $_GET['where'], 'district', 'ARRAY_A' );
// https://gist.github.com/4139337 これが長い方