$post_ID = 10; //記事ID $post = get_post($post_ID); $title = get_the_title($post);
参考http://www.4web8.com/739.html
$post_ID = 10; //記事ID $post = get_post($post_ID); $title = get_the_title($post);
参考http://www.4web8.com/739.html
<META name="description" content="0561ナビ<?php wp_title(); ?>|<?php $con_disp= mb_substr(strip_tags($post-> post_content),0,100); echo str_replace(array("\r\n","\r","\n"), '', $con_disp); ?> " />
参考
http://wordpress.webys.jp/php_reference/392.html
ポイント
イフはぶポストで一回区切る
エンドワイルで一回区切る
‘post__not_in’=> array($now_post_id),
<!------------------------------最新記事------------------------------------> <?php $user_id = get_the_author_meta( 'id' ); ?> <?php $now_post_id= get_the_ID(); ?> <?php $args = array( 'posts_per_page' => 3, 'author'=>$user_id, 'orderby' => 'modified',//更新順 'post__not_in'=> array($now_post_id), ); ?> <!----/宣言-----> <!----宣言2-----> <?php query_posts( $args ); ?> <?php if ( have_posts () ) :?> ■<?php echo get_the_author_meta( 'author_nickname' ); ?> さんの最新記事 <div style="clear:both"></div><br /> <?php while ( have_posts() ) : the_post(); ?> <?php include("d_blog_roop_new.php"); ?> <?php endwhile;?> <div class="blog_more"><a href="<?php bloginfo('url'); ?>/?author=<?php $user_id = get_the_author_meta( 'id' ); ?><?php echo $user_id; ?>"> <?php echo get_the_author_meta( 'author_nickname' ); ?>さん のブログをみる▶</a></div> <?php endif; ?> <!------------------------------リセットクエリ------------------------------------> <?php wp_reset_query(); ?>
<?php the_time('Y年m月d日 G:i'); ?>
2013年11月18日 19:19
こう出る
<?php if(has_post_thumbnail()){ /*サムネイルの表示*/ the_post_thumbnail(array(200,200)); }else{ /*代替え画像の表示*/ echo '<img src="http://r-ichinomiya.com/wp-content/uploads/2012/06/wpid-NEC_00144-240x240.jpg" width="200" alt="一宮スナックRのロゴ">'; } ?>
プラグイン
Auto Post Thumbnailを入れる
<?php wp_get_attachment_image( $attachment_id, $size, $icon, $attr ); ?> //デフォルトはechoで出力 <?php echo wp_get_attachment_image(); ?>
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/wp_get_attachment_image
<?php wp_get_attachment_image_src( $attachment_id, $size, $icon ); ?>
戻り値
(配列)
配列は以下を含みます:
[0] => url
[1] => width
[2] => height
[3] => 真偽値: リサイズされいている場合は true、元のサイズの場合は false
http://wpdocs.sourceforge.jp/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/wp_get_attachment_image_src
#profile-page h3, #profile-page table:nth-of-type(1) tr:nth-child(1), #profile-page table:nth-of-type(1) tr:nth-child(2), #profile-page table:nth-of-type(1) tr:nth-child(3), #profile-page table:nth-of-type(2) tr:nth-child(2), #profile-page table:nth-of-type(2) tr:nth-child(3), #profile-page table:nth-of-type(2) tr:nth-child(4), #profile-page table:nth-of-type(2) tr:nth-child(5), #profile-page table:nth-of-type(3) tr:nth-child(2), #profile-page table:nth-of-type(4) tr:nth-child(1) { display: none; }
ファンクション
//プロフィール画面でビジュアルエディターのチェックボックスを隠す function hide_richeditor_checkbox() { global $wp_rich_edit_exists; if ( ! current_user_can( 10 ) && defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE ) { $wp_rich_edit_exists = false; } } add_action( 'admin_head', 'hide_richeditor_checkbox' ); //ユーザープロフィールの「管理画面の配色」を削除 remove_filter( 'admin_color_scheme_picker', 'admin_color_scheme_picker' ); //管理画面の配色を強制的に青 function admin_color_force_fresh() { return 'classic'; } add_filter( 'get_user_option_admin_color', 'admin_color_force_fresh' ); //管理画面文字変更 add_filter('gettext', 'change_post_to_article'); add_filter('gettext_with_context', 'change_post_to_article'); add_filter('ngettext', 'change_post_to_article'); add_filter('ngettext_with_context', 'change_post_to_article'); function change_post_to_article($translated) { $translated = str_ireplace( 'プロフィール', 'パスワードの変更', $translated ); return $translated; } //このcssでCSS3を使って項目見えなくする //CSSで管理画面内のサイドメニューを非表示にする 権限指定 function custom_admin_styles(){ $current_user = wp_get_current_user(); //現在のユーザー情報を取得 if(check_user_role($current_user,'shop_owner')){ //編集者(editor)かチェック echo '<link rel="stylesheet" type="text/css" href="' .get_bloginfo('template_directory'). '/custom-admin-css2.css" />'; } if(check_user_role($current_user,'editor')){ //編集者(editor)かチェック echo '<link rel="stylesheet" type="text/css" href="' .get_bloginfo('template_directory'). '/custom-admin-css2.css" />'; } } 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; }
http://qiita.com/koh-taka@github/items/79309c1f367f00c425d8
if(is_post_type_archive( 'xxxxx' )){ //処理内容 }
//CSSで管理画面内のサイドメニューを非表示にする 権限指定 function custom_admin_styles(){ $current_user = wp_get_current_user(); //現在のユーザー情報を取得 if(check_user_role($current_user,'shop_owner')){ //チェック echo '<link rel="stylesheet" type="text/css" href="' .get_bloginfo('template_directory'). '/custom-admin-css2.css" />'; } } 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; }
custom-admin-css2.css
#menu-dashboard{ display: none; }
参考
http://mgzl.jp/2013/08/09/how-to-hide-the-unnecessary-item-from-the-side-menu-on-the-admin-page-of-wordpress/
非表示にしたい項目はChrome等の開発者ツールで見てもらうのが早いと思うが、一応下記にデフォルトで存在しているものを列挙する。
#menu-dashboard ダッシュボード
#menu-posts 投稿
#menu-media メディア
#menu-links リンク
#menu-pages 固定ページ
#menu-comments コメント
#menu-appearance 外観
#menu-plugins プラグイン
#menu-users ユーザー
#menu-tools ツール
#menu-settings 設定
.wp-menu-separator (区切り線)
後は管理画面にCSSを読みこませればいい。
//プラグインを全て非表示にする #menu-plugins{ display:none; } //プラグインのサブメニューの2つ目の項目を非表示にする #menu-plugins .wp-submenu li:nth-child(2){ display:none; } //更新可能なプラグインのアイコンを非表示にする #menu-plugins .update-plugins{ display:none; }
http://www.cseas.kyoto-u.ac.jp/info/2013/08/5210
特定サイドメニューの非表示(2013/08/27)
編集者にはいらないメニューは極力見えないようにしたいものです。
カスタム投稿、プラグインが追加したメニューなども消すことができます。
ここでは、「管理者以外」は、「コメント」「カスタム投稿(hogehogeと名前付けしていると仮定)」「Contact Form 7」「Subscribe2」のメニューを非表示にします。
function my_remove_menu(){
remove_menu_page(‘edit-comments.php’); // コメントの非表示
remove_menu_page(‘edit.php?post_type=hogehoge’); // カスタム投稿「hogehoge」の非表示
// プラグインによる追加の場合には、管理画面のid(<li id=”hogehoge-{slug}”>)のslugを指定すること
remove_menu_page(‘wpcf7’); // Contact form 7の「お問い合わせ」を非表示
remove_menu_page(‘s2’); // Subscribe2を非表示
}
// 管理者以外は指定メニューを消す
if(!current_user_can(‘administrator’))
add_action(‘admin_menu’, ‘my_remove_menu’);
プラグイン設定の上書き
WordPress Download Monitorで編集者に特定権限を付与(2013/08/27)
通常は、管理者ユーザしか使えません。これを編集者も使えるようにするための方法です。
下記の設定によって、追加と編集が可能になります。設定やログ閲覧は不可です。
function add_theme_caps() {
$role = get_role( ‘editor’ );
$role->add_cap( ‘user_can_edit_downloads’);
$role->add_cap( ‘user_can_add_new_download’);
$role->remove_cap( ‘user_can_config_downloads’);
$role->remove_cap( ‘user_can_view_downloads_log’);
}
add_action( ‘admin_init’, ‘add_theme_caps’);
ただし、一旦登録してしまうと設定をOFFにしても有効になります。
設定の追加は、add_capに、設定の削除はremove_capに明示しましょう。
TablePressで編集者への特定権限を削除(2013/08/27)
WP-Table Reloadedの後継にあたります。
全面的に書き直されたTablePressについては、いくつかの権限について上書きが可能です。
ここでは、「編集者、作成者は、テーブル削除、インポート、About閲覧を不可」にします。
function add_theme_caps2() {
foreach (array(‘editor’,’author’) as $user){
$role = get_role( $user );
$role->remove_cap( ‘tablepress_delete_tables’);
$role->remove_cap( ‘tablepress_import_tables’);
$role->remove_cap( ‘tablepress_access_options_screen’);
$role->remove_cap( ‘tablepress_access_about_screen’);
}
}
add_action( ‘admin_init’, ‘add_theme_caps2’);
何が出来るかについては、tablepressのソースフォルダ以下で「cap」をキーワードに検索してみてください。
メディア等で扱える拡張子の追加
プラグインを作って公式ディレクトリに登録しましたので、そちらを使って貰えればと思います。
WP Add Mime Types(2013年8月16日公開、日本語説明)
//メディア自分ののみ add_action( "pre_get_posts", "set_ajax_media_query" ); function set_ajax_media_query( $wp_query ) { global $current_user; if( $wp_query ->query_vars['post_type'] != "attachment" ) { return; } get_currentuserinfo(); if( $current_user->roles[0] == "administrator" ) { return; } $wp_query->query_vars['author'] = $current_user->ID; }
<a href="<?php echo get_post_type_archive_link( get_post_type() ); ?>"> <?php echo esc_html( get_post_type_object( get_post_type() )->label ); ?></a>
複数パン屑参考
http://ja.forums.wordpress.org/topic/5176
カテゴリーを情報取得後フォーチループ
<?php $category = get_the_category(); foreach( $category as $cat ){ // echo '<a href="ホームページのURL">Home</a> > '; echo '<a href="ホームページのURL/category/' . $cat->category_nicename . '/">'; echo $cat->cat_name; echo '</a> >'; echo the_title(); echo '<br />'; } ?>
フォーチの並び替え参考
http://masago.kir.jp/php20030119.php
ksort($category,SORT_STRING);//フォーチの並び替え指示 これ使用 asort($category,SORT_NUMERIC);//フォーチの並び替え指示 asort($category,SORT_STRING);//フォーチの並び替え指示 これ機能せず
フォーチの回数指定参考
http://www.geekzshu.com/php/509
例 $i = 0; $kiji = 5; foreach ($rss->items as $item ) { if($i >= $kiji){ break;} else{ $title = $item['title']; $link = $item['link']; echo "<li><a href="$link">$title</a></li>n"; $i++; } }
シングル用複数パン屑完成 0561仕様
<!--------------------------------------------------------------------------------------------------------------------------------------------------パンくずリスト---> <div id="top_navi"> <?php $urls = home_url(); $category = get_the_terms( 0, 'genre' ); ksort($category,SORT_STRING);//フォーチの並び替え指示 $i = 0; $kiji = 3;//この回数でフォーチ終わる。 foreach( $category as $cat ){ if($i >= $kiji){//siが3よりおおきくなったら break;}//ループおわり else{//それまではこれで出力 $urls2=get_term_link($cat->slug,'genre');//$urls2にゲットタームリんくでとったもの入れた。 echo '<a href="' .$urls. '">0561navi</a> > '; //$termにはいってる情報で分岐 if ( $cat->parent ) { // 親IDが入ってれば (子だったら) //親のIDを取得してターム情報を引き出す。 $ido=$cat->parent; $term2=get_term($ido,'genre'); ?> <a href="<?php //親のターム情報からターム名とリンクを引き出す。 echo get_term_link($term2->slug,'genre'); ?> "> <?php echo $term2->name; ?> </a> > <?php } echo '<a href="' .$urls2. '">'; echo $cat->name; echo '</a> > '; //echo the_title(); echo '<br />'; $i++;//多分繰り返すごとに$iに数値が1つづ増える }//回数指定終了 } ?> <div style="clear:both; padding-bottom:20px;"></div> </div>
ラベルからシングルネームを取り出して表示
<?php echo esc_html( get_post_type_object( get_post_type() )->labels->singular_name ); ?>
タームの場合ディスプリクションを使う
<?php //カテゴリー・タグ情報を取得(slug,アーカイブページでターム名取得,タクソノミー名取得) $term3 = get_term_by('slug',get_query_var( 'term' ),get_query_var( 'taxonomy' )); echo $term3->description; //現在ターム位置所得 ?>
カテゴリーの場合のコード
親カテゴリのIDが分かっている場合、 たとえば親カテゴリのIDが1のとき、
<?php wp_list_categories( 'child_of=1' ); ?>
親カテゴリはもちろん記事や子カテゴリによって違うわけです。 なので、親カテゴリデータ受け取り→加工の手順が必要です。
/* 現在のカテゴリ-の取得 */
$cat_now = get_the_category();
$cat_now = $cat_now[0];
/*親カテゴリーのID取得*/
$parent_id = $cat_now->category_parent;
- See more at: http://little.ws/200906/204.html#sthash.GAtaZEJG.dpuf
全部まとめると
<?php $cat_now = get_the_category(); $cat_now = $cat_now[0]; $parent_id = $cat_now->category_parent; ?> <?php wp_list_categories("title_li=&child_of=$parent_id"); ?>
引用
http://little.ws/200906/204.html
//タイトルを入力してくださいを変える function change_default_title( $title ) { $screen = get_current_screen(); if ( 'performer' == $screen->post_type ) { $title = 'パフォーマー名を入力してください。'; } else if ( $screen -> post_type == 'post' ) { $title = 'これは投稿だけ変更します'; } return $title; } add_filter('enter_title_here', 'change_default_title');
<?php //カテゴリー・タグ情報を取得(slug,アーカイブページでターム名取得,タクソノミー名取得) $term = get_term_by('slug',get_query_var( 'term' ),get_query_var( 'taxonomy' ) ); ?> <?php //$termにはいってる情報で分岐 if ( $term->parent ) { // 親IDが入ってれば (子だったら) ?> <!---TOP部分--> <?php //親のIDを取得してターム情報を引き出す。 $ido=$term->parent; $term2=get_term($ido,get_query_var( 'taxonomy' )); ?> <a href="<?php //子 親のターム情報からターム名とリンクを引き出す。 echo get_term_link($term2->slug,get_query_var( 'taxonomy' )); ?> "> <?php echo $term2->name; ?> </a> <div style="clear:both"></div> <!---一覧部分--> <?php wp_list_categories( array( 'title_li' => '', 'taxonomy' => get_query_var( 'taxonomy' ), 'child_of' => $term->parent,//親のIDを出力 'hide_empty' => 0, ) ); } else { //親だったらそのまま出力 ?> <!---TOP部分--> <a href="<?php //親 echo get_term_link($term->slug,get_query_var( 'taxonomy' )); ?> "> <?php echo $term->name; ?> </a> <div style="clear:both"></div> <!---一覧部分--> <?php wp_list_categories( array( 'title_li' => '', 'taxonomy' => get_query_var( 'taxonomy' ), 'child_of' => $term->term_id, 'hide_empty' => 0, ) ); }?>
タダ見つけたさんこう
http://blog.cgfm.jp/garyu/archives/2001こっから引用下記
<?php //カスタム投稿タイプの場合slugを取得 $post_type = get_post_type(); //取得結果: 'event' //カスタム投稿タイプのラベルを取得 $post_type_object = get_post_type_object($post_type); $post_type_label = $post_type_object->label; //取得結果:'イベント情報' //クエリからtaxonomy(カスタム分類タクソノミー)のslug取得 $taxonomy_var = get_query_var('taxonomy'); //取得結果:'event-category' //クエリからterm(カスタム分類タクソノミー内のカテゴリ)のslug取得 $term_var = get_query_var( 'term' ); //取得結果:'workshop' //termの情報を取得 $my_term = get_term_by('slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); //termのラベルを取得 $term_name = $my_term->name; //取得結果:'ワークショップ' ?>
http://ja.forums.wordpress.org/topic/7806
ここ参照
<?php $term = get_term_by('slug',get_query_var( 'term' ),get_query_var( 'taxonomy' ) ); ?> <?php if ( $term->parent ) { // 子? $posts = get_posts( array( 'taxonomy' => get_query_var( 'taxonomy' ), 'term' => get_query_var( 'term' ), ) ); ?><ul><?php foreach ( (array) $posts as $post ) : setup_postdata( $post ); printf('<li><a href="%1$s">%2$s</a></li>', esc_url( get_permalink( get_the_ID() ) ), esc_html( get_the_title( get_the_ID() ) ) ); endforeach; ?></ul><?php wp_reset_postdata(); } else { wp_list_categories( array( 'taxonomy' => get_query_var( 'taxonomy' ), 'child_of' => $term->term_id, 'hide_empty' => 0, ) ); }?>