Skip to content

Instantly share code, notes, and snippets.

@senooat
senooat / WordPressのサイドバーにカテゴリー、最近の記事、月別アーカイブなどよくあるコンテンツを表示するテンプレートタグまとめ
Last active March 8, 2018 02:25
WordPressのサイドバーにカテゴリー、最近の記事、月別アーカイブなどよくあるコンテンツを表示するテンプレートタグまとめ
/*-----------------------------------
カテゴリー
-----------------------------------*/
<h2>カテゴリー</h2>
<ul>
<?php wp_list_categories( 'title_li=&show_count=1&hide_empty=0' ); ?>
</ul>
/*-----------------------------------
最近の記事(5件表示)
@senooat
senooat / 『Advanced Custom Fields』のアドオンThe Repeater Field(繰り返しフィールド) テンプレートサンプル
Last active February 12, 2018 05:55
『Advanced Custom Fields』のアドオンThe Repeater Field(繰り返しフィールド) テンプレートサンプル
<?php
/*
Template Name: スタッフ紹介
*/
?>
<?php get_header(); ?>
<main class="main">
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" class="pages">
@senooat
senooat / 『Advanced Custom Fields』各フィールドの出力用テンプレートサンプル
Last active January 23, 2018 02:26
『Advanced Custom Fields』各フィールドの出力用テンプレートサンプル
<?php
/*
Template Name: カスタムフィールド出力用
*/
?>
<?php get_header(); ?>
<style>
.mb50{
@senooat
senooat / 『Advanced Custom Fields』各フィールドの出力方法まとめ
Last active January 23, 2018 02:19
『Advanced Custom Fields』の各フィールドの出力方法について
/*-----------------------------------
フィールドタイプ:基本
-----------------------------------*/
/*テキスト-----------*/
<?php if( get_field('フィールド名') ): ?>
<?php the_field('フィールド名'); ?>
<?php endif; ?>
/*テキストエリア-----------*/
<?php if( get_field('フィールド名') ): ?>
@senooat
senooat / 『Advanced Custom Fields』の使い方 テンプレートサンプル
Last active February 12, 2018 05:55
Advanced Custom Fieldsを使ったテンプレートサンプル
<?php
/*
Template Name: 会社概要用
*/
?>
<?php get_header(); ?>
<main class="main">
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" class="pages">
@senooat
senooat / add_action「wp_enqueue_scripts」の使い方 その3
Created December 8, 2017 02:24
wp_head()やwp_footer()にCSSやJSを読み込む方法
function load_inline_script(){
if ( function_exists( 'wp_add_inline_script' ) ) {
$tag = "(function($){
//ここに処理を記述
})(jQuery);";
//この場合は「tempjs-script」下に読み込ませるという設定
wp_add_inline_script('tempjs-script', $tag, 'after');
}
@senooat
senooat / add_action「wp_enqueue_scripts」の使い方 その2
Last active January 10, 2018 00:38
wp_head()やwp_footer()にCSSやJSを読み込む方法
//サイトURLを定数に設定
define('SITEURL', home_url());
//jQueryを指定のものに変更(falseだとwp_head()に読み込む)
wp_deregister_script('jquery');
wp_enqueue_script('jquery', SITEURL.'/js/library/jquery.min.js',array(), '', false);
//JSの読み込み(trueだとwp_footer()に読み込む)
@senooat
senooat / add_action「wp_enqueue_scripts」の使い方 その1
Last active December 8, 2017 01:57
wp_head()やwp_footer()にCSSやJSを読み込む方法
<?php
/*-----------------------------------
wp_head(),wp_footer()にJS,CSSを読み込み
-----------------------------------*/
function add_files() {
if ( is_admin() ) return;
//ここに処理を記述
}
@senooat
senooat / WP_Queryの使い方 サンプル2-1
Last active November 28, 2017 01:00
例)カスタム投稿タイプ「blog」をサムネイル付きで5件表示
<?php
$args = array(
'post_type' => 'blog',
'posts_per_page' => '5'
);
$the_query = new WP_Query($args);
if($the_query->have_posts()):
echo '<ul>';
while ($the_query->have_posts()) : $the_query->the_post();
?>
@senooat
senooat / WP_Queryの使い方 サンプル1-2
Last active November 28, 2017 01:00
例)カテゴリー「news」をサムネイル付きで5件表示
<?php
$args = array(
'category_name' => 'news',
'posts_per_page' => '5'
);
$the_query = new WP_Query($args);
if($the_query->have_posts()):
echo '<ul>';
while ($the_query->have_posts()) : $the_query->the_post();
?>