WordPress アップロード画像自動生成カスタマイズ

Filed under: functions.php,wordpress — kdcs @ 21年8月3日 火曜日

画像サイズを追加する「add_image_size()」関数を使用

add_image_size ( $name, $width, $height, $crop );

$name = 画像サイズ名
$width = 横幅(px)
$height = 縦幅(px)
$crop = トリミング(する=true しない=false)

トリミング位置(基準点)を指定する場合
array( ‘center’, ‘top’ ) 中央上部
array( ‘center’, ‘bottom’ ) 中央下部
array( ‘left’, ‘top’ ) 左上部
など・・・

WordPress アップロード画像自動生成の停止

Filed under: functions.php,wordpress — kdcs @ 21年8月3日 火曜日

使用しないサイズの画像自動生成を停止させる。
function.php

function my_intermediate_image_sizes($sizes) {
	$delete = array('thumbnail','medium',’large’);
	return array_diff($sizes, $delete);
}
add_filter('intermediate_image_sizes', 'my_intermediate_image_sizes');

サムネイル:thumbnail
中サイズ:medium
大サイズ:large

welcart導入時のユーザー権限カスタマイズ

Filed under: functions.php,welcart — kdcs @ 21年7月17日 土曜日

welcartプラグインをインストールし、有効化すると権限グループに「編集者(設定権限無し)」と「編集者(マネジメント権限無し)」の二つが追加される。

メインメニュー サブメニュー 編集者(設定権限無し) 編集者(マネジメント権限無し)
Welcart のユーザー権限
Welcart Shop ホーム ○(権限あり) ○(権限あり)
商品マスター ○(権限あり) ○(権限あり)
新規商品追加 ○(権限あり) ○(権限あり)
基本設定 ×(権限無し) ×(権限無し)
営業日設定 ×(権限無し) ×(権限無し)
配送設定 ×(権限無し) ×(権限無し)
メール設定 ×(権限無し) ×(権限無し)
カートページ設定 ×(権限無し) ×(権限無し)
会員ページ設定 ×(権限無し) ×(権限無し)
システム設定 ×(権限無し) ×(権限無し)
クレジット決済設定 ×(権限無し) ×(権限無し)
Welcart Management 受注リスト ○(権限あり) ×(権限無し)
新規受注見積登録 ○(権限あり) ×(権限無し)
会員リスト ○(権限あり) ×(権限無し)
新規会員登録 ○(権限あり) ×(権限無し)

「マネジメント権限無し」だと商品管理しかできず、「設定権限無し」だと商品と顧客の管理しかできない。
各種設定が操作できないユーザーになってしまう。

WordPressの権限グループにある「編集者」を選択するとwelcartのすべての設定が操作できるようになるが、ユーザーに触ってほしくない項目もある。(システム設定やクレジット決済設定など)

そこで、触ってほしくないメニューを非表示にする方法
以下をfunction.php内に記述し、表示したいメニューをコメントアウトする。

    function remove_menus () {
      if (!current_user_can('administrator')) { // 管理者権限以外
        global $menu;
        remove_submenu_page('usc-e-shop/usc-e-shop.php', 'usces_initial'); // 基本設定
        remove_submenu_page('usc-e-shop/usc-e-shop.php', 'usces_schedule'); // 営業日設定
        remove_submenu_page('usc-e-shop/usc-e-shop.php', 'usces_delivery'); // 配送設定
        remove_submenu_page('usc-e-shop/usc-e-shop.php', 'usces_mail'); // メール設定
        remove_submenu_page('usc-e-shop/usc-e-shop.php', 'usces_cart'); // カートページ設定
        remove_submenu_page('usc-e-shop/usc-e-shop.php', 'usces_member'); // 会員ページ設定
        remove_submenu_page('usc-e-shop/usc-e-shop.php', 'usces_system'); // システム設定
        remove_submenu_page('usc-e-shop/usc-e-shop.php', 'usces_settlement'); // クレジット決済設定

        remove_submenu_page('usces_orderlist', 'usces_memberlist'); // 会員リスト
        remove_submenu_page('usces_orderlist', 'usces_membernew'); // 新規会員登録
      }
    }
add_action('admin_menu', 'remove_menus');

マネジメント権限をすべて非表示にする場合はこちら

remove_menu_page('usces_orderlist'); // Welcart Management

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 Popular Postsでwelcartの商品メイン画像を使えるようにする

Filed under: functions.php,welcart — kdcs @ 20年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 );

サイト内検索

カテゴリー

最近の投稿

↑上に戻る