Skip to content

Instantly share code, notes, and snippets.

@mypacecreator
mypacecreator / table.php
Last active December 21, 2015 06:18
get_postsで投稿を取得してtableで出力し、奇数列偶数列にclassをつけてCSSでしましまにできるように
<table>
<tr>
<th>日付</th>
<th>タイトル</th>
</tr>
<?php
$postcount = 1; //奇数偶数をカウント
$news = get_posts( array(
'post_type' => 'type',
'posts_per_page' => -1,
@mypacecreator
mypacecreator / functions.php
Last active December 21, 2015 06:18
特権管理者じゃなくてもdlとかのclassを消されたり、WordPress Importerで投稿をインポートした時記事内にiframeとかobjectとかあっても消されたりしないようにする
<?php
//HTMLの自動整形を解除
function set_allowedposttags($content){
global $allowedposttags;
$allowedposttags['dl'] = array(
'class' => array(),
'id' => array()
);
$allowedposttags['dt'] = array(
'class' => array(),
@mypacecreator
mypacecreator / front-page.php
Last active December 21, 2015 06:19
get_postsほぼ全部入り
<dl>
<?php
$news = get_posts( array(
'posts_per_page' => 20,
'order' => 'ASC', //ASC/*DESC
'orderby' => 'ID', //ID/author/title/date/modified/parent/rand/comment_count/menu_order/meta_value/meta_value_num
'category_name' => 'slug',
'tag' => 'slug'
'post_type' => 'slug',
'taxonomy' => 'slug',
@mypacecreator
mypacecreator / gist:6263118
Created August 18, 2013 18:16
メールフォームの都道府県選ぶアレ
<select name="pref">
<option value="">お選びください</option>
<optgroup label="北海道・東北">
<option value="北海道">北海道</option>
<option value="青森県">青森県</option>
<option value="岩手県">岩手県</option>
<option value="宮城県">宮城県</option>
<option value="秋田県">秋田県</option>
<option value="山形県">山形県</option>
<option value="福島県">福島県</option>
@mypacecreator
mypacecreator / page-faq.php
Last active December 21, 2015 06:19
get_termsとget_postsの入れ子例
<?php
$taxonomies = get_terms(
'faqcategory',array(
'orderby' => 'slug',
'order' => 'ASC'
));
foreach($taxonomies as $taxonomy) :
?>
<div class="parentBox">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
@mypacecreator
mypacecreator / functions.php
Last active December 22, 2015 03:48
カスタム投稿タイプ+カスタムタクソノミー作成でよく使うやつ
<?php
//カスタム投稿タイプ作成
function mypace_custom_post_type() {
register_post_type( 'voice', array(
'label' => 'お客様の声',
'public' => true,
'exclude_from_search' => false,
'hierarchical' => false,
'menu_position' => 5,
'has_archive' => true,
@mypacecreator
mypacecreator / ameblo-feed.php
Last active May 24, 2016 05:23
アメブロRSSから[PR]を外してfetch_feedするやーつ
<?php
//以下3行の項目を任意に変更
$display_posts_count = 5; //実際に表示したい記事件数
$get_posts_count = 10; //取得する記事件数(PR記事を含むので$display_posts_countより少し多めに設定)
$feed = fetch_feed('http://feedblog.ameba.jp/rss/ameblo/**blogname**/rss20.xml'); //取得したいRSS
//
$counter = 0; //ループ回数カウンター
include_once(ABSPATH . WPINC . '/feed.php');
if (!is_wp_error( $feed ) ) : //エラーがなければ
@mypacecreator
mypacecreator / single.php
Last active December 28, 2015 11:58
アイキャッチ画像をポップアップに
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php
$popupimg_id = get_post_thumbnail_id();
$popupimg_url = wp_get_attachment_image_src($popupimg_id,'full', true);
echo esc_url($popupimg_url[0]);
?>"><?php the_post_thumbnail(); ?></a>
<?php endif; ?>
@mypacecreator
mypacecreator / single.php
Last active December 28, 2015 11:58
single.phpで、カテゴリースラッグを元にタイトル画像を表示する(子カテゴリーの場合も、親カテゴリーの画像を使う)
<?php
$cat = get_the_category();
if ($cat[0]->category_parent): //子カテゴリの場合
$parent_cat = get_category($cat[0]->category_parent);
?>
<p class="title"><img src="<?php echo get_template_directory_uri(); ?>/images/title_<?php echo $parent_cat->slug; ?>.jpg" alt="<?php echo $parent_cat->name; ?>" /></p>
<p class="subtitle"><?php echo $cat[0]->cat_name; ?></p>
<?php else: //親カテゴリの場合 ?>
<p class="title"><img src="<?php echo get_template_directory_uri(); ?>/images/title_<?php echo $cat[0]->category_nicename; ?>.jpg" alt="<?php echo $cat[0]->cat_name; ?>" /></p>
<?php endif; ?>
@mypacecreator
mypacecreator / archive.php
Last active December 28, 2015 11:58
アーカイプページで、カテゴリースラッグを元にタイトル画像を表示する(子カテゴリーの場合も、親カテゴリーの画像を使う)
<?php if(is_category()): ?>
<?php
$cat_id = get_query_var('cat');
$cat = get_category($cat_id);
$cat_parent_id = $cat->category_parent;
$cat_parent = get_category($cat_parent_id);
if( $cat_parent_id == 0 ): //親カテゴリの場合
$cat_parent = get_category($cat_parent_id);
?>
<p class="title"><img src="<?php echo get_template_directory_uri(); ?>/images/title_<?php echo $cat->category_nicename; ?>.jpg" alt="<?php single_cat_title(); ?>" /></p>