アンカーリンク移動時の位置調整

Filed under: JavaScript — kdcs @ 2020年11月2日 月曜日
<script>
jQuery(function(){
    var windowWidth = $(window).width();
    var headerHight = 100; 
    jQuery('a[href^=#]').click(function() {
    var speed = 1000;
    var href= jQuery(this).attr("href");
    var target = jQuery(href == "#" || href == "" ? 'html' : href);
    var position = target.offset().top-headerHight;
    jQuery('body,html').animate({scrollTop:position}, speed, 'swing');
    return false;
   });
});
</script>

var headerHight = 上位置からの高さ
var speed = 移動スピード

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

Filed under: wordpressプラグイン — kdcs @ 2020年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 @ 2020年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-->

(続きを読む…)

カスタムフィールドを利用したカスタム投稿タイプのタームでの絞り込み

Filed under: php,wordpress — kdcs @ 2020年9月20日 日曜日

Advanced Custom Fieldsのカスタムフィールドを利用してカスタム投稿タイプのタームで記事を絞り込む例
tax_queryのrelationをANDにしてブランドとタイプで絞り込み、WP_Queryでループさせる

カスタム投稿タイプ:items
カスタム投稿タイプのタクソノミー:items_category
カスタムフィールド:00brand , item_type , 02item-image1(メイン画像)

<h3>関連商品</h3>
<div id="recommend">
<?php
  $brand = get_field('00brand');
  $type = get_field('item_type');
    $args = array(
  'post_type' => 'items', //カスタム投稿タイプ名
	'tax_query' => array(
        'relation' => 'AND',
		array(
			'taxonomy' => 'items_category',
			'field'    => 'slug',
			'terms'    => $brand,
		),
		array(
			'taxonomy' => 'items_category',
			'field'    => 'slug',
			'terms'    => $type,
		),
	),
  'numberposts' => 12, //12件表示(デフォルトは5件)
  'orderby' => 'abc', //ランダム表示 rand
  'post__not_in' => array($post->ID) //表示中の記事を除外
 );
?>
<p><?php echo $type; ?></p>
<div class="item">
<div class="itemList inner clearfix">
<?php $recommend = new WP_Query( $args ); ?>
<?php if($recommend -> have_posts()): while($recommend -> have_posts()): $recommend -> the_post(); ?>
<?php
    $attachment_id1 = get_field('02item-image1');
    $size1 = "thumbnail"; // (thumbnail, medium, large, full or custom size)
    $image1 = wp_get_attachment_image_src( $attachment_id1, $size1 );
    $attachment_id1f = get_field('02item-image1');
    $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;
?>
<div class="itemBox4"><a href="<?php the_permalink(); ?>"><img src="<?php echo $image1f[0]; ?>" alt="<?php echo $alt1; ?>" title="<?php echo $image_title1; ?>"><h4><?php echo nl2br(post_custom('01model')); ?></h4><p><?php echo nl2br(post_custom('03price')); ?></p></a></div>
<?php endwhile; ?>
</div><!--/itemList-->
</div><!--/item-->
<?php else : ?>
 <p>関連アイテムはまだありません。</p>
</div><!--/itemList-->
</div><!--/item-->
<?php endif; wp_reset_postdata(); ?>
</div><!--/#recommend-->

WordPress Popular Postsでwelcartの商品メイン画像を使えるようにする

Filed under: functions.php,welcart — kdcs @ 2020年9月14日 月曜日

アイキャッチ画像を呼び出す部分をwelcart商品メイン画像に差し替える

//商品画像を取得してPopular postのアイキャッチ画像にする
function my_custom_single_popular_post( $post_html, $p, $instance ){
	global $usces;
	$post_id = $p->id;
	$code =  get_post_meta($post_id, '_itemCode', true);
	$pictid = (int)$usces->get_mainpictid($code);
	$image_src = wp_get_attachment_image_src($pictid);
	$output = '<li class="wpp_list_item cf"><a href="' . get_the_permalink($p->id) . '" class="my-custom-title-class"><img src="' .$image_src[0]. '"/>' . esc_html( $p->title ) . '</a></li>' ;  
	return $output;
}
add_filter( 'wpp_post', 'my_custom_single_popular_post', 10, 3 );

サイト内検索

カテゴリー

最近の投稿

↑上に戻る