Skip to content

Instantly share code, notes, and snippets.

@ShinichiNishikawa
Last active December 16, 2015 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShinichiNishikawa/5465203 to your computer and use it in GitHub Desktop.
Save ShinichiNishikawa/5465203 to your computer and use it in GitHub Desktop.
テーマ作るときのデフォルトのfunctions.php
<?php
// アイキャッチ
add_theme_support('post-thumbnails');
// set_post_thumbnail_size(443, 171, true);
// その他の画像サイズ
//add_image_size( 'sizename', 100, 100, true );
// jQuery の差し替えとその他のJSの登録
// add_action('init', 'replacejQuery');
function replacejQuery()
{
if ( ! is_admin() ) {
wp_deregister_script('jquery');
$jqueryPath = 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
wp_enqueue_script('jquery', $jqueryPath, array(), '1.7.1');
wp_enqueue_script('abc', get_template_directory_uri() . '/js/abc.js', array('jquery'), '');
}
}
// カスタム投稿タイプ「あああ / xxx」を追加
add_action( 'init', 'create_customPostType_xxx' );
function create_customPostType_xxx()
{
$label_arr = array(
'name' => 'あああ',
'singular_name' => 'あああ',
'search_items' => '検索する',
'add_new' => '新規追加',
'add_new_item' => '新規追加',
'edit_item' => '編集',
'new_item' => '新規追加',
'view_item' => '表示',
'not_found' => 'ありません',
'not_found_in_trash' => 'ゴミ箱は空です',
// 'parent_item_colon' => '' //非階層タイプでは利用しない
);
$conf_array = array(
'labels' => $label_arr,
'public' => true, // 公開用のコンテンツか
'exclude_from_search' => false, // 検索から除外するならtrue
'publicly_queryable' => true, // Query操作したいならtrue
'show_ui' => true, // falseだとUIが表示されない
'show_in_nav_menus' => true, //ナビゲーションメニューに表示する
'show_in_menu' => true, // メニューに表示するか。string指定してトップレベルを選べる
'menu_position' => 5, // 5投稿、10メディア、15リンク、20固定ページ、25コメント、60外観、65プラグイン、70ユーザ、75ツール、80設定、100最下部に独立
//'menu_icon' => '', url指定してアイコンを
'capability_type' => 'post', // 権限タイプ post なら投稿権限がある人に表示される的な
'hierarchical' => false, // 親子があるかどうか trueだとページ、falseだと投稿みたいになるのか
'supports' => array(
'title',
'editor',
'thumbnail',
// 'custom-fields',
'revisions',
'author',
// 'excerpt',
//'trackbacks',
//'comments',
//'page-attributes',
),
'has_archive' => true,
// リライト関連
'rewrite' => array(
'slug' => 'xxx',
'with_front' => true,
'feeds' => true, // feed
'pages' => true, // ページネーション
), // rewriteするかどうか
'query_var' => true, // true: ポストタイプ名でquery操作が可能, string指定でその文字列でquery操作が可能
);
register_post_type( 'xxx', $conf_array );
}
// xxx にカスタムタクソノミ「いいい / yyy」を追加する。
add_action( 'init', 'add_customTaxonomy_yyy' );
function add_customTaxonomy_yyy()
{
register_taxonomy(
'yyy',
'xxx',
array(
'label' => 'いいい',
'show_ui' => true,
'query_var' => true,
'show_admin_column' => true,
'sort' => true,
'hierarchical' => true,
'args' => array( 'orderby' => 'term_order' ),
'rewrite' => array( 'slug' => 'yyy' ),
)
);
}
// 投稿→ニュースに表記変更
add_filter( 'gettext', 'custom_gettext', 10, 3 );
add_filter( 'gettext_with_context', 'trans_custom_gettext', 10, 4 );
add_filter( 'ngettext', 'trans_custom_gettext', 10, 5 );
add_filter( 'ngettext_with_context', 'trans_custom_gettext', 10, 6 );
function custom_gettext( $translated, $text, $domain, $newText='投稿' )
{
$custom_translates = array(
'default' => array(
'投稿' => $newText,
'投稿編集' => '編集',
'投稿の編集' => '編集',
'投稿一覧' => '一覧',
'投稿を検索' => '検索',
'投稿を表示' => '表示',
'投稿は見つかりませんでした。' => 'ニュースは見つかりませんでした。',
'ゴミ箱内に投稿が見つかりませんでした。' => 'ゴミ箱は空です',
'投稿を更新しました。<a href="%s">投稿を表示する</a>' => $newText . 'を更新しました。<a href="%s">' . $newText . 'を表示する</a>',
'この投稿を先頭に固定表示' => 'このニュースを先頭に固定表示',
'アイキャッチ画像' => 'メイン画像',
'アイキャッチ画像を設定' => 'メイン画像を選ぶ',
)
);
if ( isset( $custom_translates[$domain][$translated] ) ) {
$translated = $custom_translates[$domain][$translated];
}
return $translated;
}
function trans_custom_gettext() {
$args = func_get_args();
$translated = $args[0];
$text = $args[1];
$domain = array_pop( $args );
$translated = custom_gettext( $translated, $text, $domain );
return $translated;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment