クロピグログ

職業訓練で学んだことまとめ

【WordPress授業十日目】ブロックエディタ、おすすめプラグイン

ブロックエディタ

WordPress:「テキスト」カテゴリブロック確認 | JOBTECH.JP

WordPress:「メディア」カテゴリブロック確認 | JOBTECH.JP

WordPress:「デザイン」カテゴリブロック確認 | JOBTECH.JP

 

 

おすすめプラグイン

カスタムフィールド作成

p05:カスタムフィールド作成「Advanced Custom Fields」 | JOBTECH.JP

 

●変数に代入してそれを入れていくやり方

<?php /***** メインループ開始 *****/ ?>
<?php if (have_posts()) : ?>
  <?php while (have_posts()) : the_post(); ?>
    <?php
    // get_field関数
    // カスタムフィールドの値を取得できる
    // 第1引数:カスタムフィールドの名前
    // 戻り値:カスタムフィールドの種類で異なる
    $top_service1_img = get_field('top_service1_img');
    $top_service1_title = get_field('top_service1_title');
    $top_service1_text = get_field('top_service1_text');
    $top_service1_slug = get_field('top_service1_slug');
    $top_service1_url = get_permalink($top_service1_slug);
 
 
    $top_service2_img = get_field('top_service2_img');
    $top_service2_title = get_field('top_service2_title');
    $top_service2_text = get_field('top_service2_text');
    $top_service2_slug = get_field('top_service2_slug');
    $top_service2_url = get_permalink($top_service2_slug);

    $top_service3_img = get_field('top_service3_img');
    $top_service3_title = get_field('top_service3_title');
    $top_service3_text = get_field('top_service3_text');
    $top_service3_slug = get_field('top_service3_slug');
    $top_service3_url = get_permalink($top_service3_slug);
    ?>
  <?php endwhile?>
<?php endif?>
<?php /***** メインループ終了 *****/ ?>
 
---------------------
 body内(下をx3)

<li class="Archive__item">
  <a class="Archive__link" href="<?php echo esc_url($top_service2_url); ?>">
    <figure class="Archive__thumbnail">
      <img class="Archive__img" src="<?php echo esc_url($top_service2_img); ?>" alt="制作タイトル">
    </figure>
    <h2 class="Archive__title"><?php echo esc_html($top_service2_title); ?></h2>
    <div class="Archive__text"><?php echo esc_html($top_service2_text); ?></div>
  </a>
</li>

 

 

●直接書いて、forでループさせるやり方

<?php for ($i = 1$i <= 3$i++) : ?>
  <?php
  $nam_url = "top_service" . $i . "_slug";
  $nam_img = "top_service" . $i . "_img";
  $nam_title = "top_service" . $i . "_title";
  $nam_text = "top_service" . $i . "_text";
  ?>
  <li class="Archive__item">
    <a class="Archive__link" href="<?php echo esc_url(get_permalink(get_field($nam_url))); ?>">
      <figure class="Archive__thumbnail">
        <img class="Archive__img" src="<?php echo esc_url(get_field($nam_img)); ?>" alt="制作タイトル">
      </figure>
      <h2 class="Archive__title"><?php echo esc_html(get_field($nam_title)); ?></h2>
      <div class="Archive__text"><?php echo esc_html(get_field($nam_text)); ?></div>
    </a>
  </li>
<?php endfor?>