/wp 以下に作成したWPサイトのトップページだけは独立したページを使用します。


↑のindex.htmlをトップに表示させます。

1) テンプレートファイル template_toppage.phpを作成します。
内容は以下の通り

<?php
/*
Template Name: Top Page
*/
readfile(ABSPATH . '/index.html');
?>

ABSPATHはwordpressがインストールされたフォルダのパスを示します。
ですのでindex.htmlがwp/フォルダ以下にあっても上記の指定でOKです。

2) WP管理画面から固定ページを新規に作成します。
タイトルは「トップページ」などてきとうでかまいません。

テンプレートに先ほど作成したTop Pageが表示されますのでこれを選択します。

3) 「設定」=> 「表示設定」=>「フロントページの表示」で「固定ページ」にチェックをし、先ほど作成したページを選択します。

Yahoo!店舗の製作の際に覚えたこと

画像ファイルのパス

テンプレート内で記入する場合は下記でOK
どのフォルダにアップしてもここに入ります。

<img src="/lib/ストアアカウント/画像ファイル名">

実際のURLは

<img src="http://shopping.c.yimg.jp/lib/ストアアカウント/画像ファイル名">

となるようです。

固定たて帯バナーを設置する
トリプルを使わない場合は外部のstylesheetを読み込めないので、全部インラインで指定する必要があります。

<div style="position:fixed;background-image:url(http://shopping.c.yimg.jp/lib/店舗ID/画像ファイル名);background-repeat:repeat-y;right:0;top:0;height:1000px;width:200px;z-index:-1"></div>

position:fixed;
background-image:url(http://shopping.c.yimg.jp/lib/店舗ID/画像ファイル名);  /*画像ファイル*/
background-repeat:repeat-y;
right:0;
top:0;
height:1000px;
width:200px;
z-index:-1 /*重なった時に下になるように*/

thumbnail,medium,large,fullから選ぶ

<?php the_post_thumbnail('画像のサイズ'); ?>

画像のサイズは下記から指定します。

thumbnail サムネイル
medium
large
full 原寸大

選べるのは4種類だけですが、管理画面からそれぞれのサイズの数値を指定できます。
「設定」→「メディア」から設定できます。

子カテゴリを非表示に

default-widgets.phpの533行目当たりから始まる部分が
カテゴリ一覧ウィジェットを生成する部分みたいです。

/**
* Categories widget class
*
* @since 2.8.0
*/
class WP_Widget_Categories extends WP_Widget {
public function __construct() {
$widget_ops = array('classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories." ) );
parent::__construct('categories', __('Categories'), $widget_ops);
}
public function widget( $args, $instance ) {
/** This filter is documented in wp-includes/default-widgets.php */
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base );
$c = ! empty( $instance['count'] ) ? '1' : '0';
$h = ! empty( $instance['hierarchical'] ) ? '1' : '0';
$d = ! empty( $instance['dropdown'] ) ? '1' : '0';
echo $args['before_widget'];
if ( $title ) {
echo $args['before_title'] . $title . $args['after_title'];
}
$cat_args = array( 'orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
if ( $d ) {
$cat_args['show_option_none'] = __('Select Category');
/**
* Filter the arguments for the Categories widget drop-down.
*
* @since 2.8.0
*
* @see wp_dropdown_categories()
*
* @param array $cat_args An array of Categories widget drop-down arguments.
*/
wp_dropdown_categories( apply_filters( 'widget_categories_dropdown_args', $cat_args ) );
?>
<script type='text/javascript'>
/* <![CDATA[ */
	var dropdown = document.getElementById("cat");
	function onCatChange() {
		if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
			location.href = "<?php echo home_url(); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
		}
	}
	dropdown.onchange = onCatChange;
/* ]]> */
</script>
<?php
} else {
?>
<div id="right_categories">
<ul>
<?php
$cat_args['title_li'] = '';
/**
		 * Filter the arguments for the Categories widget.
		 *
		 * @since 2.8.0
		 *
		 * @param array $cat_args An array of Categories widget options.
		 */
wp_list_categories( apply_filters( 'widget_categories_args', $cat_args ) );
?>
</ul>
</div>
<?php
}
echo $args['after_widget'];
}
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['count'] = !empty($new_instance['count']) ? 1 : 0;
$instance['hierarchical'] = !empty($new_instance['hierarchical']) ? 1 : 0;
$instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0;
return $instance;
}
public function form( $instance ) {
//Defaults
$instance = wp_parse_args( (array) $instance, array( 'title' => '') );
$title = esc_attr( $instance['title'] );
$count = isset($instance['count']) ? (bool) $instance['count'] :false;
$hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
$dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false;
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
<p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>"<?php checked( $dropdown ); ?> />
<label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e( 'Display as dropdown' ); ?></label><br />
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>"<?php checked( $count ); ?> />
<label for="<?php echo $this->get_field_id('count'); ?>"><?php _e( 'Show post counts' ); ?></label><br />
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> />
<label for="<?php echo $this->get_field_id('hierarchical'); ?>"><?php _e( 'Show hierarchy' ); ?></label></p>
<?php
}
}

559行目からの部分がカテゴリ一覧を抽出する部分の様で、ここに depth という引数を記入します。 depth => 1 が’第一階層のみを表示’のようです。なので

$cat_args = array('depth' => '1', 'orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);

で親カテゴリだけが表示されます。

分かりやすくなってました。

前回xcodeをアップデートしたらiPhoneシミュレータの場所が変わってて焦りました。

/Users/[User]/Library/Developer/CoreSimulator/Devices/[DeviceID]/data/Containers/Data/Application/[App]

ということでしたが、Containers というディレクトリが無くたどり着けません。
いろいろ探した結果、

Applications/Xcode.paa/Contents/Developer/Applications/

に入ってました。
な〜んだ。

あと普通にXcodeをDockから右クリックして”Open Developer Tool”から開けました。

Posted in mac

really simple csv importer を使うために csv をutf-8に変換するために nkf をインストールするために homebrew をインストールするために xcode をアップデート中。。。

wordpressでECサイトを構築する案件。
300件近くある商品情報を一括で記事として投稿する方法を探したところ、
really simple csv importer が良いらしいのですが、
試してみたところ、なぜかタイトルも記事も読み込まれません。


全部”タイトルなし”に。。。

どうやら文字コードの問題のようですので、csvファイルをutf-8に変換しようとするもlibreoffice のスプレッドシートでは無理な模様。
windowsだったら秀丸エディタでできてたのに。。。

フリーの良いエディタは無いかなと思って探していると nkf というコマンドがあるそうな。

コマンドラインから
nkf -w [入力ファイル名] > [出力ファイル名]
でutf-8に変換できるそうなのですが、インストールされておらず。

macのパッケージ管理システムも入ってないみたいで homebrew というのをインストールすることにする。

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1
Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir /usr/local
Password:
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local
==> /usr/bin/sudo /bin/mkdir /Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> Downloading and installing Homebrew...
remote: Counting objects: 203632, done.
remote: Compressing objects: 100% (54818/54818), done.
remote: Total 203632 (delta 147629), reused 203632 (delta 147629)
Receiving objects: 100% (203632/203632), 43.29 MiB | 90.00 KiB/s, done.
Resolving deltas: 100% (147629/147629), done.
From https://github.com/Homebrew/homebrew
* [new branch]      master     -> origin/master
HEAD is now at 61eb490 hashpump: add 1.1.0_1 bottle.
==> Installation successful!
==> Next steps
Run `brew doctor` before you install anything
Run `brew help` to get started

で言われた通りbrew doctorすると、

$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry and just ignore them. Thanks!
Warning: Your Xcode (5.1.1) is outdated
Please update to Xcode 6.0.1.
Xcode can be updated from the App Store.
$ 

なんかXcodeバージョンが古いそうなので今アップデート中。。。

再訪問に行って帰って来ると、

$ brew doctor
Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry and just ignore them. Thanks!
Warning: Git could not be found in your PATH.
Homebrew uses Git for several internal functions, and some formulae use Git
checkouts instead of stable tarballs. You may want to install Git:
brew install git
Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.
Warning: You have not agreed to the Xcode license.
Builds will fail! Agree to the license by opening Xcode.app or running:
xcodebuild -license
$ sudo brew help
Password:
Example usage:
brew [info | home | options ] [FORMULA...]
brew install FORMULA...
brew uninstall FORMULA...
brew search [foo]
brew list [FORMULA...]
brew update
brew upgrade [FORMULA...]
brew pin/unpin [FORMULA...]
Troubleshooting:
brew doctor
brew install -vd FORMULA
brew [--env | config]
Brewing:
brew create [URL [--no-fetch]]
brew edit [FORMULA...]
open https://github.com/Homebrew/homebrew/wiki/Formula-Cookbook
Further help:
man brew
brew home
$

と、どうやらbrew はインストールされた模様。
さっそくnkfをインストールしようとすると、

$ brew install nkf
Warning: You have not agreed to the Xcode license.
Builds will fail! Agree to the license by opening Xcode.app or running:
xcodebuild -license
Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.

なんかXcode利用規約にagreeしないといけないとか。
Xcodeを立ち上げる→利用規約に同意する→閉じる
でもう一回インストール

$ brew install nkf
==> Downloading http://dl.sourceforge.jp/nkf/59912/nkf-2.1.3.tar.gz
Already downloaded: /Library/Caches/Homebrew/nkf-2.1.3.tar.gz
==> make CC=clang
==> make install prefix=/usr/local/Cellar/nkf/2.1.3 MKDIR=mkdir -p
/usr/local/Cellar/nkf/2.1.3: 4 files, 352K, built in 2 seconds
$ nkf --version
Network Kanji Filter Version 2.1.3 (2013-11-22)
Copyright (C) 1987, FUJITSU LTD. (I.Ichikawa).
Copyright (C) 1996-2013, The nkf Project.

と、どうやらインストールされた感じ。
nkf は Network Kanji Filter の略なんですね〜

で、今回のcsvファイルの文字コードを見ると

$ nkf -g testdata1_50.csv
Shift_JIS

これが原因?
さっそく変換してみます。

$ nkf -w testdata1_50.csv > testdata1_50utf8.csv
$ nkf -g testdata1_50.csv
Shift_JIS
$ nkf -g testdata1_50utf8.csv
UTF-8

再度 Really Simple CSV Importer から読み込ませると。。。
ブジ登録されてました!!
よかった〜

オプションは

-s Shift_JISへ変換
-w UTF-8へ変換
-e EUCへ変換

ちなみにEUC-JPは確認するとCP51932と表示されます 

Posted in mac