CSSで管理画面内のサイドメニューを非表示にする 権限指定

//CSSで管理画面内のサイドメニューを非表示にする 権限指定
function custom_admin_styles(){
$current_user = wp_get_current_user(); //現在のユーザー情報を取得
if(check_user_role($current_user,’shop_owner’)){ //shop_ownerかチェック
echo ‘ ‘;
}
if(check_user_role($current_user,’editor’)){ //編集者(editor)かチェック
echo ‘ ‘;
}

}
add_action(‘admin_print_styles’, ‘custom_admin_styles’, 21);

/*
* ユーザーの権限をチェックする
* @param $user ユーザーオブジェクト
* @param $role ユーザー権限の文字列
* (administrator, editor, author, contributor, subscriber)
*/
function check_user_role($user,$role){
foreach($user->roles as $user_role){
if($user_role === $role){
return true;
}
}
return false;
}

カスタムアドミンはこちら

ダッシュボードにオリジナルメニューを追加

//☆--オリジナルメニューを追加
function example_dashboard_widget_function() {
 echo '
  <div class="da d1"><a href="./post-new.php">投稿</a></div>
  <div class="da d1"><a href="./edit.php">投稿一覧</a></div>
 <div class="da d6"><a href="./admin.php?page=home/goldsource/www/temp/ecoroop/wp-content/themes/D/functions.php">マニュアル</a></div>
 ';
}
function example_add_dashboard_widgets() {
 wp_add_dashboard_widget('example_dashboard_widget', '更新', 'example_dashboard_widget_function');
}
add_action('wp_dashboard_setup', 'example_add_dashboard_widgets' );
//オリジナルメニューを追加--☆
//☆--オリジナルメニューを追加
function example_dashboard_widget_function() {
 echo '
  <div class="da d1"><a href="./post-new.php">新規 JC NEWS</a></div>
  <div class="da d1"><a href="edit.php?post_type=member_only">新規 ファイルアップロード</a></div>
 <div class="da d6"><a href="post-new.php?post_type=public_information">新規 公開情報</a></div>
 <div style="clear:both"></div>
 ';
}
function example_add_dashboard_widgets() {
 wp_add_dashboard_widget('example_dashboard_widget', '更新', 'example_dashboard_widget_function');
}
add_action('wp_dashboard_setup', 'example_add_dashboard_widgets' );
//オリジナルメニューを追加--☆

カスタムアドミンに

.da{
	float: left;
	padding-top: 10px;
	padding-right: 5px;
	padding-bottom: 10px;
	padding-left: 5px;
}


.da a{
	padding: 15px;
	background-color: #4091B4;
	color: #FFF;
	    -webkit-border-top-left-radius: 5px;  
    -webkit-border-top-right-radius: 5px;  
    -webkit-border-bottom-right-radius: 5px;  
    -webkit-border-bottom-left-radius: 5px;  
    -moz-border-radius-topleft: 5px;  
    -moz-border-radius-topright: 5px;  
    -moz-border-radius-bottomright: 5px;  
    -moz-border-radius-bottomleft: 5px;  
}

オリジナルアドミンバーメニュー

//オリジナルアドミンバーメニュー
add_action('admin_bar_menu', 'customize_admin_bar_menu', 9999);

function customize_admin_bar_menu($wp_admin_bar){
    $title = sprintf(
        '<span class="ab-icon"></span><span class="ab-label">%s</span>',
        '瀬戸青年会議所'
    );
    $wp_admin_bar->add_menu(array(
        'id'    => 'bookpress-app',
        'meta'  => array(),
        'title' => $title,
        'href'  => home_url()
    )); 
	$wp_admin_bar->add_menu(array(
    'parent' => 'bookpress-app', // 親メニューのIDを指定する
    'id'     => 'bookpress-app-sub4',
    'meta'   => array(),
    'title'  => '管理画面へ',
    'href'   => home_url('/wp-admin/')
));
	$wp_admin_bar->add_menu(array(
    'parent' => 'bookpress-app', // 親メニューのIDを指定する
    'id'     => 'bookpress-app-sub',
    'meta'   => array(),
    'title'  => 'JC NEWSを書く',
    'href'   => home_url('/wp-admin/post-new.php')
));
$wp_admin_bar->add_menu(array(
    'parent' => 'bookpress-app', // 親メニューのIDを指定する
    'id'     => 'bookpress-app-sub2',
    'meta'   => array(),
    'title'  => 'ファイルをアップロード',
    'href'   => home_url('/wp-admin/post-new.php?post_type=member_only')
));

$wp_admin_bar->add_menu(array(
    'parent' => 'bookpress-app', // 親メニューのIDを指定する
    'id'     => 'bookpress-app-sub3',
    'meta'   => array(),
    'title'  => 'ログアウト',
    'href'   => home_url('/wp-login.php?action=logout&redirect_to=http%3A%2F%2Fwww.setojc.org&_wpnonce=58ea72a46d')
));
}



//アドミンバー内容消す
add_action('admin_bar_menu', 'customize_admin_bar_menu2', 9999); // 優先順位は大きめで!

function customize_admin_bar_menu2($wp_admin_bar){
    // Adminバー左側
    $wp_admin_bar->remove_node('wp-logo');     // 一番左のWordPressのロゴを消す。
	$wp_admin_bar->remove_node('comments'); // コメント
    $wp_admin_bar->remove_node('site-name');   // 左から2番めのサイト名を消す。
    $wp_admin_bar->remove_node('new-content'); // 「+ 新規」ってメニューを消す。

    // Adminバー右側
    $wp_admin_bar->remove_node('my-account'); // アカウントのメニューを消す。
    $wp_admin_bar->remove_node('search');     // 検索のメニューを消す。
}

ダッシュボードウィジェット非表示

// ダッシュボードウィジェット非表示
function example_remove_dashboard_widgets() {
if (!current_user_can(‘level_10’)) { //level10以下のユーザーの場合ウィジェットをunsetする
global $wp_meta_boxes;
unset($wp_meta_boxes[‘dashboard’][‘normal’][‘core’][‘dashboard_right_now’]); // 現在の状況
unset($wp_meta_boxes[‘dashboard’][‘normal’][‘core’][‘dashboard_recent_comments’]); // 最近のコメント
unset($wp_meta_boxes[‘dashboard’][‘normal’][‘core’][‘dashboard_incoming_links’]); // 被リンク
unset($wp_meta_boxes[‘dashboard’][‘normal’][‘core’][‘dashboard_plugins’]); // プラグイン
unset($wp_meta_boxes[‘dashboard’][‘side’][‘core’][‘dashboard_quick_press’]); // クイック投稿
unset($wp_meta_boxes[‘dashboard’][‘side’][‘core’][‘dashboard_recent_drafts’]); // 最近の下書き
unset($wp_meta_boxes[‘dashboard’][‘side’][‘core’][‘dashboard_primary’]); // WordPressブログ
unset($wp_meta_boxes[‘dashboard’][‘side’][‘core’][‘dashboard_secondary’]); // WordPressフォーラム
}
}
add_action(‘wp_dashboard_setup’, ‘example_remove_dashboard_widgets’);

ログアウト2種

インデックスへ
<div class="menu_d"><a href="<?php echo wp_logout_url(home_url()); ?>">ログアウト</a></div>

ログインページへ
<div class="menu_d"><?php wp_loginout(); ?></div>

会員専用ページ ログインしてないとログインページへ

http://amazon-ebay.inthecom.net/?p=662

リダイレクト テーマバイログインだとだめだったな

<?php /* Template Name: 会員専用ページ Single Post Template: 会員専用ページ Description: This part is optional, but helpful for describing the Post Template */ ?>

<?php if (is_user_logged_in()){  }else {auth_redirect(); }; ?>

アドミンバー項目削除

function remove_bar_menus( $wp_admin_bar ) {
    $wp_admin_bar->remove_menu('wp-logo'); // W ロゴ
    $wp_admin_bar->remove_menu('site-name'); // サイト名
    $wp_admin_bar->remove_menu('view-site'); // サイト名 -> サイトを表示
    $wp_admin_bar->remove_menu('comments'); // コメント
    $wp_admin_bar->remove_menu('new-content'); // 新規
    $wp_admin_bar->remove_menu('new-post'); // 新規 -> 投稿
    $wp_admin_bar->remove_menu('new-media'); // 新規 -> メディア
    $wp_admin_bar->remove_menu('new-link'); // 新規 -> リンク
    $wp_admin_bar->remove_menu('new-page'); // 新規 -> 固定ページ
    $wp_admin_bar->remove_menu('new-user'); // 新規 -> ユーザー
    $wp_admin_bar->remove_menu('updates'); // 更新
    $wp_admin_bar->remove_menu('my-account'); // マイアカウント
    $wp_admin_bar->remove_menu('user-info'); // マイアカウント -> プロフィール
    $wp_admin_bar->remove_menu('edit-profile'); // マイアカウント -> プロフィール編集
    $wp_admin_bar->remove_menu('logout'); // マイアカウント -> ログアウト
}
add_action('admin_bar_menu', 'remove_bar_menus', 201);

カテゴリ系のまとめ

<?php //カテゴリーページでカテゴリー名を取得 りんくなし
 $cat_d = get_the_category(); 
 $cat_d = $cat_d[0];
 $cat_name_d = $cat_d->cat_name;
 echo $cat_name_d;
  ?>

上記 記事が無いとでないため

<?php single_term_title(); ?> 

こっち

かてID2へのリンク

<a href="<?php echo get_category_link('2');?>">活動報告をもっと見る▶</a>

リンクつき記事のカテゴリ出力

<?php the_category(', '); ?> 

Custom Field Suite 日付日本語化!!!

日付日本語化 プラグ▶fields▶date
jquery.datetime.js

変更

出力
単発

echo date('Y年m月d日', strtotime($cfs->get('birthday')));

ループ未検証

<?php $loop = new WP_Query(array("post_type" => "schedule", "posts_per_page" => 1 ));

while($loop->have_posts()): $loop->the_post(); ?>

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

 <h2><?php the_title(); ?></h2>
 <h3><?php echo $cfs->get('title'); ?></h3>

<ul>
 <li><?php echo date('Y年m月d日', strtotime($cfs->get('date'))); ?></li>
 <li><?php echo $cfs->get('summary'); ?></li>
</ul>

 <?php $fields = $cfs->get('Schedule'); foreach ($fields as $field) { ?>

 <h3><?php echo $field['title']; ?></h3>

<ul>
 <li><?php echo date('Y年m月d日', strtotime($field['date'])); ?></li>
 <li><?php echo $field['summary']; ?></li>
</ul>
 <?php } ?>

</div>

 <?php endwhile; ?>

参考

http://brushape.com/wordpress/%E3%80%90wordpress%E3%80%91%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%A0%E3%83%95%E3%82%A3%E3%83%BC%E3%83%AB%E3%83%89%E3%82%92%E7%B0%A1%E5%8D%98%E4%BD%9C%E6%88%90%E3%81%97%E3%81%9F%E3%81%8F%E3%81%A6%E3%80%8Ccu/

(ライブ)スケジュール機能

スケジュール準備

未来記事表示 No Future Post
http://imasashi.net/blog/wordpress/future-info.html

もしっくは
ファンクション未検証http://istks.net/2300

function myfunc($data, $posts) {
if ($data['post_status'] === 'future' &amp;&amp; $posts['post_status'] === 'publish') {
$data['post_status'] = 'publish';
}
return $data;
}
add_filter('wp_insert_post_data', 'myfunc', 10, 2);

ループ みけん

<?php
function filter_where($where = '') {
$where .= " AND post_date > '" . date('Y-m-d', strtotime('0 days')) . "'";
return $where;
}
add_filter('posts_where', 'filter_where');
query_posts(array(
    'cat' => ※記事カテゴリーID,
    'order' => ASC,
));?>
<?php if (have_posts()) : ?>
<?while (have_posts()): the_post(); ?>
    ※ループ中身
<?php endwhile; ?>
<?php else : ?>
    ※予定が無い場合のメッセージ
<?php endif; ?>

カテゴリーページの場合みけん

<?php
function filter_where($where = '') {
$where .= " AND post_date > '" . date('Y-m-d', strtotime('0 days')) . "'";
return $where;
}
add_filter('posts_where', 'filter_where');
query_posts(array(
'cat' => get_query_var('cat'),
'order' => ASC,
));?>

アーカイブページみけん

<?php
  function filter_where($where = '') {
    $where .= " AND post_date > '" . date('Y-m-d', strtotime('1 days')) . "'";
    return $where;
  }
add_filter('posts_where', 'filter_where');
global $query_string;
query_posts($query_string . "&order=ASC");
?>

何日間とか指定
http://wpdocs.sourceforge.jp/%E3%83%86%E3%83%B3%E3%83%97%E3%83%AC%E3%83%BC%E3%83%88%E3%82%BF%E3%82%B0/query_posts#.E6.97.A5.E6.99.82.E5.BC.95.E6.95.B0

何日から何日と指定
http://webcake.no003.info/webdesign/wp-queryposts-datesearch.html

記事が無い時ほかのページ みけん

http://ja.forums.wordpress.org/topic/21998?replies=5

本日の日付から過去30日間に書かれた最新記事を5件表示みけん
http://www.imamura.biz/blog/cms/wordpress/tips/8176

ignore_sticky_posts=1とは
http://mekemoke.jp/2012/10/428.html

検証結果===============

>< =><=がキーマン [php]function filter_where($where = '') {//フィルター $where .= " AND post_date > '" . date('Y-m-d', strtotime('0 days')) . "'";//AND post_date のあとの記号で未来過去をチェンジ return $where; } add_filter('posts_where', 'filter_where');[/php]

ログインしてたらの分岐

この条件分岐タグは、現在の訪問者がログインしているかチェックします。これは TRUE または FALSE の値を返す boolean 関数です。

<?php if ( is_user_logged_in() ) { ... } ?>

<?php if ( is_user_logged_in() ):?>

<?php
if ( is_user_logged_in() ) {
	echo 'Welcome, registered user!';
} else {
	echo 'Welcome, visitor!';
};
?>

Custom Field Suite のまとめ2? ループフィールドの出力方法基本

■ギャラリー

<?php
if ( have_posts () ) :
    while ( have_posts() ) :
        the_post();
?>

<!--ギャラリー取得--->
<?php
$fields = $cfs->get('shop_gallery');
foreach ($fields as $field) :
?>

<?php
 $attachment_id = $field['gallery_photo'];
 $sample_photo = wp_get_attachment_image($attachment_id,'full');
echo $sample_photo;
?>

<?php
endforeach;
?>

<?php
    endwhile;
endif;
?>

05naviの記事件数 登録 何件?

ファンクションへ
オリジナル関数だと思う

//特定のカテゴリと特定のタグで絞った記事数の表示方法
function taxonomy_found_posts_num() {
    $args = array(
'post_type' => array('shoku','asobu','share','seikatsu','iryou','manabu','koukyou','ofuroyado'), //カスタム投稿名
    );
    $my_query = new WP_Query($args);
    return $my_query->found_posts;
}

//表示箇所に
//<?php echo taxonomy_found_posts_num('hokkaido','タグ1'); 件<br />
//<?php echo taxonomy_found_posts_num('aomori','タグ2'); 件

上記正式コード

<?php
function taxonomy_found_posts_num($cat_slug,$tag_slug) {
    $args = array(
        'post_type' =>'post',
        'tax_query' => array(
            'relation' => 'AND',
            array(
                'taxonomy' => 'category',
                'field' => 'slug',
                'terms' => $cat_slug,
            ),
            array(
                'taxonomy' => 'post_tag',
                'field' => 'slug',
                'terms' => $tag_slug,
            ),
        ),
        'posts_per_page' => 1
    );
    $my_query = new WP_Query($args);
    return $my_query->found_posts;
}
?>
    <?php 

//特定のポストタイプと特定のユーザーIDで絞った記事数の表示方法
function taxonomy_found_posts_num1($post_type,$user_id) {
    $args = array(
'post_type' => $post_type, //カスタム投稿名
'author' => $user_id,
    );
    $my_query = new WP_Query($args);
    return $my_query->found_posts;
}

//ログインユーザーのIDを取得
$user = wp_get_current_user();
$user_idd = $user->get('ID')."\n"; // ID

//出力
echo taxonomy_found_posts_num1('shoku',$user_idd);
	?>