Advanced Custom FieldsのフィールドタイプにTableを追加するプラグイン

Filed under: wordpressプラグイン — kdcs @ 22年4月6日 水曜日

Advanced Custom FieldsのフィールドタイプにTableを追加するプラグイン「Advanced Custom Fields: Table Field」

出力例

<?php $table = get_field( 'your_table_field_name' );
if ( ! empty ( $table ) ) {
echo '<table border="0">';
  if ( ! empty( $table['caption'] ) ) {
  echo '<caption>' . $table['caption'] . '</caption>';
  }
  if ( ! empty( $table['header'] ) ) {
  echo '<thead>';
    echo '<tr>';
      foreach ( $table['header'] as $th ) {
      echo '<th>';
        echo $th['c'];
        echo '</th>';
      }
      echo '</tr>';
    echo '</thead>';
  }
  echo '<tbody>';
    foreach ( $table['body'] as $tr ) {
    echo '<tr>';
      foreach ( $tr as $td ) {
      echo '<td>';
        echo $td['c'];
        echo '</td>';
      }
      echo '</tr>';
    }
    echo '</tbody>';
  echo '</table>';
}
?>

カスタムフィールドのデータを削除できるプラグイン「Delete Custom Fields」

Filed under: wordpressプラグイン — kdcs @ 20年10月3日 土曜日

このプラグインでWordPressのカスタムフィールド(Advanced Custom Fields)データーを任意のフィールドを選択して削除することができる。
カスタムフィールド自体の削除はこのプラグインではなく、Advanced Custom Fields側で削除を行う必要がある。

ローカル環境でテスト
xamppカスタム Apache2.4.43、MySQL5.6.20、PHP7.4.4
WordPressのバージョンは5.4
Delete Custom Fieldsのバージョンは0.3.1
ダウンロードはここから

※このプラグインの最終更新日は9年前
このプラグインの公開は2024年4月12日に停止されており、現在はダウンロードできません。

WordPress Popular postsのカスタマイズ

Filed under: functions.php,wordpressプラグイン — kdcs @ 20年9月26日 土曜日

ランキングプラグイン「WordPress Popular posts」の出力にカスタムフィールド(Advanced Custom Fields)の値や画像を含めたい。

function.phpの記述

/* ---------------------------------------------------------------------------------------
   ◆◆◆ WordPress Popular posts カスタマイズ ###########################################
------------------------------------------------------------------------------------------*/
function my_custom_single_popular_post( $post_html, $p, $instance ){
    $attachment_id =  get_field('02item-image1',$p->id);//カスタムフィールド画像取得
    $size = "img320"; //画像サイズ (thumbnail, medium, large, full or custom size) img320はカスタムサイズ
    $image = wp_get_attachment_image_src( $attachment_id, $size );
$acf1 = get_post_meta($p->id, 'field_name', true);//カスタムフィールドその1
$acf2 = get_post_meta($p->id, 'field_name', true);//カスタムフィールドその2
$custom_id= $p->id;//id番号出力
$output = '
<li><a href="' . get_the_permalink($p->id) . '"><img src="'. $image[0] .'" alt=""/><br />
' . esc_attr($p->title) . '<br />'. $acf1 .'</a>
</li>
';
return $output;
}
add_filter( 'wpp_post', 'my_custom_single_popular_post', 10, 3 );

ランキング表示
例:カスタム投稿タイプ items カスタムタクソノミー items_category タームid 28

<div id="rankingS" class="inner clearfix">
<?php
    if (function_exists('wpp_get_mostpopular')){
      $arg = array (
        'range' => 'all',//集計期間
        'order_by' => 'views',
        'stats_views' => '0',
        'post_type' => 'items',//投稿タイプ
         'taxonomy' => 'items_category',//カスタムタクソノミー
         'term_id' => ' 28',タームid
        'limit' => 4,//表示件数
        'wpp_start' => '<ul class="ranking">',//開始タグ
        'wpp_end' => '</ul>',//終了タグ
      );
      wpp_get_mostpopular($arg);
    }
    ?>
</div><!--/rankingS-->

(続きを読む…)

WordPress「Favorites」のお気に入り一覧でACFの画像を出力する

Filed under: php,wordpressプラグイン — kdcs @ 20年8月12日 水曜日

WordPress お気に入りプラグイン「Favorites」のお気に入り一覧ページに
ACF(アドバンスドカスタムフィールド)を出力させる

一覧ページにACFの画像を出力
カスタムフィールド名:02item-image1

<?php 

$favorites = get_user_favorites();

    if (isset($favorites) && !empty($favorites)) :
      foreach ($favorites as $post_id) :
$p = get_post($post_id);

    $attachment_id1f = get_field('02item-image1' , $post_id );
    $size1f = "large"; // (thumbnail, medium, large, full or custom size)
    $image1f = wp_get_attachment_image_src( $attachment_id1f, $size1f );
    $attachment = get_post( get_field('02item-image1') );
    $alt1 = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
    $image_title1 = $attachment->post_title;

        echo '<div>' . get_the_title($post_id) . get_favorites_button($post_id) . '</div>';
        echo '<img src=' . $image1f[0] . '>';
      endforeach;
    else :
      // No Favorites
      echo '<p class="text-center">お気に入りがありません。</p>';
    endif; ?>

WordPress Popular Posts 特定のカテゴリー記事のランキング

Filed under: php,wordpressプラグイン — kdcs @ 20年2月24日 月曜日

カテゴリーページやアーカイブページ他、条件分岐で指定したカテゴリー内でそのカテゴリー記事のランキングを表示させる

<?php $cat = get_the_category(); ?>
<?php $cat_id = isset( $cat[0] ) ? $cat[0]->term_id : ''; ?>
<?php if ( function_exists( 'wpp_get_mostpopular' ) ) : ?>
<?php $args = array( 
  'limit' => 12,
  'range' => 'all',
  'order_by' => 'views',
  'thumbnail_width' => 100,
  'thumbnail_height' => 100,
  'cat' => $cat_id,
  'wpp_start' => '<ul>',
  'wpp_end' => '</ul>',
  'stats_views' => 1,
  'post_html' => '<li><a href="{url}">{thumb}</a><a href="{url}">{text_title}</a><span>{stats}</span></li>' ); ?>
<?php wpp_get_mostpopular( $args ); ?>
<?php endif; ?>

サイト内検索

カテゴリー

最近の投稿

↑上に戻る