目次
子テーマのjsファイルを読み込む
子テーマのfunctions.phpにて親テーマのjs
→子テーマのjs
という順番で読み込み順を指定することで、ファイルとしては2つとも出力されるが、後から読み込んだ子テーマのjs
の方が適用されることで上書きできるようだ。
// 子テーマの function.php の theme_enqueue_styles() の下とかに追記
function theme_enqueue_scripts() {
//親テーマのsample.js
wp_enqueue_script(
'parent-func', // ハンドル名。ここは親テーマに書いてあるハンドル名と揃える
get_template_directory_uri() . '/js/sample.js',
array(), // $deps, 依存関係。よく 'jquery' とかが入る
null // $ver か $in_footer のどちらかだけど、なぜfalseじゃなくてnullなのかは不明
);
//子テーマのsample.js
wp_enqueue_script(
'child-func', // 親テーマの
get_stylesheet_directory_uri() . '/js/sample.js',
array( 'parent-func' ), // ここで親テーマのjsに依存関係を持たせるらしい
null
);
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_scripts' );
ただ親テーマで読み込んでいるファイル群すべてを子テーマ側でも呼ばないと不具合が起きるらしい‥。いつもダイナシイエスタデイさんの記事に辿り着くが、この記事とこの記事の2つがあるので注意。また記事の上部にあるコードをパットコピペしたりせず、ちゃんと文章読みましょう。
<?php wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); ?>
https://wpdocs.osdn.jp/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/wp_enqueue_script
カスタム投稿タイプの出力
ターム毎の一覧ページを作る
<?php
$taxonomy_name = 'spend_cat';
$post_type = 'spend';
$args = array(
'order' => 'ASC',
);
$taxonomys = get_terms( $taxonomy_name, $args);
if ( !is_wp_error($taxonomys) && count($taxonomys) ) {
foreach($taxonomys as $taxonomy):
$tax_posts = get_posts( array(
'post_type' => $post_type,
'posts_per_page' => 10, // 表示させたい記事数
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => $taxonomy_name,
'terms' => array( $taxonomy->slug ),
'field' => 'slug',
'include_children' => true, //子タクソノミーを含める
)
)
));
if ($tax_posts) { ?>
<h2 id="<?php echo $taxonomy->term_taxonomy_id; ?>"><?php echo esc_html($taxonomy->name); ?></h2>
<ul>
<?php foreach($tax_posts as $tax_post): ?>
<li>
<a href="<?php echo get_permalink($tax_post->ID); ?>">
<h3><?php echo get_the_title($tax_post->ID); ?></h3>
// アイキャッチ画像を出力したい場合(has_post_thumbnailとthe_post_thumbnailは使えない)
<?php if ( get_the_post_thumbnail($tax_post->ID) ): ?>
<?php echo get_the_post_thumbnail( $tax_post->ID ); ?>
<?php else : ?>
<img src="<?php bloginfo('template_url'); ?>/images/no_image.gif" />
<?php endif ; ?>
// カスタムフィールド値を出力したい場合
<?php if (get_field('sub_title', $tax_post->ID)) { ?>
<h4><?php the_field('sub_title', $tax_post->ID); ?></h4>
<?php } ?>
</a>
</li>
<?php endforeach;
wp_reset_postdata(); ?>
</ul>
<?php }
endforeach; ?>
<?php } else { ?>
<p>投稿はありません。</p>
<?php } ?>
ACFの出力
テキスト
<?php if (get_field('text_field_name')) {
echo the_field('text_field_name');
} ?>
Case: Needed post id
通常のループの中ではない場所で出力したい場合は投稿IDが必要
get_field($selector, [$post_id], [$format_value]);
$selector
(string) (Required) The field name or field key.
$post_id
(mixed) (Optional) The post ID where the value is saved. Defaults to the current post.
$format_value
(bool) (Optional) Whether to apply formatting logic. Defaults to true.
画像
返り値のフォーマット:画像ID
<?php
$img = get_field('image_field_name');
$img_urls = wp_get_attachment_image_src($img, 'full');
if ($img_urls) { ?>
<img src="<?php echo $img_urls[0]; ?>" alt="">
<?php }
?>
ただしレスポンシブ画像としての出力はしてくれない。
(thumbnail, medium, large, full)または2つのアイテムを持つ配列が幅と高さをピクセルで、array(32,32)という形で表します
https://wpdocs.osdn.jp/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/wp_get_attachment_image_src#.E3.83.91.E3.83.A9.E3.83.A1.E3.83.BC.E3.82.BF
array指定が効いてくれなかったのは、元のアスペクト比と違う比率を指定したからか?
MW WP Form プラグインのデザイン


MW WP Form に記述するもの
// フォームHTML
<ol class="form_step">
<li>入力</li>
<li>内容確認</li>
<li>完了</li>
</ol>
<table class="mailform-tbl">
<tbody>
<tr>
<th>お名前 <span class="attention">※</span></th>
<td class="w50">[mwform_text name="name"]</td>
</tr>
<tr>
<th>フリガナ<span class="attention">※</span></th>
<td class="w50">[mwform_text name="kana"]</td>
</tr>
<tr>
<th>電話番号</th>
<td class="w50">[mwform_text name="tel"]</td>
</tr>
<tr>
<th>メールアドレス <span class="attention">※</span></th>
<td class="w50">[mwform_text name="mail"]</td>
</tr>
<tr>
<th>お問い合わせ内容 <span class="attention">※</span></th>
<td class="w80">[mwform_textarea name="message" placeholder="ご質問・ご相談など、お気軽にお問合わせください"]</td>
</tr>
</tbody>
</table>
<p id="submit-button">[mwform_backButton value="戻る"][mwform_submitButton preview_value="確認画面へ" submit_value="送信する"]</p>
// 完了画面HTML
<ol class="form_step">
<li>入力</li>
<li>内容確認</li>
<li>完了</li>
</ol>
<div>
<p>お問い合わせありがとうございます。ご入力いただいたメールアドレスに自動返信メールをお送り致しました。</p>
<p>メールが届かない場合や、2〜3日経っても連絡がない場合は、お手数ですがお電話(00-0000-0000)までご連絡をお願いいたします。</p>
<a class="btn home" href="/">TOPページに戻る</a>
CSS
CSSはやはりstyle.cssなどにコードで記述し管理するのがおすすめ。固定ページ側に WP Add Custom CSS プラグインなどでカスタムCSSを追加できるようにしていたが、リビジョンの復元の際に反映されないため不便。記述場所も1つに統一できる。
.mw_wp_form {
width: 100%;
color: #333;
}
.mw_wp_form table.mailform-tbl {
width: 100%;
margin-bottom: 40px;
}
.mw_wp_form table tr {
width: 100%;
border-bottom: 1px dotted #ccc;
padding: 30px 0;
font-weight: normal;
}
.mw_wp_form table tr:first-child {
border-top: 1px dotted #ccc;
}
.mw_wp_form table th {
padding: 20px 0;
text-align: left;
vertical-align: top;
font-weight: normal;
width: 30%;
float: left;
}
.mw_wp_form table th .attention {
font-size: 80%;
margin-left: 10px;
color: red;
padding: 3px;
}
.mw_wp_form table td {
padding: 20px 0;
width: 70%;
float: left;
}
.mw_wp_form table td.w50 input, .mw_wp_form table td.w50 select {
width: 50%;
box-sizing: border-box;
}
.mw_wp_form table td.w80 input, .mw_wp_form table td.w80 select {
width: 80%;
box-sizing: border-box;
}
.mw_wp_form table td.w80 textarea {
width: 80%;
box-sizing: border-box;
}
.mw_wp_form #submit-button {
text-align: center;
}
.mw_wp_form #submit-button input {
margin: 1em;
display: inline-block;
padding: 10px 30px;
border: 1px solid #c19e56;
background: #c19e56;
color: #fff;
box-sizing: border-box;
height: 40px;
-webkit-appearance: none;
border-radius: 5px;
font-size: 90%;
}
.mw_wp_form #submit-button input[name="submitBack"] {
margin: 1em;
display: inline-block;
padding: 10px 30px;
border: 1px solid #999;
background: #999;
color: white;
box-sizing: border-box;
height: 40px;
-webkit-appearance: none;
border-radius: 5px;
font-size: 90%;
}
.mw_wp_form .form_step {
display: flex;
justify-content: center;
align-items: center;
margin: 0 0 20px 0;
list-style: none;
}
.mw_wp_form .form_step>li {
display: block;
position: relative;
padding: 0.5em;
width: 22%;
border: 1px solid currentColor;
color: #C19E56;
font-size: 16px;
font-weight: bold;
text-align: center;
margin: 0;
}
.mw_wp_form .form_step>li:nth-of-type(n + 2) {
margin: 0px 0px 0px 4%;
}
.mw_wp_form .form_step>li:nth-of-type(n + 2):before {
position: absolute;
top: 50%;
left: -1.5em;
width: 0.5em;
height: 0.5em;
border-top: 2px solid #C19E56;
border-left: 2px solid #C19E56;
transform: translateY(-50%) rotate(135deg);
content: "";
}
.mw_wp_form_input .form_step>li:nth-of-type(1), .mw_wp_form_preview .form_step>li:nth-of-type(2), .mw_wp_form_complete .form_step>li:nth-of-type(3) {
background-color: #C19E56;
color: #fff;
}
@media screen and (max-width: 768px) {
.mw_wp_form .form_step>li {
font-size: 10px;
width: 30%;
}
.mw_wp_form table td {
width: 65%;
float: right;
}
.mw_wp_form table td.w50 input, .mw_wp_form table td.w50 select {
width: 100%;
box-sizing: border-box;
}
.mw_wp_form table td.w80 input, .mw_wp_form table td.w80 select {
width: 100%;
box-sizing: border-box;
}
.mw_wp_form table td.w80 textarea {
width: 100%;
box-sizing: border-box;
}
}
自動返信メール本文
// 自動返信メール本文
{name} 様
以下の内容でお問い合わせを受け付けました。内容を確認させていただき次第、ご返信させていただきます。
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
【お名前】
{name}({kana})様
【電話番号】
{tel}
【メールアドレス】
{mail}
【お問い合わせ内容】
{message}
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ご質問内容によっては、お返事にお時間がかかる場合や、お返事できない場合もございますので、何卒ご了承ください。
------------------------------------------------------------
株式会社サンプル商事
TEL: 03-0000-0000
info@sample.com
https://sample.com/
------------------------------------------------------------
管理者宛メール本文
// 管理者宛メール本文
以下の内容でお問い合わせがありました。
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
【お名前】
{name}({kana})様
【電話番号】
{tel}
【メールアドレス】
{mail}
【お問い合わせ内容】
{message}
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
※本メールはお問合せがあった際の自動配信メールです。
ご対応よろしくお願いいたします。
https://lifestylecreators.net/3242/#MW_WP_FORM_CSS
https://migi.me/wordpress/mw-wp-form-style-responsive/