/*---- !!!!危険!!!!! ----*/
/*---- もし修正する場合にはこのファイルのバックアップをとっておいて ----*/
/*---- 落ちたら差し替えてください ----*/
/*---- もし小林が消えたら次の会社に相談をしてください
株式会社カーネル(豊島区池袋) kk-kernel.co.jp
担当:田中社長、タルミ取締役に取り次いでもらってください
「(0< 全WPノウハウあげますからよろしくっす!by小林」 ----*/
//**************************************************//
// 管理画面関係
//**************************************************//
//----------------------------------------------
//クイック編集関係
//余計なものを消す
function remove_post_supports() {
remove_post_type_support( 'post', 'trackbacks' ); // トラックバック
//remove_post_type_support( 'post', 'comments' ); // コメント
remove_post_type_support( 'post', 'revisions' ); // リビジョン
}
add_action( 'init', 'remove_post_supports' );
//□現在の日時を出す
function display_my_custom_quickedit( $column_name, $post_type ) {
// 一度だけ表示
static $print_nonce = true;
if ($print_nonce) {
$print_nonce = false;
// CSRF対策
wp_nonce_field(wp_create_nonce(__FILE__), 'custom_fields_nonce');
//現在の日時のチェックを出す
$mytag = <<< EOF
EOF;
echo $mytag;
}
}
add_action( 'quick_edit_custom_box', 'display_my_custom_quickedit', 10, 2 );
//保存前の動作(完売だったら日付を2011/1/1にする)(更新予定管理)
function save_custom_meta( $post_id ) {
//ループ対策
if ( ! wp_is_post_revision( $post_id ) ) {
// この関数をフックから外し、無限ループを防ぐ。
remove_action( 'save_post', 'save_custom_meta' );
//クイック修正で□現在の日時が出ていたら日付を入れる
if ( isset( $_REQUEST['nowtimeinput'] ) ) {
date_default_timezone_set('Asia/Tokyo');
$nowdate = date("Y-m-d H:i:s");
$my_post = array(
'ID' => $post_id,
'post_date' => $nowdate
);
//postデータの更新
wp_update_post( $my_post );
}
//更新予定の自動入力
//更新情報の取得
$start = date("2000/01/01");
$end = date("2090/01/01");
$cnt = 0;
for($i = 1;$i <= 5;$i++){
$field_name = "追記日付" . mb_convert_kana($i,"A");
$in_date = date(get_post_meta($post_id, $field_name,true));
if($in_date != ""){
if($start < $in_date){
$start = $in_date;
}
if($in_date < $end){
$end = $in_date;
}
$cnt++;
}
}
if($cnt == 0){
$yotei = "";
}elseif($cnt == 1){
$yotei = $start . "(1件)";
}else{
$yotei = $start . "…" . $end . "(" . $cnt . "件)";
}
update_post_meta($post_id , "更新予約" , $yotei);
if(has_tag("完売",$post_id)){
$olddate = "2011/01/01 01:01:01";
//クリック日付の更新
update_post_meta($post_id , "クリック日付" , $olddate);
//更新日の更新
if(get_the_date("Y/m/d H:i:s", $post_id ) != $olddate){
$my_post = array(
'ID' => $post_id,
'post_date' => $olddate
);
wp_update_post($my_post);
}
}
}
// この関数を改めてフックする。
add_action( 'save_post', 'save_custom_meta' );
}
add_action( 'save_post', 'save_custom_meta' );
//----------------------------------------------
//管理画面:集計画面へのボタン
function analytics_title_head(){
global $wp_admin_bar;
$jspath = get_template_directory_uri(). "/3s_analytics.php";
$wp_admin_bar->add_menu(array(
'id' => 'new_item_in_admin_bar',
'title' => __(' 集計'),
'href' => $jspath,
'target' => '_blank'
));
//休み設定
/*
$wp_admin_bar->add_menu(array(
'id' => 'new_item_in_admin_bar2',
'title' => __(' 休みメッセージ'),
'href' => "https://www.3scom.com/php/rusu_edit.php",
'target' => '_blank'
));
*/
//休み設定
$wp_admin_bar->add_menu(array(
'id' => 'new_item_in_admin_bar3',
'title' => __(' メーカー一覧'),
'href' => "/makerlist.html",
'target' => '_blank'
));
}
add_action( 'wp_before_admin_bar_render', analytics_title_head );
//--------------------------------------------------
//投稿画面のカスタマイズ
//商品情報のコピペ関連
function caution_title_head(){
require_once("cmn_sub.php");
global $post;
//コピペツール
echo ' ';
echo '
';
//更新予約ありの場合は青色に
$yoyaku = date(get_post_meta($post -> ID, "更新予約",true));
if($yoyaku != ""){
echo '
■追記予約が設定されています '. $yoyaku . '';
}
}
add_action( 'edit_form_top', caution_title_head );
//--------------------------------------------------
// 表示回数のカウント
add_action('wp_head_postviews', 'process_postviews');
//--------------------------------------------------
// 表示の補助
function replace_br($str){
$str = str_replace("\n","
",$str);
return $str;
}
//--------------------------------------------------
// 記事のmoreを前と後ろに分ける
function get_the_divided_content( $more_link_text = null, $stripteaser = 0, $more_file = '' ) {
$regex = '#(
|)#';
$content = get_the_content( $more_link_text, $stripteaser, $more_file );
$content = apply_filters( 'the_content', $content );
$content = str_replace( ']]>', ']]>', $content );
if ( preg_match( $regex, $content ) ) {
list( $content_array['before'], $content_array['after'] ) = preg_split( $regex, $content, 2 );
} else {
$content_array['before'] = '';
$content_array['after'] = $content;
}
return $content_array;
}
//--------------------------------------------------
// WP機能のサムネイル関係
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
}
//--------------------------------------------------
// 「投稿一覧」に表示しているリストのカスタマイズ
// カスタムフィールドの表示
function manage_custom_columns($columns) {
$columns['クリック日付'] = 'クリック日付';
$columns['更新予約'] = '更新予約';
return $columns;
}
add_filter('manage_posts_columns', 'manage_custom_columns');
function add_custom_columns($column_name, $post_id) {
if ($column_name == 'クリック日付') {
echo get_post_meta($post_id, 'クリック日付', true);
}
if ($column_name == '更新予約') {
echo get_post_meta($post_id, '更新予約', true);
}
}
add_action('manage_posts_custom_column', 'add_custom_columns', 10, 2);
// ソート対応処理
function column_orderby_custom( $vars ) {
if ( isset( $vars['orderby'] ) && 'クリック日付' == $vars['orderby'] ) {
$vars = array_merge( $vars, array(
'meta_key' => 'クリック日付',
'orderby' => 'meta_value'
));
}
if ( isset( $vars['orderby'] ) && '更新予約' == $vars['orderby'] ) {
$vars = array_merge( $vars, array(
'meta_key' => '更新予約',
'orderby' => 'meta_value'
));
}
return $vars;
}
add_filter( 'request', 'column_orderby_custom' );
function posts_register_sortable( $sortable_column ) {
$sortable_column['クリック日付'] = 'クリック日付';
$sortable_column['更新予約'] = '更新予約';
return $sortable_column;
}
add_filter( 'manage_edit-post_sortable_columns', 'posts_register_sortable' );
//-------------------------------------------
//投稿画面でタグを常に表示
function enlargetagcloud($args,$taxonomies){
if(DOING_AJAX && $_POST['action']=='get-tagcloud'){
$args['number']=100;
}
return($args);
}
add_filter('get_terms_args','enlargetagcloud',10,2);
function my_admin_head(){
echo
'';
}
add_action('admin_head', 'my_admin_head');
//-------------------------------------------
// 入力画面のフォントサイズをpxではなく%で使用
if ( ! function_exists( 'extend_mce_button' ) ) {
function extend_mce_button( $buttons ) {
array_unshift( $buttons, 'fontsizeselect' );
return $buttons;
}
}
add_filter( 'mce_buttons_2', 'extend_mce_button' );
add_filter( 'tiny_mce_before_init', 'my_mce_before_init',5 );
function my_mce_before_init( $settings ) {
$settings['fontsize_formats'] = "100% 125% 150% 175% 200% 250% 300% 400% 500%";
return $settings;
}
// ビジュアルエディタ用CSS
add_editor_style('editor_style.css');
function custom_editor_settings( $initArray ) {
$initArray['body_class'] = 'editor-area';
return $initArray;
}
add_filter( 'tiny_mce_before_init', 'custom_editor_settings' );
//**************************************************//
// 表示関係
//**************************************************//
//--------------------------------------------------
// 記事に画像があったら小さくしてサムネイルにする
function catch_that_image($post) {
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('//i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "";
}
return $first_img;
}
//--------------------------------------------------
// コメントの表示関連
function mytheme_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
extract($args, EXTR_SKIP);
echo "";
edit_comment_link(__('(Edit)'),'','');
$tag = 'li';
comment_text();
}
//-----------------------------------------
// 記事の表示の際に追記タグを削除する
function punchline($the_content) {
if (is_singular()) {
$return = $the_content;
for($i = 1;$i <= 5;$i++){
$field_num = mb_convert_kana($i,"A");
$return = str_replace("#追記予定部分". $field_num . "#","" ,$return);
}
return $return;
} else {
return $the_content;
}
}
add_filter('the_content','punchline');
//**************************************************//
// 以降ショートコード関係
//**************************************************//
//--------------------------------------------------
//[タグ処理]すべての表示履歴
function findlists_fnc($atts) {
require_once locate_template('shortcode_simple.php');
@$html = shortcode_findlists();
return $html;
}
add_shortcode('findlists', 'findlists_fnc');
//--------------------------------------------------
//[タグ処理] 更新順
function newlist_fnc($atts) {
require_once locate_template('shortcode_simple.php');
extract ( shortcode_atts ( array (
'cnt' => '0'
), $atts ) );
@$html = shortcode_newlist($cnt);
return $html;
}
add_shortcode('newlist', 'newlist_fnc');
//--------------------------------------------------
//[タグ処理] メーカー別
function maker_select_fnc($atts) {
require_once locate_template('shortcode_maker_select.php');
extract ( shortcode_atts ( array (
'maker_no' => '0'
), $atts ) );
@$html = shortcode_maker_select($maker_no);
return $html;
}
add_shortcode('maker_select', 'maker_select_fnc');
//--------------------------------------------------
//[タグ処理] 金額別
function pricerange_fnc($atts) {
require_once locate_template('shortcode_item_lists.php');
extract ( shortcode_atts ( array (
'min_price' => '0',
'max_price' => '10'
), $atts ) );
@$html = get_item_by_price($min_price , $max_price);
return $html;
}
add_shortcode('pricerange', 'pricerange_fnc');
function pricerange_simple_fnc($atts) {
require_once locate_template('shortcode_item_lists.php');
extract ( shortcode_atts ( array (
'min_price' => '0',
'max_price' => '10',
'cnt' => '6'
), $atts ) );
@$html = get_item_by_price_simple($min_price , $max_price , $cnt);
return $html;
}
add_shortcode('pricerange_simple', 'pricerange_simple_fnc');
//--------------------------------------------------
//[タグ処理] ランキング
function ranking_views_fnc($atts) {
require_once locate_template('shortcode_ranking_views.php');
extract ( shortcode_atts ( array (
'from_no' => '1',
'to_no' => '15'
), $atts ) );
@$html = shortcode_ranking_views($from_no , $to_no );
return $html;
}
add_shortcode('ranking_views', 'ranking_views_fnc');
//--------------------------------------------------
//[タグ処理] カスタムフィールド類似
function customrange_fnc($atts) {
require_once locate_template('shortcode_item_lists.php');
extract ( shortcode_atts ( array (
'customtitle' => 'ER',
'value' => ''
), $atts ) );
@$html = get_item_by_custom($customtitle , $value);
return $html;
}
add_shortcode('customrange', 'customrange_fnc');
//--------------------------------------------------
//[タグ処理] タグ抽出 商品
function tagselect_fnc($atts) {
require_once locate_template('shortcode_item_lists.php');
extract ( shortcode_atts ( array (
'search_tag' => '',
'kanbai' => "なし",
'is_rank' => "true"
), $atts ) );
@$html = get_item_by_tag($search_tag,$kanbai,$is_rank);
return $html;
}
add_shortcode('tagselect', 'tagselect_fnc');
//--------------------------------------------------
//[タグ処理] タグ抽出 テキスト:内容表示タイプ
function tagselect_text_content_fnc($atts) {
require_once locate_template('shortcode_text_lists.php');
extract ( shortcode_atts ( array (
'search_tag' => '',
), $atts ) );
@$html = get_news_by_tag($search_tag);
return $html;
}
add_shortcode('tagselect_text_content', 'tagselect_text_content_fnc');
//--------------------------------------------------
//[タグ処理] ガチャ
function gatya_show_fnc($atts) {
require_once locate_template('shortcode_simple.php');
extract ( shortcode_atts ( array (
'selecttype' => '0'
), $atts ) );
@$html = shortcode_gatya_show($selecttype);
return $html;
}
add_shortcode('gatya_show', 'gatya_show_fnc');
//--------------------------------------------------
//[タグ処理] 新カテゴリー体制
function relation_fnc($atts) {
require_once locate_template('shortcode_item_lists.php');
extract ( shortcode_atts ( array (
'keyword' => '',
'num' => 100,
'kanbai' => "あり",
'is_rank' => false
), $atts ) );
@$html = get_item_by_key($keyword,$num,$kanbai,$is_rank);
return $html;
}
add_shortcode('my_relation', 'relation_fnc');
//--------------------------------------------------
//[タグ処理] カスタムランキング
function custon_ranking_fnc($atts) {
require_once locate_template('shortcode_custonranking.php');
extract ( shortcode_atts ( array (
'flg' => '0'
), $atts ) );
@$html = custon_ranking($flg);
return $html;
}
add_shortcode('custon_ranking', 'custon_ranking_fnc');
//--------------------------------------------------
// 検索の際にはクリック日付でソート(完売を後ろにするために)
function SortArchive( $query ) {
if ($query->is_search() ) {
$query->set( 'meta_key', 'クリック日付' );
$query->set( 'orderby', 'meta_value' );
return;
}
}
add_action( 'pre_get_posts', 'SortArchive' );
/* カテゴリ部分を大きくする */
function hide_category_tabs_adder() {
global $pagenow;
global $post_type;
if ( is_admin() && ($pagenow=='post-new.php' || $pagenow=='post.php') ) {
echo '';
}
}
add_action( 'admin_head', 'hide_category_tabs_adder' );
?>
///
/// カテゴリーページの表示
///
//【注意!】 get_query_var('paged')は都度取らないと
// どこかでカウントUPしているみたいです
require_once("cmn.php");
require_once("cmn_sub.php");
require_once("shortcode_item_lists.php");
require_once("shortcode_text_lists.php");
//------------------------------------
// テンプレートの決定
$html = file_get_contents('dw_contents.html');
$html = css_mob_pc($html);
//------------------------------------
// 必要事項を入れ込む
// mete、footer、sidebar等を入れ込む
unification_set($html,$cat,"");
$html = str_replace("#H1_TAGS",date('Y年m月')."の".$H1_TAGS ,$html);
$html = str_replace("#H2_TAGS","" ,$html);
$html = str_replace("#TITLE","" ,$html);
$contents = "";
$tmp_page = get_query_var('paged') ;
// 最初のページのみバナーと説明
if($tmp_page == "0"){
//カテゴリーのディスクリプションを用いてカテゴリーの説明
$lastdate = mysql2date('Y-m-d', get_lastpostmodified(), false);
/*
$contents = "";
$contents = "".category_description()." 最終更新日:".$contents."
";
$contents .= get_field('カテゴリ上部分','category_'.$cat);
*/
$contents = get_field('カテゴリ上部分','category_'.$cat);
}
// カテゴリ、タグ向けの特殊バナー
$contents .= tax_banner(get_category($cat)->name);
//記事の表示
if ( have_posts() )
{
//--------------------------------
//--- テキストカテゴリーの場合 ---
if(is_cat_text($cat)){
$contents .= "";
while (have_posts()) : the_post();
$contents .= text_list($post);
endwhile;
$contents .= "
";
// ページの表示
$contents .= get_pagelinks();
//----------------------------
//--- 商品カテゴリーの場合 ---
}else{
// 定数
$posts_per_page = get_option('posts_per_page');
$val_category_ins_ranking = cmn_info("val_category_ins_ranking");
// 補足表示
//$contents .= "※画像をクリックすると詳細を表示します。
";
// ページリンクの表示
$contents .= get_pagelinks_min();
//商品用 基本SQLの取得 完売あり
$arg = get_sql_item("あり");
//SQLの修正 カテゴリ用に
$arg[cat] = query_itemonly($cat);
//SQLの修正 ランキング用に
$arg[showposts] = $val_category_ins_ranking;
//商品リスト ランキングの取得
$contents_rank= get_datalists_item_rank($arg,get_category($cat)->name,$remove_posts_id);
//--------------------------------
// 1ページ目の時はランキングの表示
if($tmp_page == "0"){
//商品リストランキングの取得
$contents .= $contents_rank;
}
//---------------------------------
// 商品の取得
//SQLの修正 一覧用
$arg[showposts] = $posts_per_page;
$arg[posts_per_page] = $posts_per_page;
$arg[paged] = $tmp_page;
//商品リスト表示順の取得
$contents_view = get_datalists_item_viewdate($arg,$remove_posts_id);
$contents .= $contents_view;
//--------------------------------------------------------
// 件数調整部分
// カテゴリ記事数 = 商品記事数 + 文章記事数
// 総ページ数 = カテゴリ記事数 / 設定:表示件数
// 最初は無理やり商品のみ抜粋しているので、
// 商品の抜粋が終わったら文章記事ページを表示
if($contents_view == ""){
//カテゴリ内の件数
$allcat_cnt = get_category($cat)->count;
//カテゴリ内の商品のみの件数
$list_texts = cmn_info("list_texts");
$ary_list_texts = explode(",", $list_texts);
$item_arg = array(
category__in => $cat,
showposts => -1,
category__not_in => $ary_list_texts
);
$itemcat_cnt = count(get_posts($item_arg));
//テキストだけの件数
$textcat_cnt = $allcat_cnt - $itemcat_cnt;
//商品&テキストの記事だけの場合ページ
$real_tmp_page = floor($tmp_page - ($itemcat_cnt / $posts_per_page));
if($real_tmp_page <= 0){
$real_tmp_page = 1;
}
//現ページ内のデータの取得
$arg = query_textonly($cat);
$arg[showposts] = $posts_per_page;
$arg[offset] = ($real_tmp_page - 1) * $posts_per_page;
$contents .= "情報ページ" .$real_tmp_page . "
". get_datalists_news_linkstyle($arg);
}
//-----------------------------------
// ページの表示
$contents .= get_pagelinks();
//-----------------------------------
//リンク階層:従属固定ページ関連
$child_list = relation_cat_children_list($cat);
$child_list = set_children_sidebar($child_list);
$html = str_replace("#CHILD_LIST",$child_list ,$html);
//スマホはカテゴリリンクまで
if(is_sumapho()){
if(strpos($html,"child_list") !== false){
$contents = "
カテゴリを絞り込む
" . $contents;
}
}
//もし最初のページなら追加する
if($tmp_page == "0"){
$contents .= get_field('カテゴリ下部分','category_'.$cat) . "
最終更新日:";
}
//商品リストの下
$contents .= cmn_info("itemlist_footer");
//--------------------------------------------------------
// 商品&テキストの記事内容表示
if($tmp_page == "0"){
$post_cnt = 5;
query_posts(query_textonly($cat));
$contents .= "";
while (have_posts()) : the_post();
$contents .= "
".get_the_title()."
";
ob_start();
the_content();
$contents .= ob_get_clean();
$post_cnt --;
if($post_cnt <= 0) break;
endwhile;
$contents .= "
";
wp_reset_query();
}
}
}
$html = str_replace("#TEXT_CONTENTS",$contents ,$html);
// 補完できないタブは削除
$html = str_replace("","" ,$html);
$html = str_replace("","" ,$html);
$html = str_replace("","" ,$html);
$html = str_replace("#CHILD_LIST","" ,$html);
//最後に微調整があったら入れる
original_unify_after($html);
echo $html;
?>