Google Chromeを開いたら「Ctrl」「Shift」「Delete」を同時に押して「閲覧履歴データの削除」を開き削除します。
それだけのこと
カテゴリー: Wordpress
Ajax Load More(Repeater Templates)
URLをカスタムフィールドとして取り出す場合の例
2行名のURL部分がカスタムフィールドのケース
<li class="load_more_box"> <a href="<?php $hoge = get_post_meta(get_the_ID(),'url',true); echo $hoge;?>" target="_brank"> <h3 class="load_more_img"><?php if ( has_post_thumbnail() ) { the_post_thumbnail('large'); }?></h3> <h4><?php the_title(); ?></h4> </a> </li>
<li class="load_more_box"> <?php $hoge = get_post_meta(get_the_ID(),'url',true); if($hoge != ''){ echo '<a href="'.$hoge.'" target="_brank">'; } ?> <h3 class="load_more_img"><?php if ( has_post_thumbnail() ) { the_post_thumbnail('large'); }?></h3> <h4><?php the_title(); ?></h4> <?php $hoge = get_post_meta(get_the_ID(),'url',true); if($hoge != ''){ echo '</a>'; } ?> </li>
Ajax Load More でカテゴリを指定する
Ajax Load More
Shortcode Builder
↓
Query Parameters
上から3つ目くらいに「Category」欄がある
WordPressのカテゴリタイトルから「カテゴリー:」を消す
WordPressのカテゴリページやタグページのタイトルには、タイトルの頭に「カテゴリー:」や「タグ:」
functions.php に下記を追記
add_filter( 'get_the_archive_title', function ($title) { if ( is_category() ) { $title = single_cat_title( '', false ); } elseif ( is_tag() ) { $title = single_tag_title( '', false ); } elseif ( is_author() ) { $title = '' . get_the_author() . '' ; } return $title; });
wordpress の URL関連変数
1.URLの記載方法(HTML、リンク) Wordpressの場合 手打ちの固定URLではなく、Wordpress変数で書くことが基本 誤り例) https://okusuri24.net/login/ 正解例) <?php echo site_url(); ?>/login/ (Wordpressテンプレートの基礎です) 2.URLの記載方法(HTML、Themeディレクトリ配下の”ファイル・画像”のURL) 誤り例) https://okusuri24.net/wp-content/themes/hueman-child/image/icn_4arrow.png 正解例) <?php echo get_parent_theme_file_uri(); ?>/image/icn_4arrow.png (Wordpressテンプレートの基礎です) 3.URLの記載方法(CSS、画像URL) CSSに記載するURLは、「CSSファイルからの相対Pathで記載する」 誤り例) https://okusuri24.net/wp-content/themes/hueman-child/image/icn_4arrow.png 正解例) ./image/icn_4arrow.png (一般CSSの基礎です) いずれも、とりあえずは動きますが、Wordpressの基本機能を潰す行為になり、後々困るので
記事(投稿)のカテゴリIDを取得する
WordPressで記事(投稿)のカテゴリIDを取得する
$category = get_the_category(); $cat_id = $category[0]->cat_ID; echo $cat_id;
WordPress、ショートコードでPHPファイルを読み込む
下記のように、Themeディレクトリの functions.php 末尾に追記する
function shortcode_include_php(){ ob_start(); include(STYLESHEETPATH . "/php/index.php"); return ob_get_clean(); } add_shortcode('include_php', 'shortcode_include_php');
表示したい投稿や固定ページに [include_php] と書けば読み込まれる
ファイル権限(オーナー、www-data)の変更
www-data などで権限を変更したい場合
wordpress が吐き出す .htaccess でよく利用する
# chmod -R 777 ./○○○/* # 62 chmod g+w -R ./○○○/*
※ 末尾の「*(アスタリスク、ワイルドカード)」は隠しファイル(.htaccess)には効かないので、ファイル名を叩くor 「.*」とすると有効
POST,GETで表示がエラーになる
WordPress の場合、予約変数とかぶるとエラーになる
代表的な予約言
- author
- calendar
- cat
- category
- customized
- day
- fields
- hour
- minute
- more
- name
- order
- page
- post
- preview
- search
- second
- year
Unknown collation: ‘utf8mb4_unicode_520_ci’
原因は移行先サーバーのMySQLがMySQL5.5以下であるためです。例えば某Sサーバーなど..。utf8mb4_unicode_520_ciというcollationはMySQL5.6以上でしか利用できません。
現行のWordPressはutf8mb4_unicode_520_ciが使用できるサーバーではutf8mb4_unicode_520_ciを優先的に使用してインストールを行います。charsetとcollationを決定するwp-db.phpのコードは以下のようになっています。
/** * Determines the best charset and collation to use given a charset and collation. * * For example, when able, utf8mb4 should be used instead of utf8. * * @since 4.6.0 * @access public * * @param string $charset The character set to check. * @param string $collate The collation to check. * @return array The most appropriate character set and collation to use. */ public function determine_charset( $charset, $collate ) { if ( ( $this->use_mysqli && ! ( $this->dbh instanceof mysqli ) ) || empty( $this->dbh ) ) { return compact( 'charset', 'collate' ); } if ( 'utf8' === $charset && $this->has_cap( 'utf8mb4' ) ) { $charset = 'utf8mb4'; } if ( 'utf8mb4' === $charset && ! $this->has_cap( 'utf8mb4' ) ) { $charset = 'utf8'; $collate = str_replace( 'utf8mb4_', 'utf8_', $collate ); } if ( 'utf8mb4' === $charset ) { // _general_ is outdated, so we can upgrade it to _unicode_, instead. if ( ! $collate || 'utf8_general_ci' === $collate ) { $collate = 'utf8mb4_unicode_ci'; } else { $collate = str_replace( 'utf8_', 'utf8mb4_', $collate ); } } // _unicode_520_ is a better collation, we should use that when it's available. if ( $this->has_cap( 'utf8mb4_520' ) && 'utf8mb4_unicode_ci' === $collate ) { $collate = 'utf8mb4_unicode_520_ci'; } return compact( 'charset', 'collate' ); }
対策・解決方法
インポートするSQLファイルをエディタで開き、以下のように置き換えます。
utf8mb4_unicode_520_ci → utf8_general_ci
utf8mb4 → utf8
[参考]
カスタムフィールドの住所からGoogleMAPを表示する
カスタムフィールドの住所からGoogleMAPを表示する
<iframe src="https://maps.google.co.jp/maps?output=embed&q=<?php echo get_post_meta($post->ID , 'フィールド名' ,true); ?>&z=14" width="1000" height="600" frameborder="0" scrolling="no" ></iframe>
カスタムフィールドの値を表示する(チェックボックス、複数選択)
カスタムフィールドでチュエックボックス(複数選択)の値を表示する。
<?php $colors = get_field('detail_lable'); if ($colors): ?> <ul> <?php foreach ($colors as $color) : ?> <?php echo $color; ?> / <?php endforeach; ?> </ul> <?php endif; ?>
カスタムフィールドの値を表示する(繰り返しフィールド、画像)
カスタムフィールドの値を表示する
繰り返しフィールドで、画像の場合
<?php $rows = get_field('フィールド名' ); for($i = 0; $rows[$i] != ''; $i ++){ $row = $rows[$i]; $image = $row['サブフィールド名']; // echo '<pre>'; // var_dump($image); // echo '</pre>'; echo '<div style="margin-top:20px;">'.$image[title].'<div>'; echo '<img src="'.$image[url].'" alt="'.$image[title].'" />'; } ?>
wordpress の変数を PHP に渡すいろいろ
wordpress で何かを表示する情報は多いのですが
PHP変数に渡すというのは、情報が少ないので、ここにまとめていこうと思う
ID(post_ID、記事ID)
<?php $post_id = get_the_ID(); ?>
タイトル
<?php $car_name = the_title('', '', false); ?>
wordpressの管理画面にページを増やす
wordpressの管理画面に「ページ、メニュー」を増やす方法
1つだけ増やす例は沢山公開されているが、複数の場合は下記のように書く
function.php の最後に書きます。
// ページの追加 add_action( 'admin_menu', 'register_my_custom_menu_page' ); function register_my_custom_menu_page() { add_menu_page('管理画面の使い方', '予約管理', 'manage_options', 'yoyaku', 'add_manual_page', 'dashicons-welcome-learn-more', 3); add_menu_page('顧客管理の使い方', '顧客管理', 'manage_options', 'customer', 'add_manual_page2', 'dashicons-welcome-learn-more', 3); } // ページの中身のHTML function add_manual_page() { include('../yoyakukanri.php'); } function add_manual_page2() { include('../customer.php'); }
wordpressで「ログイン状態を保存する」が解除されてしまう
使っている theme の function.php に、下記のコードを追記することで
ログイン状態を維持できるようになる
function wplogin_rememberme_checked() {?> <script src="//code.jquery.com/jquery-1.11.1.js"></script> <script> $(document).ready(function(){ $('#rememberme').prop('checked', true); }); </script> <?php } add_action( 'login_enqueue_scripts', 'wplogin_rememberme_checked' );
WordPressでカテゴリ毎に公開・非公開を変更
<?php include ('./wp-config.php'); $pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8', DB_USER, DB_PASSWORD); // 該当カテゴリのPOST_IDの配列を生成 $post_id_array = array(); $sql = "SELECT * FROM `mint_term_relationships` WHERE `term_taxonomy_id` = '2'"; // カテゴリIDを指定 foreach($pdo->query($sql) as $item) { array_push($post_id_array, $item[object_id]); } var_dump($post_id_array); // 公開フラグを変更する for($i = 0; $post_id_array[$i] != ''; $i ++){ // 公開 // $sql = "UPDATE `mint_posts` SET `post_status` = 'publish', `comment_status` = 'open', `ping_status` = 'open' WHERE `ID` = '$post_id_array[$i]'"; // 非公開 $sql = "UPDATE `mint_posts` SET `post_status` = 'inherit', `comment_status` = 'closed', `ping_status` = 'closed' WHERE `ID` = '$post_id_array[$i]'"; $statement = $pdo->query($sql); } ?>
指定カテゴリの記事一覧、アイキャッチ有り
<?php $cat = 'カテゴリスラッグ'; $num = '5'; global $post; $term_id = get_category_by_slug($cat)->term_id; $myposts = get_posts('numberposts=' .$num. '&category_name=' .$cat); if ($myposts) { foreach($myposts as $post): setup_postdata($post); echo '<li><div class="blog_thumb"><a href=' .get_permalink(). '>'; if ( has_post_thumbnail() ) { echo ''.get_the_post_thumbnail($page->ID, 'thumbnail'). ''; } else { echo '<span class="no_image"><i class="fa fa-ban fa-2x" aria-hidden="true"></i> No images</span>'; } echo '</a></div><div class="blog_data">'; echo '<div class="blog_date">' .get_the_time('Y/n/j').'</div>'; echo '<div class="blog_tit"><a href='.get_permalink().'>'. the_title("","",false).'</a></div>'; echo '<div class="blog_content">' .mb_substr( strip_tags( $post -> post_content ), 0, 100 ). '...</div></div></li>'; endforeach; echo '</ul><p><a href=' .get_category_link($term_id). '>カテゴリの一覧 ≫</a></p>'; } else { echo '<p>記事がありません。</p>'; } ?>
WordPressでpathやURLを取得するためのタグと出力例
関数 | 解説 | 出力 |
---|---|---|
ABSPATH | インストールされた場所のパス | C:\xampp\htdocs\xampp\example/(ローカルの場合) /var/www/html/example/(サーバの場合) |
admin_url() | 管理画面のパス | http://www.example.com/wp-admin/ |
content_url() | wp-contentディレクトリのパス | http://www.example.com/wp-content |
get_attachment_link( $id ) | 添付ファイルのIDを渡すと添付ページの URI を返す | http://www.example.com/?attachment_id=$id |
get_author_posts_url( $author ) | 投稿者別のアーカイブページへのリンク。投稿者名を入力する | http://www.example.com/?author=0 |
get_bloginfo( $show ) | デフォルトはnameでサイト名が返ってくる。変数による違いは以下の通り。 | http://localhost/xampp/example |
$show = ‘admin_email’ | admin@example.com | |
$show = ‘atom_url’ | http://www.example.com/home/feed/atom | |
$show = ‘charset’ | UTF-8 | |
$show = ‘comments_atom_url’ | http://www.example.com/home/comments/feed/atom | |
$show = ‘comments_rss2_url’ | http://www.example.com/home/comments/feed | |
$show = ‘description’ | Just another WordPress blog | |
$show = ‘home’ | http://www.example.com/home (DEPRECATED! use url option instead) | |
$show = ‘html_type’ | text/html | |
$show = ‘language’ | en-US | |
$show = ‘name’ | Testpilot | |
$show = ‘pingback_url’ | http://www.example.com/home/wp/xmlrpc.php | |
$show = ‘rdf_url’ | http://www.example.com/home/feed/rdf | |
$show = ‘rss2_url’ | http://www.example.com/home/feed | |
$show = ‘rss_url’ | http://www.example.com/home/feed/rss | |
$show = ‘siteurl’ | http://www.example.com/home (DEPRECATED! use url option instead) | |
$show = ‘stylesheet_directory’ | http://www.example.com/home/wp/wp-content/themes/largo | |
$show = ‘stylesheet_url’ | http://www.example.com/home/wp/wp-content/themes/largo/style.css | |
$show = ‘template_directory’ | http://www.example.com/home/wp/wp-content/themes/largo | |
$show = ‘template_url’ | http://www.example.com/home/wp/wp-content/themes/largo | |
$show = ‘text_direction’ | ltr | |
$show = ‘url’ | http://www.example.com/home | |
$show = ‘version’ | 3.5 | |
$show = ‘wpurl’ | http://www.example.com/home/wp | |
get_category_link( $id ) | カテゴリーアーカイブページヘのリンク | http://www.example.com/?cat=0 |
get_day_link( $year, $month, $day ) | 日別アーカイブページのリンク。デフォルトは現在の日。 | http://www.example.com/?m=20150313 |
get_edit_user_link( $user_id ) | ユーザー情報編集画面用のパス | http://www.example.com/wp-admin/profile.php |
get_feed_link() | FeedのURLを取得 | http://www.example.com/?feed=rss2 |
get_month_link( $year, $month ) td> | 年別アーカイブページのリンク。デフォルトは現在の年度。 | http://www.example.com/?m=201503 |
get_page_link( $id ) | 固定ページのパーマリンクを取得 | http://www.example.com/?page_id=$id |
get_permalink( $id ) | $idを入力するとURLのスラッグを返す。パーマリンク設定によって異なる | http://www.example.com/?p=$id |
get_post_type_archive_link( $posttype ) | カスタム投稿タイプのアーカイブページを返す。get_post_type_archive_link( get_post_type() )など | http://www.example.com/$posttype |
get_stylesheet() | 現在適用されているテーマ(スタイルシート)のディレクトリ | twentyten-child |
get_stylesheet_directory() | 現在適用されているテーマ(スタイルシート)のディレクトリ | /var/www/html/example/wp-content/themes/twentyten-child |
get_stylesheet_directory_uri() | 現在適用されているテーマをURI表記で返す | http://www.example.com/wp-content/themes/twentyten-child |
get_stylesheet_uri() | 現在適用されているテーマ(スタイルシート)のパス | /var/www/html/example/wp-content/themes/twentyten-child/style.css |
get_tag_link( $id ) | タグアーカイブページヘのリンク。IDで指定してスラッグで返ってくる。 | http://www.example.com/?tag=wordpress |
get_template_directory() | 親テーマのディレクトリ | /var/www/html/example/wp-content/themes/twentyten |
get_template_directory_uri() | 親テーマのURI | http://www.example.com/wp-content/themes/twentyten |
get_term_link( $id ) | カスタム分類アーカイブページヘのリンク。タクソノミーが無いとWP_Error Objectを返す | http://www.example.com/custom-taxonomy |
get_theme_root() | テーマのディレクトリ | /var/www/html/example/wp-content/themes |
get_theme_root_uri() | 親テーマのディレクトリ | http://www.example.com/wp-content/themes |
get_year_link( $year ) | 年別アーカイブページのリンク。デフォルトは現在の年度。 | http://www.example.com/?m=2015 |
home_url( $path, $scheme ) | $pathにはホームURLからの相対パス。$schemeはhttpかhttpsもしくはrelative(相対パス) | http://www.example.com/$path |
includes_url() | wp-includesのディレクトリを返す | http://www.example.com/wp-includes/ |
plugin_dir_path( __FILE__ ) | 現在のファイルのディレクトリを返す。pluginファイルに書けばプラグインのパスを返すが、必ずしもpluginのディレクトリを返すとは限らない | /var/www/html/example/wp-content\themes\twentyten-child/ |
plugins_url() | プラグインディレクトのパス | http://www.example.com/wp-content/plugins |
site_url() | サイトのアドレスを表示。スラッシュは付かない | http://localhost/xampp/example |
the_permalink() | 現在のページのパス | http://www.example.com/ |
WP_CONTENT_DIR | wp-contentディレクトリのパス | /var/www/html/example/wp-content |
wp_get_shortlink( $id ) | 短縮URL、ショートリンクを表示する。パーマリンク設定で長いスラッグにしている場合に外部プログラムへ短いURLを渡したい場合などに使う | http://www.example.com/?p=$id |
WP_LANG_DIR | languagesディレクトリのパス | /var/www/html/example/wp-content/languages |
wp_login_url() | ログイン画面のパス | http://www.example.com/wp-login.php |
wp_logout_url() | ログアウト用のパス | http://www.example.com/wp-login.php?action=logout&_wpnonce=0000000000 |
wp_lostpassword_url() | ログアウト用のパス | http://www.example.com/wp-login.php?action=lostpassword |
WP_PLUGIN_DIR | プラグインディレクトのパス | /var/www/html/example/wp-content/plugins |
wp_registration_url() | ユーザー登録用のパス | http://www.example.com/wp-login.php?action=register |
wp_upload_dir($time) | アップロードディレクトリ URL。配列で返ってくる。$timeはデフォルトはnull。$time = ‘path‘ | /var/www/html/example/wp-content/uploads |
$time = ‘url‘ | http://www.example.com/wp-content/uploads | |
$time = ‘subdir‘ | ||
$time = ‘basedir‘ | /var/www/html/example/wp-content/uploads | |
$time = ‘baseurl‘ | http://www.example.com/wp-content/uploads | |
$time = ‘error‘ | bool(false) |
WordPressのリビジョン機能を停止する
WordPressのリビジョン機能は、編集するたびに、以前の状態を保存されます。
編集画面を開いていると、数分に一度、自動保存もされます。
1つの記事に対し、数十から数百に及ぶこともあり、データベースの肥大化、動作が重くなる原因となります。
リビジョン削除のプラグインもありますが、プラグインを増やすことも動作が重くなる要因なので
ソースコードで停止する方法です。
wp-config.php に次の一行を追記します。
define('WP_POST_REVISIONS', false);
※ ABSPATH よりも前に記載しないと効きません。
welcart 商品の並び順をドラッグアンドドロップで変える
商品マスタ(商品一覧)のテンプレートファイル
/wp-content/plugins/usc-e-shop/includes/usces_item_master_list.php
詳細
/home/hashimoto/www/yoga-lien.com/wp-content/plugins/usc-e-shop/js にファイルを追加
jquery-1.8.0.min.js
jquery-ui.js
商品一覧のテンプレート(一覧大規模変更)
/home/hashimoto/www/yoga-lien.com/wp-content/plugins/usc-e-shop/includes/usces_item_master_list.php
// 並び替えページ
”usces_item_popup.php”を追加(新設)した。
”itemList.class.php” にてソート順を変更した
手法:$rows[L:410付近]の並び順を変えることで成功!
DB wp_posts.to_ping 型をtext → int に変更
// Heart-Lab Start //------------------------------------------------- /* echo '<pre>'; var_dump($rows); echo '</pre>';*/ // 商品IDのソート順 $id_array = array(); $pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8', DB_USER, DB_PASSWORD); $sql = "SELECT * FROM `wp_posts` WHERE `post_mime_type` = 'item' AND `post_type` = 'post' AND `post_status` = 'publish' ORDER BY `to_ping` ASC"; foreach($pdo->query($sql) as $item) { // echo $item[ID].' -- '; array_push($id_array, $item[ID]); } // var_dump($id_array); // $rows の並び順を変える for($i = 0; $id_array[$i] != ''; $i ++){ for($a = 0; $rows[$a] != ''; $a ++){ if($id_array[$i] == $rows[$a][ID]){ $new_rows[$i][ID] = $rows[$a][ID]; $new_rows[$i][item_code] = $rows[$a][item_code]; $new_rows[$i][item_name] = $rows[$a][item_name]; } } } // echo '<pre>'; // var_dump($new_rows); // echo '</pre>'; $rows = $new_rows; // Heart-Lab END //-------------------------------------------------
”usces_item_popup.php”
<html lang="ja" class="no-js"><head><meta charset="UTF-8"> <!-- WR --> <style> a { color: gray; } .wr_menu li { display: inline-block; margin: 0 20px 30px 0; } .ns { display: block; float: left; border: 1px solid silver; width: 500px; height: 60px; background: white; overflow: hidden; margin: 0 0 5px 0; } .w100 { display: block; float: left; width: 80px; } .w200 { display: block; float: left; width: 300px; overflow: hidden; } #tablenavi { display: none; } </style> </head> <body> <?php error_reporting(E_ALL & ~E_NOTICE); $act1 = ''; $act2 = ''; $act3 = ''; if($_GET["wr"] == 'lesson'){ $act1 = ' style="color:red;font-weight: bold"'; }elseif($_GET[wr] == 'shopping'){ $act2 = ' style="color:red;font-weight: bold"'; }else{ $act3 = ' style="color:red;font-weight: bold"'; } echo '<div class="wr_menu">'; echo '<li><a href="?page=usces_itemedit&wr=all"'.$act3.'>All</a></li>'; echo '<li><a href="?page=usces_itemedit&wr=lesson"'.$act1.'>Lesson</a></li>'; echo '<li><a href="?page=usces_itemedit&wr=shopping"'.$act2.'>Shopping</a></li>'; echo '</div>'; ?> <script type="text/javascript"> <!-- function p_reload(){ var pwin=window.opener; pwin.location.reload(); pwin.focus(); window.close(); } //--> </script> <button type="button" onclick="p_reload()" style="float: right;">閉じる</button> <br><br> <form action="" method="post"> <input type="submit" id="submit" value="並び順を保存する" onClick="alert('並べ替え完了です')"/> <ul class="sortable"> <!-- WR --> <?php include("../../../../wp-config.php"); $pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8', DB_USER, DB_PASSWORD); // 並べ替え if($_POST[result] != ''){ $sort_ids = explode(",", $_POST[result]); for($i = 0; $sort_ids[$i] != ''; $i ++){ if($_GET[wr] == 'shopping'){ $a = $i; }else{ $a = $i + 10000; } $sql = "UPDATE `wp_posts` SET `to_ping` = '$a' WHERE `ID` = '$sort_ids[$i]'"; $statement = $pdo->query($sql); } } $sql = "SELECT * FROM `wp_posts` WHERE `post_mime_type` = 'item' AND `post_type` = 'post' AND `post_status` = 'publish' ORDER BY `to_ping` ASC"; foreach($pdo->query($sql) as $item) { $print_flg = 0; if($_GET[wr] == 'shopping'){ $sql2 = "SELECT * FROM `wp_term_relationships` WHERE `object_id` = '$item[ID]' AND `term_taxonomy_id` = '5'"; $statement2 = $pdo->query($sql2); $item2 = $statement2->fetch(PDO::FETCH_ASSOC); if($item2[object_id] != ''){ $print_flg = 1; } } if($_GET[wr] == 'lesson'){ $sql2 = "SELECT * FROM `wp_term_relationships` WHERE `object_id` = '$item[ID]' AND `term_taxonomy_id` = '3'"; $statement2 = $pdo->query($sql2); $item2 = $statement2->fetch(PDO::FETCH_ASSOC); if($item2[object_id] != ''){ $print_flg = 1; } } if( ($_GET[wr] == '') || ($_GET[wr] == 'all') ) $print_flg = 1; if($print_flg == 1){ // 商品情報取得 $sql2 = "SELECT * FROM `wp_postmeta` WHERE `post_id` = '$item[ID]' AND `meta_key` = '_isku_'"; $statement2 = $pdo->query($sql2); $item2 = $statement2->fetch(PDO::FETCH_ASSOC); $hoge = explode(";", $item2[meta_value]); $wr_array = array(); for($i = 0; $hoge[$i] != ''; $i ++){ $hhh = explode('"', $hoge[$i]); // echo $i.'> '.$hhh[1].'<br>'; array_push($wr_array, $hhh[1]); } $ID = $item["ID"]; ///////idのようなモノ $code = $wr_array[1]; $price = number_format($wr_array[7]); $stock_num = number_format($wr_array[11]); // 在庫有無 if($stock_num == 0){ $stock_text = '<span style="color:red;">在庫切れ</span>'; }else{ $stock_text = '.'; } // 公開状態 if($item[post_status] == 'publish'){ $open_text = '公開'; }else{ $open_text = '<span style="color:red;">非公開</span>'; } // カテゴリ $sql3 = "SELECT * FROM `wp_term_relationships` WHERE `object_id` = '$ID' AND `term_taxonomy_id` != '2'"; $statement3 = $pdo->query($sql3); $item3 = $statement3->fetch(PDO::FETCH_ASSOC); $sql4 = "SELECT * FROM `wp_terms` WHERE `term_id` = '$item3[term_taxonomy_id]'"; $statement4 = $pdo->query($sql4); $item4 = $statement4->fetch(PDO::FETCH_ASSOC); $category = $item4[name]; // 画像 $sql2 = "SELECT * FROM `wp_postmeta` WHERE `post_id` = '$item[ID]' AND `meta_key` = '_thumbnail_id'"; $statement2 = $pdo->query($sql2); $item2 = $statement2->fetch(PDO::FETCH_ASSOC); $sql2 = "SELECT * FROM `wp_posts` WHERE `ID` = '$item2[meta_value]'"; $statement2 = $pdo->query($sql2); $item2 = $statement2->fetch(PDO::FETCH_ASSOC); $img = $item2[guid]; $post_name = $item2[post_title]; // url $sql2 = "SELECT * FROM `wp_options` WHERE `option_name` = 'siteurl'"; $statement2 = $pdo->query($sql2); $item2 = $statement2->fetch(PDO::FETCH_ASSOC); $http_url = $item1[option_value]; $item[post_title] = mb_strimwidth( $item[post_title], 0, 85, '…','UTF-8' ); echo '<li class="ns" id="'.$ID.'"> <div class="w100"><img src="'.$img.'" width="60" alt=" IMG"></div> <div class="w100">'.$ID.'</div> <div class="w200">'.$code.'<br>'.$item[post_title].'</div> <!-- <div class="w100">'.$price.'</div> <div class="w100">'.$stock_num.'</div> <div class="w100">'.$stock_text.'</div> <div class="w100">'.$category.'</div> <div class="w100">'.$open_text.'</div> --> </li><!-- ----リスト---- -->'; } } ?> <?php // url $sql2 = "SELECT * FROM `wp_options` WHERE `option_name` = 'siteurl'"; $statement2 = $pdo->query($sql2); $item2 = $statement2->fetch(PDO::FETCH_ASSOC); $http_url = $item2[option_value]; ?> <!-- WR --> </ul> <input type="hidden" id="result" name="result" /> </form> <script src="<?php echo $http_url; ?>/wp-content/plugins/usc-e-shop/js/jquery-1.8.0.min.js"></script> <script src="<?php echo $http_url; ?>/wp-content/plugins/usc-e-shop/js/jquery-ui.js"></script> <script> $(function() { $(".sortable").sortable(); $(".sortable").disableSelection(); $("#submit").click(function() { var result = $(".sortable").sortable("toArray"); $("#result").val(result); $("form").submit(); }); }); </script> <div style="clear:both;"></div> <!-- <pre> <?php var_dump($_POST); ?> </pre> --> <!-- WR -->
welcart 商品順番をドラッグで変更する
Welcart の商品情報の取り出し方
商品名、説明などは、wp-posts に記録され、その他の情報は wp-postmeta に記録されています。
例)データベース
// 商品情報取得 $sql2 = "SELECT * FROM `wp_postmeta` WHERE `post_id` = '$item[ID]' AND `meta_key` = '_isku_'"; $statement2 = $pdo->query($sql2); $item2 = $statement2->fetch(PDO::FETCH_ASSOC); $hoge = explode(";", $item2[meta_value]); $wr_array = array(); for($i = 0; $hoge[$i] != ''; $i ++){ $hhh = explode('"', $hoge[$i]); // echo $i.'> '.$hhh[1].'<br>'; array_push($wr_array, $hhh[1]); }
上記のような方法で整形したデータ
0> code 1> L-20170926 2> name 3> 4> cprice 5> 6> price 7> 1500 8> unit 9> 10> stocknum 11> 8 12> stock 13> 0 14> gp 15> 0 16> sort 17> 0 18>
WordPressでログインURLを変える
1) TOPディレクトリに「heart-lab-login.php」というファイルを作る。
内容は下の通り。
<?php define( 'ANYWHERE_LOGIN', sha1( 'keyword' ) ); require_once './wp-login.php'; ?>
2) テーマファイルのfunction.php に下記を追記する
define( 'ANYWHERE_LOGIN_PAGE', 'heart-lab-login.php' ); add_action( 'login_init', 'heart_lab_login_init' ); add_filter( 'site_url', 'heart_lab_login_site_url', 10, 4 ); add_filter( 'wp_redirect', 'heart_lab_login_wp_redirect', 10, 2 ); if ( ! function_exists( 'heart_lab_login_init' ) ) { function heart_lab_login_init() { if ( !defined( 'ANYWHERE_LOGIN' ) || sha1( 'keyword' ) != ANYWHERE_LOGIN ) { status_header( 403 ); exit; } } } if ( ! function_exists( 'heart_lab_login_site_url' ) ) { function heart_lab_login_site_url( $url, $path, $orig_scheme, $blog_id ) { if ( ( $path == 'wp-login.php' || preg_match( '/wp-login\.php\?action=\w+/', $path ) ) && ( is_user_logged_in() || strpos( $_SERVER['REQUEST_URI'], ANYWHERE_LOGIN_PAGE ) !== false ) ) $url = str_replace( 'wp-login.php', ANYWHERE_LOGIN_PAGE, $url ); return $url; } } if ( ! function_exists( 'heart_lab_login_wp_redirect' ) ) { function heart_lab_login_wp_redirect( $location, $status ) { if ( strpos( $_SERVER['REQUEST_URI'], ANYWHERE_LOGIN_PAGE ) !== false ) $location = str_replace( 'wp-login.php', ANYWHERE_LOGIN_PAGE, $location ); return $location; } }
3) その結果
「wp-admin」「wp-login.php」は403になるので安全です。
twentysixteen の要なファイルのありか
twentysixteen/template-parts に重要なファイルがある。
biography.php
content.php
content-none.php
content-page.php
Includeタグ
get_template_part('content');
WordPress[twentysixteen] テーマのリセットCSS
twentysixteen
html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp, small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, figcaption, figure, footer, header, hgroup, menu, nav, section, summary, time, mark, audio, video { margin:0; padding:0; border:0; outline:0; font-size:100%; vertical-align:baseline; background:transparent; } body { line-height:1; } article,aside,details,figcaption,figure, footer,header,hgroup,menu,nav,section { display:block; } nav ul { list-style:none; } blockquote, q { quotes:none; } blockquote:before, blockquote:after, q:before, q:after { content:''; content:none; } a { margin:0; padding:0; font-size:100%; vertical-align:baseline; background:transparent; } / change colours to suit your needs / ins { background-color:#ff9; color:#000; text-decoration:none; } / change colours to suit your needs / mark { background-color:#ff9; color:#000; font-style:italic; font-weight:bold; } del { text-decoration: line-through; } abbr[title], dfn[title] { border-bottom:1px dotted; cursor:help; } table { border-collapse:collapse; border-spacing:0; } /* change border colour to suit your needs */ hr { display:block; height:1px; border:0; border-top:1px solid #cccccc; margin:1em 0; padding:0; } input, select { vertical-align:middle; } .skip-link, .menu-toggle, .site-header-menu { display: none; } /* カラム設定 -------------------------------------------------*/ #masthead { width: 100%; } .site-header-main { max-width: 1000px; margin: 0 auto; border: 1px solid silver; } #content { width: 100%; margin: 20px 0 40px 0; } #content_inner { max-width: 1000px; margin: 0 auto; border: 1px solid silver; } #footer { width: 100%; } #footer_inner { max-width: 1000px; margin: 0 auto; border: 1px solid silver; }
”perth” WordPress テーマ編集のコツ
メイン画像のサイズ変更
要は、TP_DIR/inc/style.php Line:42付近
//Body size $header_height = get_theme_mod( 'header_height', '600' );
WordPressでmod_rewriteが効かない
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /web1.download/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /web1.download/index.php [L] </IfModule> # END WordPress
WordPressでパーマリンクが有効にならない時
mod_rewriteが効かないと勘違いしやすい
サーバー設定かと思い「http.conf」などを見て、動かいないはずがない、変だぞ!
そんなことにハマるケースも多いです。
.htaccess を見ても文法ばかりを気にして、ドメインが違っているなんて、気づきにくいことかもしれません。
またハマってしまったので。。。
4行目、8行目にドメインが記載されています。
カスタムフィールドの保存方法を見てみよう!
カスタムフィールドは、wp_options というテーブルに保存されます。サイトの基本情報やプラグイン、テーマファイルなど、様々な設定情報と同じテーブルに保存されています。書き方も暗号かとおもうほど複雑難解です。慣れれば読めるようになります。
しかし、画像の場合ここには保存されずにIDのみが保存されます。
記事やページを記録する wp-posts というテーブルに保存されていますので、上記から抽出したIDを元にソートをかけると、やっと目的の画像ファイル名にたどり着けます。
↓wp_options
wordpress のデータベース構造は最小公倍数に設計されているのでとてもシンプルですが、構造がシンプルな代わりに保存方法が無限にありますので解析するにはかなりの熟練が必要です。
特定カテゴリを指定して記事一覧を表示する
<ul> <?php $category_recent_post = 5; // 記事数 $category_recent_id = 1; // カテゴリID $posts = get_posts('numberposts=' . $category_recent_post . '&category=' . $category_recent_id); global $post; if($posts) { foreach($posts as $post) { setup_postdata($post); echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>'; } } ?> </ul>
wordpressの検索機能は複数キーワード対応?
wordpressの検索で複数キーワードは使えないのか?
半角カンマで区切ればできますが、
スペース区切りとかではNGです。
。。。直すしかない。
「WP Multibyte Patch プラグイン」を有効にするだけです。
WP Multibyte Patch プラグインの主な機能
投稿抜粋
「文字数ベース」抜粋の補助機能を提供します。抜粋の最大文字数と more 文字列を設定ファイルより変更できます。
文字列カウント方式の設定
言語設定が ja の場合、デフォルトで文字列カウント方式の設定を「文字数ベース」に固定します。
検索
検索の際に全角スペースを区切り文字として認識させます。また、検索文字列内の重複するスペースを取り除きます。
メール送信
送信メールのエンコーディングを JIS (ISO-2022-JP) 、UTF-8、自動判別の3つのモードから選ぶことができます。有効時のデフォルトは JIS (ISO-2022-JP) です。WordPress 本体の実装とは異なり、UTF-8 モードではボディ部も base64 エンコード (7bit) します。
トラックバック受信
日本語を含む多くのエンコーディングのデータが破壊される問題を修正します。
ピンバック受信
マルチバイト文字で書かれたページからのピンバック処理機能一式 (エンコーディング検出、変換、トリム) を実装します。また、一部の UTF-8 文字が破壊される問題を修正します。
ファイル名サニタイズ
マルチバイトを含むファイル名のファイルがアップロード、またはメール添付された場合にファイル名を md5 に変換します。
管理パネル
- ダッシュボードの「最近のコメント」、「最近の下書き」でマルチバイト文字列が正しく抜粋されるようにします。
- 投稿エディターの文字数表示機能を正しく動作させます。
- 既存コンテンツへの内部リンクを検索する際のインクリメンタルサーチを2文字から動作させます。
- 日本語フォントの表示にあわせ、管理パネルのフォントファミリーを sans-serif 系に統一、イタリック体を標準に変えます。
BuddyPress 抜粋関数
bp_create_excerpt() でマルチバイト投稿の抜粋が作られない問題を修正します。HTML タグを取り除いた形の文字数ベースの抜粋を生成します。本機能はデフォルトではオフになっておりますので、ご利用の際は wpmp-config.php を編集して有効化してください。
ご注意: Activity の抜粋機能は表示時ではなく Activity データ記録時の実データに適用されます。また、抜粋化されるタイプとされないタイプの投稿があります。これらは BuddyPress の仕様によるものですのでご了承ください。
Twenty Twelve の Open Sans 対策
Twenty Twelve テーマの Open Sans Web フォントが一部ブラウザにおいて日本語表示の不具合を引き起こす問題の対応として、翻訳ファイルの有無に関わらず当該フォントの無効化を行う機能を提供します。
その他
設定ファイル (wpmp-config.php) から各パッチ機能を個別に有効化・無効化できます。
wordpressの変数をPHPに渡す方法
記事ID
<?php the_ID();>?
IDが表示されてしまう。
<?php $id = get_the_ID(); echo $id; ?>
自由にPHPで利用したり出来る。
WordPress のカテゴリにカスタムフィールドを追加する
この記事ではWordpress3.2を使用しています。
カテゴリー編集に項目を追加
さっそくですがカテゴリー編集画面に項目を追加してみましょう。
現在使用している「functions.php」に以下を追加します。
functions.php
add_action ( 'edit_category_form_fields', 'extra_category_fields'); function extra_category_fields( $tag ) { $t_id = $tag->term_id; $cat_meta = get_option( "cat_$t_id"); ?> <tr class="form-field"> <th><label for="extra_text">その他テキスト</label></th> <td><input type="text" name="Cat_meta[extra_text]" id="extra_text" size="25" value="<?php if(isset ( $cat_meta['extra_text'])) echo esc_html($cat_meta['extra_text']) ?>" /></td> </tr> <tr class="form-field"> <th><label for="upload_image">画像URL</label></th> <td> <input id="upload_image" type="text" size="36" name="Cat_meta[img]" value="<?php if(isset ( $cat_meta['img'])) echo esc_html($cat_meta['img']) ?>" /><br /> 画像を追加: <img src="images/media-button-other.gif" alt="画像を追加" id="upload_image_button" value="Upload Image" style="cursor:pointer;" /> </td> </tr> <?php }
項目を追加したい場合は「$cat_meta」の配列名を変更して追加してください。
これでカテゴリー編集画面を見ると下図のようになっているはずです。
メタデータの保存
項目を追加しただけでは保存されませんので、保存する処理を記述しましょう。
先ほど記述した「extra_category_fields」の下に追加します。
functions.php
add_action ( 'edited_term', 'save_extra_category_fileds'); function save_extra_category_fileds( $term_id ) { if ( isset( $_POST['Cat_meta'] ) ) { $t_id = $term_id; $cat_meta = get_option( "cat_$t_id"); $cat_keys = array_keys($_POST['Cat_meta']); foreach ($cat_keys as $key){ if (isset($_POST['Cat_meta'][$key])){ $cat_meta[$key] = $_POST['Cat_meta'][$key]; } } update_option( "cat_$t_id", $cat_meta ); } }
画像アップ用のjs&cssの読み込み
追加した項目がテキストフィールドだけなら必要ありませんが、今回は画像フィールドもあるので、その場でアップロードできるようにcssとjsを読み込みます。
まずは新しいjavascriptを作成します。
upload.js
(function($) { $(function() { $('#upload_image_button').click(function() { formfield =$('#upload_image').attr('name'); tb_show('', 'media-upload.php?type=image&post_id=&TB_iframe=true'); return false; }); window.send_to_editor = function(html) { imgurl = $('img',html).attr('src'); $('#upload_image').val(imgurl); tb_remove(); } }); })(jQuery);
このjsファイルは「upload.js」として現在使用しているテーマの「js」フォルダに保存します。
次に「functions.php」に戻って下記を追加します。
functions.php
add_action('admin_print_scripts', 'my_admin_scripts'); add_action('admin_print_styles', 'my_admin_styles'); function my_admin_scripts() { global $taxonomy; if( 'category' == $taxonomy ) { wp_enqueue_script('media-upload'); wp_enqueue_script('thickbox'); wp_register_ script('my-upload', get_bloginfo('template_ directory') .'/js/upload.js'); wp_enqueue_script('my-upload'); } } function my_admin_styles() { global $taxonomy; if( 'category' == $taxonomy ) { wp_enqueue_style('thickbox'); } }
これで画像を追加の横のアイコンをクリックすると、いつもの画像を挿入するウィンドウが表示されます。
テンプレートファイルでの表示
入力したデータをテンプレートで表示してみます。
ここではリスト表示をしてみます。
<ul class="clearfix"> <?php $tag_all = get_terms("category", "fields=all"); foreach($tag_all as $value): $cat_data = get_option('cat_'.intval($value->term_id)); ?> <li> <?php echo esc_html($value->name) ?> <img src="<?php echo esc_html($cat_data['img']) ?>" width="110" height="110" /> <?php echo esc_html($cat_data['extra_text']) ?><br /> </li> <?php endforeach; ?> </ul>
カテゴリーで追加したカスタムフィールドのデータは「wp_options」に保存されていますので、「term_id」でidを取得したら「get_option」で取得できます。
保護中: ダウンロード(WordPress のCSSリセット済みThame)
WordPress のCSSをリセットする
WordPress にデザインをかけようとするとデフォルトのCSSが細かすぎて厄介者だ!
毎日のようにWordpressを使っていると無駄を省きたいと考えるのは皆同じことだろう。
最近主流のデザインは
ヘッダーやフッターの背景は画面いっぱい、ヘーダーの内容・フッターの内容は指定幅、というものがほとんどだ。
下記のようなCSSを基本にスタートすると作業が早い。
※ID名・クラス名が増えているので、注意する。
herder.php と footer.php に<3つ(#header_inner、#main_inner、#footer_inner)を追記することが必須です。 ↓style.css
/* Theme Name: Twenty Eleven Theme URI: http://wordpress.org/extend/themes/twentyeleven Author: the WordPress team Author URI: http://wordpress.org/ Description: The 2011 theme for WordPress is sophisticated, lightweight, and adaptable. Make it yours with a custom menu, header image, and background -- then go further with available theme options for light or dark color scheme, custom link colors, and three layout choices. Twenty Eleven comes equipped with a Showcase page template that transforms your front page into a showcase to show off your best content, widget support galore (sidebar, three footer areas, and a Showcase page widget area), and a custom "Ephemera" widget to display your Aside, Link, Quote, or Status posts. Included are styles for print and for the admin editor, support for featured images (as custom header images on posts and pages and as large images on featured "sticky" posts), and special styles for six different post formats. Version: 1.4 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Tags: dark, light, white, black, gray, one-column, two-columns, left-sidebar, right-sidebar, fixed-width, flexible-width, custom-background, custom-colors, custom-header, custom-menu, editor-style, featured-image-header, featured-images, full-width-template, microformats, post-formats, rtl-language-support, sticky-post, theme-options, translation-ready Text Domain: twentyeleven */ /* =Reset default browser CSS. Based on work by Eric Meyer: http://meyerweb.com/eric/tools/css/reset/index.html -------------------------------------------------------------- */ html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td { border: 0; font-family: inherit; font-size: 100%; font-style: inherit; font-weight: inherit; margin: 0; outline: 0; padding: 0; vertical-align: baseline; } :focus {/* remember to define focus styles! */ outline: 0; } body { background: #fff; line-height: 1; } ol, ul { list-style: none; } table {/* tables still need 'cellspacing="0"' in the markup */ border-collapse: separate; border-spacing: 0; } caption, th, td { font-weight: normal; text-align: left; } blockquote:before, blockquote:after, q:before, q:after { content: ""; } blockquote, q { quotes: "" ""; } a img { border: 0; } narticle, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block; } /* ここからデザイン ------------------------------------------------------*/ html {} body { font-family: "メイリオ", meirio, Verdana,"ヒラギノ角ゴ Pro W3","Hiragino Kaku Gothic Pro","MS Pゴシック","MS PGothic",sans-serif; font-size: 12px; line-height: 20px; } #page { } /* カラム割 -------------------------------------------------------*/ /* メニューバー、背景を画面幅いっぱいに、でもコンテンツは指定幅にという流行のレイアウトに対応 画面幅のカラム(インデントなし) 指定幅のカラム(インデントあり) */ #header { } #header_inner { width: 1000px; margin: 0 auto; } #main { width: 1002px; margin: 0 auto; } #main_inner { float: left; width: 1000px; margin: 0 auto; } #footer { clear: both; } #footer_inner { width: 1000px; margin: 0 auto; } /* メインカラムとサイドバーの関係 */ #primary { float: right; width: 696px; } #secondary { float: left; width: 300px; } /* レイアウト確認Border #header, #header_inner, #main, #main_inner, #footer, #footer_inner, #primary, #secondary {border: 2px solid red; }*/ #header { border: 1px solid skyblue; } #header_inner { border: 1px solid limegreen; } #main_inner { border: 1px solid gray; } #primary { border: 1px solid mediumvioletred; } #secondary { border: 1px solid mediumturquoise; } #footer { border: 1px solid blueviolet; } #footer_inner { border: 1px solid magenta; } /* EOF)カラム割 */ /* =Print ----------------------------------------------- */ @media print { body { background: none !important; font-size: 10pt; } footer.entry-meta a[rel=bookmark]:link:after, footer.entry-meta a[rel=bookmark]:visited:after { content: " [" attr(href) "] "; /* Show URLs */ } #page { clear: both !important; display: block !important; float: none !important; max-width: 100%; position: relative !important; } #branding { border-top: none !important; padding: 0; } #branding hgroup { margin: 0; } #site-title a { font-size: 21pt; } #site-description { font-size: 10pt; } #branding #searchform { display: none; } #branding img { display: none; } #access { display: none; } #main { border-top: none; box-shadow: none; } #primary { float: left; margin: 0; width: 100%; } #content { margin: 0; width: auto; } .singular #content { margin: 0; width: 100%; } .singular .entry-header .entry-meta { position: static; } .entry-meta .edit-link a { display: none; } #content nav { display: none; } .singular .entry-header, .singular .entry-content, .singular footer.entry-meta, .singular #comments-title { margin: 0; width: 100%; } .singular .hentry { padding: 0; } .entry-title, .singular .entry-title { font-size: 21pt; } .entry-meta { font-size: 10pt; } .entry-header .comments-link { display: none; } .page-link { display: none; } .singular #author-info { background: none; border-bottom: none; border-top: none; margin: 2.2em 0 0; padding: 0; } #respond { display: none; } .widget-area { display: none; } #colophon { display: none; } /* Comments */ .commentlist > li.comment { background: none; border: 1px solid #ddd; -moz-border-radius: 3px 3px 3px 3px; border-radius: 3px 3px 3px 3px; margin: 0 auto 1.625em; padding: 1.625em; position: relative; width: auto; } .commentlist .avatar { height: 39px; left: 2.2em; top: 2.2em; width: 39px; } .commentlist li.comment .comment-meta { line-height: 1.625em; margin-left: 50px; } .commentlist li.comment .fn { ndisplay: block; } .commentlist li.comment .comment-content { margin: 1.625em 0 0; } .commentlist .comment-edit-link { display: none; } . commentlist > li::before, .commentlist > li.bypostauthor::before { content: ''; } .commentlist .reply { display: none; } /* Post author highlighting */ .commentlist > li.bypostauthor { color: #444; } .commentlist > li.bypostauthor .comment-meta { color: #666; } .commentlist > li.bypostauthor:before { content: none; } /* Post Author threaded comments */ .commentlist .children > li.bypostauthor { background: #fff; border-color: #ddd; } .commentlist .children > li.bypostauthor > article, .commentlist .children > li.bypostauthor > article .comment-meta { color: #666; } } /* =IE7 ----------------------------------------------- */ #ie7 article.intro { margin-left: -7.6%; margin-right: -7.6%; padding-left: -7.6%; padding-right: -7.6%; max-width: 1000px; } #ie7 section.featured-post { margin-left: -7.6%; margin-right: -7.6%; max-width: 850px; } #ie7 section.recent-posts { margin-right: 7.6%; } /* =IE8 ----------------------------------------------- */ #ie8 section.feature-image.large img { width: 100%; }
[WordPress]テンプレート用タグのチートシート
「My WordPress Cheat Sheet」というサイトで、Wordpressのテンプレート用のタグのチートシートが公開されている。便利なので(。_。)φメモメモ ・・・ウッシッシ
テーマのファイル構成
- header.php – ヘッダー部分
- index.php – メイン部分
- sidebar.php – サイドバー部分
- footer.php – フッター部分
- single.php – 記事テンプレート
- page.php – ページテンプレート
- comments.php – コメントテンプレート
- search.php – 検索結果
- searchform.php – 検索フォーム
- archive.php – アーカイブ
- functions.php – 特別機能
- 404.php – 404エラーページ
ループ
<?php if(have_posts()) : ?> <?php while(have_posts()) : the_post(); ?> // HTMLやPHPのコード <?php endwhile; ?> <?php else : ?> <?php endif; ?>
テンプレート・インクルード・タグ
<?php get_header(); ?> <?php get_sidebar(); ?> <?php get_footer(); ?> <?php comments_template(); ?>
ブログ情報タグ
<?php bloginfo('name'); ?> - ブログタイトル <?php bloginfo('charset'); ?> - ブログのcharset <?php bloginfo('description'); ?> - キャッチフレーズ <?php bloginfo('url'); ?> - ブログのURL <?php bloginfo('rss2_url'); ?> - RSSのURL <?php bloginfo('template_url'); ?> - テンプレートディレクトリのURL <?php bloginfo('pingback_url'); ?> - トラックバックのURL <?php bloginfo('stylesheet_url'); ?> - CSSファイルのURL <?php bloginfo('wpurl'); ?> - WordPressのURL
条件タグ
is_home() // メインページかどうか is_front_page() // フロントページかどうか is_single() // 個別記事のページかどうか is_sticky() - check if a post is sticky is_page() // 個別ページかどうか is_category() // あるカテゴリーのアーカイブページかどうか
共通タグ
<?php the_time(); ?> - 記事の投稿時間 <?php the_date(); ?> - 記事の投稿月日 <?php the_title(); ?> - 記事のタイトル <?php the_permalink(); ?> - 記事のパーマリンク <?php the_category(); ?> - 記事のカテゴリ <?php the_author(); ?> - 記事の投稿者 <?php the_ID(); ?> - 記事のID <?php wp_list_pages(); ?> - 全ページのリスト出力 <?php wp_tag_cloud(); ?> - タグクラウド <?php wp_list_cats(); ?> - 全カテゴリのリスト出力 <?php get_calendar(); ?> - カレンダー <?php wp_get_archives() ?> - 日付別アーカイブリスト <?php posts_nav_link(); ?> - 記事の前後のページへのリンク <?php next_post_link(); ?> - 記事の次のページへのリンク <?php previous_post_link(); ?> - 記事の前のページへのリンク
ナビゲーションメニュー
// カテゴリーベース <ul id="menu"> <li <?php if(is_home()) { ?> class="current-cat"<?php } ?>> <a href="<?php bloginfo('home'); ?>">Home</a></li> <?php wp_list_categories('title_li=&orderby=id'); ?> </ul> // ページベース <ul id="menu"> <li <?php if(is_home()) { ?> class="current_page_item"<?php } ?>> <a href="<?php bloginfo('home'); ?>">home</a></li> <?php wp_list_pages('sort_column=menu_order&depth=1&title_li='); ?> </ul>
あるカテゴリの記事
<?php query_posts('category_name=Name&showposts=10'); ?>
カスタム・テンプレートファイルのインクルード
<?php include (TEMPLATEPATH . '/searchform.php'); ?>