Appearance
DailyArticleTemplate - 使用例
基本的な使用例
例1: 最小限のパラメータ
php
<?php
// 投稿テンプレート内で使用
$post_id = get_the_ID();
$date = get_post_meta($post_id, 'kousatsu_date', true);
$halls = get_post_meta($post_id, 'halls', true);
echo generate_daily_article_template($date, $halls);
?>メタキー(post_meta)の値の例:
kousatsu_date:2024-11-01halls:アイランド秋葉原
生成される出力:
<!-- wp:shortcode -->
[MonthlyLinkByYear year=2024]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[BirthDayMachinePickUp year=2024 month=11 day=1 halls="island"]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[MailImage hall="アイランド秋葉原" date="20241101"]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[MoveDayHall preday="20241031" nextday="20241102" name="アイランド秋葉原"]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[CustomCode_CreateDailyArticleRelationalDay date="2024-11-01" hall="アイランド秋葉原"]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[CustomCode_CreateDailyArticleResult hall="アイランド秋葉原" date="2024-11-01"]
<!-- /wp:shortcode -->例2: 複数ホール指定
php
<?php
$post_id = get_the_ID();
$date = get_post_meta($post_id, 'kousatsu_date', true);
$halls = get_post_meta($post_id, 'halls', true); // カンマ区切り文字列
echo generate_daily_article_template($date, $halls);
?>メタキー(post_meta)の値の例:
kousatsu_date:2024-11-01halls:アイランド秋葉原,エスパス秋葉原
生成される出力:
<!-- wp:shortcode -->
[MonthlyLinkByYear year=2024]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[BirthDayMachinePickUp year=2024 month=11 day=1 halls="island,espasu"]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[MailImage hall="アイランド秋葉原" date="20241101"]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[MoveDayHall preday="20241031" nextday="20241102" name="アイランド秋葉原"]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[CustomCode_CreateDailyArticleRelationalDay date="2024-11-01" hall="アイランド秋葉原"]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[CustomCode_CreateDailyArticleResult hall="アイランド秋葉原" date="2024-11-01"]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[MailImage hall="エスパス秋葉原" date="20241101"]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[MoveDayHall preday="20241031" nextday="20241102" name="エスパス秋葉原"]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[CustomCode_CreateDailyArticleRelationalDay date="2024-11-01" hall="エスパス秋葉原"]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[CustomCode_CreateDailyArticleResult hall="エスパス秋葉原" date="2024-11-01"]
<!-- /wp:shortcode -->例3: 手動入力部分を含む
php
<?php
$post_id = get_the_ID();
$date = get_post_meta($post_id, 'kousatsu_date', true);
$halls = get_post_meta($post_id, 'halls', true);
$manual_content = get_post_meta($post_id, 'manual_content', true);
echo generate_daily_article_template($date, $halls, $manual_content);
?>メタキー(post_meta)の値の例:
kousatsu_date:2024-11-01halls:アイランド秋葉原manual_content:<p>今日の考察内容</p>
生成される出力:
<!-- wp:shortcode -->
[MonthlyLinkByYear year=2024]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[BirthDayMachinePickUp year=2024 month=11 day=1 halls="island"]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[MailImage hall="アイランド秋葉原" date="20241101"]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[MoveDayHall preday="20241031" nextday="20241102" name="アイランド秋葉原"]
<!-- /wp:shortcode -->
<p>今日の考察内容</p>
<!-- wp:shortcode -->
[CustomCode_CreateDailyArticleRelationalDay date="2024-11-01" hall="アイランド秋葉原"]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[CustomCode_CreateDailyArticleResult hall="アイランド秋葉原" date="2024-11-01"]
<!-- /wp:shortcode -->例4: 機種名を含む
php
<?php
$post_id = get_the_ID();
$date = get_post_meta($post_id, 'kousatsu_date', true);
$halls = get_post_meta($post_id, 'halls', true);
$kishu = get_post_meta($post_id, 'kishu', true);
echo generate_daily_article_template($date, $halls, null, $kishu);
?>メタキー(post_meta)の値の例:
kousatsu_date:2024-11-01halls:アイランド秋葉原kishu:犬夜叉
生成される出力:
<!-- wp:shortcode -->
[MonthlyLinkByYear year=2024]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[BirthDayMachinePickUp year=2024 month=11 day=1 halls="island"]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[MailImage hall="アイランド秋葉原" date="20241101"]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[MoveDayHall preday="20241031" nextday="20241102" name="アイランド秋葉原"]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[CustomCode_CreateDailyArticleRelationalDay date="2024-11-1" hall="アイランド秋葉原"]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[CustomCode_CreateDailyArticleResult hall="アイランド秋葉原" date="2024-11-1"]
<!-- /wp:shortcode -->
<!-- wp:shortcode -->
[kishudata day="2024/11/1" hall="アイランド秋葉原" kishu="犬夜叉"]
<!-- /wp:shortcode -->例5: すべてのパラメータを含む
php
<?php
$post_id = get_the_ID();
$date = get_post_meta($post_id, 'kousatsu_date', true);
$halls = get_post_meta($post_id, 'halls', true);
$manual_content = get_post_meta($post_id, 'manual_content', true);
$kishu = get_post_meta($post_id, 'kishu', true);
echo generate_daily_article_template($date, $halls, $manual_content, $kishu);
?>メタキー(post_meta)の値の例:
kousatsu_date:2024-11-01halls:アイランド秋葉原,エスパス秋葉原manual_content:<p>今日の考察内容</p>kishu:犬夜叉
高度な使用例
例6: 配列形式のホール指定
php
<?php
$post_id = get_the_ID();
$date = get_post_meta($post_id, 'kousatsu_date', true);
$halls = get_post_meta($post_id, 'halls', true); // カンマ区切りまたは配列 ["アイランド秋葉原", "エスパス秋葉原"]
// 配列の場合は自動的にカンマ区切り文字列に変換されます
echo generate_daily_article_template($date, $halls);
?>例7: DateTimeオブジェクトを使用
php
<?php
$post_id = get_the_ID();
$date = new DateTime('2024-11-01'); // DateTimeオブジェクト
$halls = get_post_meta($post_id, 'halls', true);
echo generate_daily_article_template($date, $halls);
?>例8: 手動入力部分にショートコードを含む
php
<?php
$post_id = get_the_ID();
$date = get_post_meta($post_id, 'kousatsu_date', true);
$halls = get_post_meta($post_id, 'halls', true);
$manual_content = get_post_meta($post_id, 'manual_content', true);
// 例: "<p>手動入力部分</p><!-- wp:shortcode -->[SomeOtherShortcode param=\"value\"]<!-- /wp:shortcode -->"
echo generate_daily_article_template($date, $halls, $manual_content);
?>注意: 手動入力部分に含まれるショートコードは、do_shortcode()で実行されます。
例9: WordPressブロック形式を含む
php
<?php
$post_id = get_the_ID();
$date = get_post_meta($post_id, 'kousatsu_date', true);
$halls = get_post_meta($post_id, 'halls', true);
$manual_content = get_post_meta($post_id, 'manual_content', true);
// 例: "<!-- wp:paragraph --><p>手動入力部分</p><!-- /wp:paragraph -->"
echo generate_daily_article_template($date, $halls, $manual_content);
?>実装例: 完全な投稿テンプレート
php
<?php
/**
* Template Name: 日別考察記事
* Template Post Type: kousatsu
*/
get_header();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header>
<div class="entry-content">
<?php
$post_id = get_the_ID();
// post_meta から値を取得
$date = get_post_meta($post_id, 'kousatsu_date', true);
$halls = get_post_meta($post_id, 'halls', true);
$manual_content = get_post_meta($post_id, 'manual_content', true);
$kishu = get_post_meta($post_id, 'kishu', true);
// テンプレート関数を呼び出してショートコードを生成
if ( $date && $halls ) {
echo generate_daily_article_template($date, $halls, $manual_content, $kishu);
} else {
echo '<p>日付とホールを設定してください。</p>';
}
?>
</div>
</article>
<?php
get_footer();
?>参考資料
最終更新
- 更新日: 2025-11-28
- バージョン: 1.0