Skip to content

Instantly share code, notes, and snippets.

@lunaluna
lunaluna / gist:9701886
Last active August 29, 2015 13:57
【Javascript】PHPから渡された緯度・経度の値からGoogleMapを描画する【WordPress】
<script>
var map;
// 緯度を変数に代入
var latitude = Number("<?php echo $latitude; ?>");
// 経度を変数に代入
var longitude = Number("<?php echo $longitude; ?>");
// 倍率を変数に代入
@lunaluna
lunaluna / gist:9702100
Created March 22, 2014 06:13
【WordPress】カスタムフィールドに入力された住所からGoogleMapを描画
<?php
$map_address = get_post_meta($post -> ID, 'googlemap_address', true);
$map_marker = get_post_meta($post -> ID, 'googlemap_label', true);
$map_address = esc_html( $map_address );
$map_address = mb_convert_kana( $map_address, "nKV", "UTF-8" );
$map_address = urlencode( $map_address );
$api_uri = 'http://maps.googleapis.com/maps/api/geocode/json?address='. $map_address .'&sensor=false';
$json = file_get_contents($api_uri, true);
@lunaluna
lunaluna / register_post_type_functions.php
Last active August 29, 2015 14:06
【WordPress】カスタム投稿タイプ「新着記事(news)」を register_post_type で登録
<?php
// カスタム投稿タイプ「新着記事(news)」
add_action( 'init', 'news_custom_post_type' );
function news_custom_post_type() {
$labels = array(
'name' => _x( '新着記事', 'post type general name' ),
'singular_name' => _x( '新着記事', 'post type singular name' ),
'add_new' => _x( '新しい新着記事を追加', 'news' ),
'add_new_item' => __( '新しい新着記事を追加' ),
@lunaluna
lunaluna / pre_get_posts_functions.php
Last active August 29, 2015 14:06
【WordPress】メインクエリをpre_get_postsフックを使って各条件で改変
<?php
add_action( 'pre_get_posts', 'foo_modify_main_queries' );
function foo_modify_main_queries ( $query ) {
if ( is_admin() || ! $query -> is_main_query() )
return;
if ( $query -> is_home() ) {
$query -> set( 'post_type', 'post' ); // 投稿
$query -> set( 'orderby', 'menu_order' ); // 指定順
@lunaluna
lunaluna / add_post_type_support_functions.php
Last active August 29, 2015 14:06
【WordPress】functions.phpにadd post type support関数を使って属性を追加
<?php
add_post_type_support( 'post', 'page-attributes' );
@lunaluna
lunaluna / pre_get_posts_functions.php
Last active August 29, 2015 14:06
【WordPress4.0】メインクエリをpre_get_postsフックを使って各条件で改変
<?php
function bar_modify_main_queries ( $query ) {
if ( is_admin() || ! $query -> is_main_query() )
return;
if ( $query -> is_home() ) {
$query -> set( 'post_type', 'post' ); // 投稿
$query -> set( 'orderby', array( 'menu_order' => 'DESC', 'date' => 'DESC' ) ); // 指定順を降順に
@lunaluna
lunaluna / Package Control.sublime-setting
Last active August 29, 2015 14:11
【Sublime Text3】Package Control.sublime-setting for ST3
{
"in_process_packages":
[
],
"installed_packages":
[
"4GL",
"ACF Snippets",
"Alignment",
"All Autocomplete",
@lunaluna
lunaluna / gist:4943971
Last active December 13, 2015 16:58
【jQuery】チェックボックスにチェックが入らないとsubmitボタンが押せない仕様(プライバシーポリシーを読ませるとか)
<script>
$(function() {
$('input[name=confirmprivacy]').change(function() {
var checked = $('input[name=confirmprivacy]').prop('checked');
if (checked) {
$('#btn_confirmation').prop('disabled', false);
$('#btn_confirmation').css('background-color','#0065b3');
} else {
$('#btn_confirmation').prop('disabled', true);
$('#btn_confirmation').css('background-color','#777');
@lunaluna
lunaluna / gist:5006075
Last active December 14, 2015 01:28
【WordPress】テンプレートファイルへ記述するテンプレートタグ【超基礎編・だが紛らわしいもの】
1.home_url - 現在のブログのホームURLを取得する
<?php $home = home_url( '/' ); ?>
現在のブログ(サイト)のホームURLを取得する。ホームURLは、管理者ページの「設定」-「一般」の「サイトのアドレス(URL)」のこと。
WordPress 3.0より前のバージョンではget_option( 'home' )やget_bloginfo( 'home' )を使用していたが、3.0以降ではこの関数を使うほうが望ましい(たぶん)。
2.site_url - 現在のブログのサイトURLを取得する
<?php $site = site_url( '/' ); ?>
現在のブログ(サイト)のサイトURLを取得する。サイトURLは、管理者ページの「設定」-「一般」の「WordPressのアドレス(URL)」のこと。
@lunaluna
lunaluna / package.json
Created February 11, 2015 16:37
Browser-sync 2.0.1 demo package.json
{
"name": "bs.2.0.1-sample",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "browser-sync start --server --files='./*.html, ./*.css'",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",