Skip to content

Instantly share code, notes, and snippets.

@tkc49
tkc49 / gist:da2bea7cad0e98d2f3b8
Last active August 29, 2015 14:02
タクソノミーを利用した際にターム一覧を表示する時のコード
<?php $target_taxonomy = "taxonomy-name"; // タクソノミー名を変数に設定する ?>
<?php $terms = get_terms($target_taxonomy,array('hide_empty' => false, )); // 空のタームも取得できるようにする ?>
<?php if ( !empty( $terms ) && !is_wp_error( $terms ) ): // 空かつエラーではないか ?>
<ul>
<?php foreach ( $terms as $term ): ?>
<li><a href="<?php echo get_term_link($term,$target_taxonomy); ?>"><?php echo $term->name; ?></a></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
@tkc49
tkc49 / functions.php
Created June 26, 2014 03:44
WordPressのビジュアルエディターに独自スタイルのボタンを追加するコード
<?php
function mytheme_tinymce_settings($settings)
{
$style_formats = array(
array(
'title' => 'タイトルにする',
'selector' => 'h1',
'classes' => 'title-headding'
),
@tkc49
tkc49 / functions.php
Created November 8, 2014 02:13
RewriteAPIのサンプルソースです。 【管理画面】→【表示設定】→投稿ページ:ブログ(slug:blog)にした時に本来、URLが http://xxxx/blog となるのを http://xxxx/contents-list/reading/blog で投稿一覧を表示するサンプルです。
function myposttype_rewrite() {
global $wp_rewrite;
add_rewrite_rule(
'contents-list/reading/blog',
'index.php?pagename=blog',
'top'
);
@tkc49
tkc49 / gist:08f859c675ce8ac8f463
Last active August 29, 2015 14:18
kintoneのレコード一覧画面、レコード詳細画面から他のアプリへページ遷移できるセレクトボックスメニューです。
(function(){
"use strict";
var subdomain = "";
// レコード一覧画面イベント
kintone.events.on('app.record.index.show',createAppSelectBox);
// レコード詳細画面イベント
kintone.events.on('app.record.detail.show',createAppSelectBox);
@tkc49
tkc49 / 0_reuse_code.js
Last active September 9, 2015 09:35
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@tkc49
tkc49 / SassMeister-input-HTML.html
Last active September 10, 2015 01:41
Generated by SassMeister.com.
<ul class="postListBlock">
<li class="postListBlock_item">
<a href="#" class="postListBlock_item_link" title="">
<div class="postListBlock_item_link_thumbnail">
<img src="http://dummyimage.com/300x150/000/fff" alt="">
</div>
<div class="postListBlock_item_link_txt">
<time class="postListBlock_item_link_txt_time">2015/09/09</time>
<div class="postListBlock_item_link_txt_category">カテゴリー</div>
<h2 class="postListBlock_item_link_txt_title">タイトル</h2>
@tkc49
tkc49 / gist:5074987
Last active December 14, 2015 10:48
[WordPress] Display a list of articles for each author. /著作者ごとに記事を一覧表示
<?php $users = get_users(); ?>
<ul>
<?php foreach($users as $user): ?>
<li><?php echo $user->display_name; ?></li>
<ul>
<?php $posts = get_posts("author=$user->ID&orderby=date&post_type=post&posts_per_page=5"); ?>
<?php foreach( $posts as $post ) : setup_postdata($post); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
@tkc49
tkc49 / gist:5074833
Last active December 14, 2015 10:49
[WordPress] single.php List of other articles of the author who wrote the article
<h2>一覧</h2>
<ul>
<?php $author_id = get_the_author_meta( 'ID' ); ?>
<?php $posts = get_posts("author=$author_id&orderby=date&post_type=post&posts_per_page=5"); ?>
<?php foreach( $posts as $post ) : setup_postdata($post); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
</ul>
@tkc49
tkc49 / gist:5229399
Last active December 15, 2015 08:18
[WordPress] Change edior-style. front-page,page /editor-styleのcssをフロントページと各固定ページごとに切り替える
if(is_admin() && isset( $_GET['post'] )){
if($_GET['post']==get_option( 'page_on_front' )){
if ( locate_template( array( 'editor-style-front.css' ) ) ) {
add_editor_style('editor-style-front.css');
}else{
add_editor_style();
}
}else{
if ( locate_template( array( sprintf('editor-style-%s.css' , get_page($_GET['post'])->post_name ) ) ) ) {
add_editor_style(sprintf('editor-style-%s.css' , get_page($_GET['post'])->post_name ));
@tkc49
tkc49 / gist:5596616
Last active December 17, 2015 10:39
カスタム投稿タイプのシングルページが表示された時に任意のカスタムメニューにcurrent-menu-itemのクラスを追加する処理
<?php
function add_nav_menu_custom_class( $menu_items ) {
$lists = array(
'post_type1' => 'page_slug1',
'post_type2' => 'page_slug2',
'post_type3' => 'page_slug3',
'post_type4' => 'page_slug4',
'post_type5' => 'page_slug5',
'post_type6' => 'page_slug6',