PHP code example of dh_man / dhead-wp
1. Go to this page and download the library: Download dh_man/dhead-wp library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dh_man / dhead-wp example snippets
use DHead_WP\DH_CPT_Builder;
DH_CPT_Builder::make('news')
->args([
'label' => 'お知らせ',
'public' => true,
'supports' => ['title', 'editor', 'thumbnail'],
])
->fields([
[
'name' => 'subtitle',
'label' => 'サブタイトル',
'type' => 'text',
],
[
'name' => 'publish_date',
'label' => '公開日',
'type' => 'date_picker',
],
], 'お知らせ情報');
use DHead_WP\DH_Options_Page_Builder;
DH_Options_Page_Builder::make('サイト設定')
->menu_title('サイト設定')
->fields([
[
'name' => 'site_logo',
'label' => 'ロゴ画像',
'type' => 'image',
],
[
'name' => 'contact_email',
'label' => 'お問い合わせメール',
'type' => 'email',
],
]);
use DHead_WP\DH_Block_Builder;
DH_Block_Builder::make('hero')
->title('Hero Block')
->description('ヒーローセクションのブロック')
->icon('cover')
->category('layout')
->fields([
[
'name' => 'title',
'label' => 'タイトル',
'type' => 'text',
],
[
'name' => 'image',
'label' => '画像',
'type' => 'image',
],
])
->render_blade('blocks.hero');
blade
{{-- resources/views/blocks/hero.blade.php --}}
<section class="hero">
<h1>{{ get_field('title') }}</h1>
@php $image = get_field('image'); @endphp
@if(!empty($image))
<img src="{{ $image['url'] }}" alt="{{ $image['alt'] }}">
@endif
{{-- ACFリピーター例 --}}
@if(have_rows('items'))
<ul>
@while(have_rows('items'))
@php the_row(); @endphp
<li>{{ get_sub_field('title') }}</li>
@endwhile
</ul>
@endif
</section>