/*---- !!!!危険!!!!! ----*/
/*---- もし修正する場合にはこのファイルのバックアップをとっておいて ----*/
/*---- 落ちたら差し替えてください ----*/
/*---- もし小林が消えたら次の会社に相談をしてください
株式会社カーネル(豊島区池袋) 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'
));
}
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 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 SortArchive( $query ) {
if ($query->is_search() ) {
$query->set( 'meta_key', 'クリック日付' );
$query->set( 'orderby', 'meta_value' );
return;
}
}
add_action( 'pre_get_posts', 'SortArchive' );
?>
//--共通関数----------------------------------------
// 記事ページの表示
//--------------------------------------------------
require_once("header.php");
require_once("cmn.php");
require_once("cmn_sub.php");
while (have_posts()) : the_post();
// テンプレートの決定
$html = file_get_contents('dw_contents.html');
$html = css_mob_pc($html);
//------------------------------------
// 必要事項を入れ込む
// mete、footer、sidebar等を入れ込む
unification_set($html,"",$post);
//リンク階層:子供や孫がいるときリンクを付ける
$child_list = relation_page_children_list($post->ID);
$child_list = set_children_sidebar($child_list);
$html = str_replace("#CHILD_LIST",$child_list ,$html);
// H1タグ
$H1_TAGS = top_htag($post);
$html = str_replace("#H1_TAGS",$H1_TAGS ,$html);
// H2タグ
$H2_TAGS = h2_tag($post);
$html = str_replace("#H2_TAGS",$H2_TAGS ,$html);
// 記事内容
ob_start();
the_content();
$TEXT_CONTENTS = ob_get_clean();
//調節して表示
$TEXT_CONTENTS = "
"
. $TEXT_CONTENTS
."
";
//スマホはカテゴリリンクまで
if(is_sumapho()){
if(strpos($html,"child_list") !== false){
$TEXT_CONTENTS = "
カテゴリを絞り込む
" . $TEXT_CONTENTS;
}
}
//修正
// ログイン状態なら「修正」と画像フォルダ名の表記
$lastname = "";
if(is_user_logged_in()){
//修正リンク
$TEXT_CONTENTS .= " ID . "&action=edit' style='background-image:none;font-size:15px'>修正する≫";
}
$html = str_replace("#TEXT_CONTENTS",$TEXT_CONTENTS ,$html);
//最後に微調整があったら入れる
original_unify_after($html);
// 補完できないタブは削除
$html = str_replace("","" ,$html);
$html = str_replace("#CHILD_LIST","" ,$html);
//表示
echo $html;
endwhile;
?>