いつも忘れてるのでメモ
1.管理画面で設定変更 ([設定] > [一般設定] )
(この時点で管理画面が表示できなくなるけど落ち着く。)
2.ファイルの移動
WordPressのファイル群を/wp/以下などに一式移動します。
個人的にわすれるので。
$ ./Console/cake schema generate -f
$ ./Console/cake Migrations.migration run all -p Migrations
‘schema_migrations’テーブルができる。
テーブル追加など
$ ./Console/cake Migrations.migration generate -f
実行すると
Cake Migration Shell
---------------------------------------------------------------
Do you want to compare the schema.php file to the database? (y/n)
[y] >
schema.phpと比較するかな? > y
---------------------------------------------------------------
Comparing schema.php to the database...
Do you want to preview the file before generation? (y/n)
[y] >
previewする? y
Please enter the descriptive name of the migration to generate:
> add_newtable_and_newfields
Generating Migration...
説明する名前つけてなので変更した内容を記述 > add_newtable_and_newfields
Do you want to update the schema.php file? (y/n)
[y] >
スキーマupdate ? yes.
Welcome to CakePHP v2.6.12 Console
---------------------------------------------------------------
App : app
Path: /Users/taka/htdocs/bizmatchocvb/html/businessmatching/app/
---------------------------------------------------------------
Cake Schema Shell
---------------------------------------------------------------
Generating Schema...
Schema file exists.
[O]verwrite
[S]napshot
[Q]uit
Would you like to do? (o/s/q)
[s] > o
Schema file: schema.php generated
上書き? yes で完了。
$ ./Console/cake Migrations.migration generate -f
で良さそう。
$ ./Console/cake Migrations.migration run
とすると
Cake Migration Shell
---------------------------------------------------------------
Available migrations:
[xxxxxxxxxxx] xxxxxxxxxxx_add_newtable_and_newfields
not applied
---------------------------------------------------------------
Please choose which version you want to migrate to. [q]uit or [c]lean.
> xxxxxxxxxxx
バージョンを聞いてくる。ので該当の xxxxxxxxxxx を入力して
---------------------------------------------------------------
Running migrations:
[xxxxxxxxxxx] xxxxxxxxxxx_add_newtable_and_newfields
> Creating table "bookmarks".
> Creating table "likes".
> Creating table "messages".
> Creating table "notices".
> Creating table "projects".
> Adding field "newstype_id" to table "news".
---------------------------------------------------------------
All migrations have completed.
/Config/Migrations/以下のMigrationのプログラムに追記
‘up’した時にどうするかを追記。(‘down’のときも必要)
/**
* After migration callback
*
* @param string $direction Direction of migration process (up or down)
* @return bool Should process continue
*/
public function after($direction) {
if ($direction === 'up') {
$Group = $this->generateModel('Group');
$Group->save(array(
'Group'=>array('name'=>'海外エージェント','key'=>'agent')
));
}
return true;
}
}
とりいそぎ機能だけ試してみたい、アプリケーション側へ集中したいということでMAMPでPHPからRedisを簡単につかう方法。
こちらからコンパイル済のredis.soを取得して
(使いたいPHPのバージョン ※マイクロバージョンが違う環境でも動作できました。)
panxianhai/php-redis-mamp https://github.com/panxianhai/php-redis-mamp
MAMPアプリケーションの以下のディレクトリに配置
/Applications/MAMP/bin/php/php5.x.x/lib/php/extensions/no-debug-non-zts-200xxxxx
メニューの [File] / [Edit Template] / [PHP] [PHP(自分のバージョン) php.ini を選択し以下を追記(最後でもどこでも)
extension=redis.so
MAMPを再起動,phpinfo()してみる。(redisが出てたらOK)
brewでredisをインストール
$ brew install redis
redisを起動
$ redis-server
サンプル実行
<?php $redis = new Redis(); $redis->connect("127.0.0.1",6379); $redis->set("name","yamaaaaa"); echo $redis->get("name");
ブラウザでアクセスして出力確認
yamaaaaa
WordPressで投稿のデータにカスタムフィールドを加えて取得する。(全文)
<?php $posts_join_keys = array(); $posts_join_prefix = 'tmp_join_table_name_'; add_filter('posts_join', 'posts_more_join' ); add_filter('posts_fields','posts_more_fields'); function posts_more_join( $join ) { global $posts_join_keys,$posts_join_prefix; foreach($posts_join_keys as $key => $k){ $alias = $posts_join_prefix.$k; $join .= sprintf(" INNER JOIN wp_postmeta as %s ON ( wp_posts.ID = %s.post_id AND %s.meta_key = '%s' )",$alias,$alias,$alias,$k); } return $join; } function posts_more_fields($fields){ global $posts_join_keys,$posts_join_prefix; foreach($posts_join_keys as $key => $k){ $alias = $posts_join_prefix.$k; $fields .= sprintf(',%s.meta_value as %s',$alias,$k); } return $fields; } $posts_join_keys[] = 'locate'; $posts_join_keys[] = 'description'; $args = array( 'posts_per_page' => -1, 'fields'=> 'wp_posts.ID,wp_posts.post_title', 'meta_query' => array(array( 'key' => 'locate', 'value' => '', 'compare' => '!=' )) ); $query = new WP_Query( $args ); $posts = $query->get_posts(); wp_reset_postdata(); $json = '{data:'.json_encode($query->get_posts()).'}'; ?>
上のプログラムの $posts_join_keysに取得したいカスタムフィールドの’meta_key’を追加(push)していけばその分取得できます。
$posts_join_keys[] = 'locate'; $posts_join_keys[] = 'description';
プラグインなどをつかわずにできるシンプルなページネーション(ページ番号)のリンクのテンプレートです。
<div class="pagenation">
<ul>
<?php
$page_current_num = (!empty($paged))? $paged:1;
$page_last_num = $wp_query->max_num_pages;
if($page_current_num > 1){
echo sprintf('<li class="prev"><a href="%s">%s</a></li>',get_pagenum_link($page_current_num-1),'PREV');
}
$page_start_num = $page_current_num - NUM_PAGENATION_BEFORE_AFTER;
if($page_start_num < 1) $page_start_num = 1;
$page_end_num = $page_current_num + NUM_PAGENATION_BEFORE_AFTER;
if($page_end_num > $page_last_num) $page_end_num = $page_last_num;
for($i = $page_start_num;$i<=$page_end_num;$i++){
if($page_current_num==$i){
echo sprintf('<li class="active">%s</li>',$i);
}else{
echo sprintf('<li><a href="%s">%s</a></li>',get_pagenum_link($i),$i);
}
}
if($page_current_num < $page_last_num){
echo sprintf('<li class="next"><a href="%s">%s</a></li>',get_pagenum_link($page_current_num+1),'NEXT');
}
?>
</ul>
</div>
//---------------------------------------------------pagination
.pagenation
padding: 40px 0
margin: auto
display: table
&:after
clear: both
content: "."
display: block
height: 0
visibility: hidden
ul
&:after
clear: both
content: "."
display: block
height: 0
visibility: hidden
text-align: center
margin: auto
li
float: left
list-style: none outside none
margin-left: 3px
&:first-child
margin-left: 0
&.active
background: #336699
color: #FFF
cursor: not-allowed
padding: 10px 20px
a
background: #F2F2F2
color: #336699
display: block
padding: 10px 20px
text-decoration: none
&:hover
background-color: #A1AABA
color: #FFF
opacity: 0.8
transition-duration: 500ms
transition-property: all
transition-timing-function: ease
function get_sub_fields_excerpt_more($key,$limit=30){ $str = get_field($key); $len = mb_strlen($str,ENCODING); if($len > NUM_EXCERPT_SLIDER){ return mb_substr($str,0,NUM_EXCERPT_SLIDER,ENCODING).'...'; }else{ return $str; } }
NUM_EXCERPT_SLIDER,ENCODINGは、文字数,文字コードの定数
WordPressで特定のカスタムフィールドが入力されている記事をランダムに取得する方法です。WP_Query関数を利用
WordPressプラグイン ACFをローカル管理画面でGoogleMapが表示されない。
/wp-content/plugins/advanced-custom-fields/core/fields/google-map.php の293行目当たりの ‘key’にGoogle API Consoleで取得したAPIKey(制限なし)をいれて解決(とりあえず!
※制限なしだと危険なのであくまで一時的。
※プラグインのバージョンアップでソースが上書きされることへの対策が必要
##エラー発生の環境など
– ローカル
– ドメインは http://hogehoge.dev を /etc/hosts にてローカル(127.0.0.1)に向けている。
– ACFのバージョンは 4.4.11
– 一瞬ちらっと地図がでるがエラー表示に切り替わる
言語切替時にドメインが http://example.com >> http://en.example.com などに切り替わったときにCSSでしている@font-faceの読み込みがエラーになってしまった。
フォント関係ファイルへのクロスドメイン制約を外して対応。
<FilesMatch "\.(ttf|eot|woff|svg)$"> <IfModule mod_headers.c> Header set Access-Control-Allow-Origin "*" </IfModule> </FilesMatch>
(ローカルにhostsで割り当てた際に発生、運用のサーバーで確認し追記よてい、取り急ぎメモ)
Powered by WordPress & Theme by Anders Norén