WordPressのカスタムフィールドを改行ありで表示

WordPressのカスタムフィールドを改行ありで表示するサンプルタグは以下の通り。

$sample = post_custom('カスタムフィールド');
echo nl2br($sample);

WordPressのカスタムフィールドで値を判定して表示

WordPressのカスタムフィールドで値を判定して表示するタグは以下の通り

$sample = post_custom('カスタムフィールド');
if ( $sample )  {
	echo $sample;
} else {
	//値が入っていません
}

WordPressの投稿一覧画面にカスタムフィールドの値を表示

WordPressの投稿一覧画面にカスタムフィールドの値を表示する方法

ひとつ追加する場合は、
下記コードをfunction.phpに追加する

/**
 * 投稿一覧に商品コード列追加
 */

function manage_posts_columns($columns) {
	$columns['Goods'] = "商品コード";
	return $columns;
}
function add_column($column_name, $post_id) {
	if( $column_name == 'Goods' ) {
		$stitle = get_post_meta($post_id, 'Goods', true);
	}
	if ( isset($stitle) && $stitle ) {
		echo attribute_escape($stitle);
	} else {
		echo __('None');
	}
}
add_filter( 'manage_posts_columns', 'manage_posts_columns' );
add_action( 'manage_posts_custom_column', 'add_column', 10, 2 );

2つ表示させる場合は、以下のコードを追加。

/**
 * 投稿一覧に商品コード列追加
 */

function manage_posts_columns($columns) {
	$columns['Goods'] = "商品コード";
	$columns['Area'] = "産地";
	return $columns;
}
function add_column($column_name, $post_id) {
	if( $column_name == 'Goods' ) {
		$stitle = get_post_meta($post_id, 'Goods', true);
	}
	if( $column_name == 'Area' ) {
		$stitle = get_post_meta($post_id, 'Area', true);
	}
	if ( isset($stitle) && $stitle ) {
		echo attribute_escape($stitle);
	} else {
		echo __('None');
	}
}
add_filter( 'manage_posts_columns', 'manage_posts_columns' );
add_action( 'manage_posts_custom_column', 'add_column', 10, 2 );

WordPressの基本タグまとめ

カテゴリーページへ使う記事へのリンクタグ

<?php the_permalink(); ?>
/*example*/
<a href="<?php the_permalink(); ?>">テキストテキスト</a>

カスタムフィールドを改行ありで表示

<?php echo nl2br(post_custom('wpcf-work_time')); ?>

WordPressで投稿ページや固定ページでコメントアウトする方法

WordPressでコメントアウトタグを挿入すると、
終わりのタグがおかしくなってしまい、
うまくできない。

そのため、以下の様な方法にて回避すると便利。

まずは、function.phpに下記コードを追記。

//コメントアウトのショートコード
function overrule_shortcode( $atts, $content = null ) {
return null;
}
add_shortcode('overrule', 'overrule_shortcode');

その後、以下コードでページ内の隠したいところを囲えば良い。

[overrule]テキストテキスト・・・・・。[/overrule]

WordPressにCSVでインポート(アップロード)できるプラグインReally Simple CSV Importer

WordPressにCSVでインポート(アップロード)したいときは、プラグインReally Simple CSV Importerを使えばいい。
使い方は、下記サイトにうまくまとめられています。
http://liginc.co.jp/web/wp/plug-in/58046

CSVでアップロードした際、
なぜか日本語の部分がうまくアップされない時がある。
それは文字コードがUTF-8ではないかららしい、。
※Shift-JISなどではエラーがでる。

なので、エクセルで編集する際は、エクセルで一度CSVで保存したあと、
テキストエディターなどで文字コードをUTF-8にして保存しなおすとよい。

MW WP Form WordPressの確認画面付きフォーム

ダウンロードはこちら
http://wordpress.org/plugins/mw-wp-form/

使い方はこちらによくまとめられている
http://webdesignerwork.jp/wordpress/mw-wp-form/

WordPressで全記事数を表示

WordPressで全記事数を表示するには、
下記タグをテンプレートファイルに書き込めばいい。

<?php $numposts = $wpdb->get_var("SELECT count(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post'");
if (0 < $numposts)
$numposts = number_format($numposts);
echo $numposts.' 商品販売中です。';
?>

カスタムフィールドやカスタム投稿・タクソノミーが簡単に設定できるWordPressのプラグインTypes

ダウンロードはこちら。
http://wp-types.com/home/types-manage-post-types-taxonomy-and-custom-fields/

設定方法は下記ページで詳しく解説してあります。
http://www.imaginationdesign.jp/blog/wordpress/2278/

表示する際は、以下のコードで表示できる。

<?php echo post_custom('wpcf-work_year'); ?>

Filezillaで一部の拡張子のみをパーミッションを一括で変える方法

Filezillaには、一部の拡張子の種類のみ、
一括でパーミッションを変える方法がありません。

しかし、フィルターを作った上で変更する方法はあります。

1.フィルターを作る

ます、Filezillaヘッダアイコンメニューの中から、
フィルタダイアログを開きます。

次に左下の『フィルタルールを編集』ボタンをクリック。

『新規作成』をクリックし、任意のフィルタ名を入力して『OK』をクリック。

右の入力部分に、『ファイル名』、『部分一致』、『.php』と入力し、『OK』をクリック。
※これは、PHPファイルのみをフィルターで出したい時の例

2.フィルターを適用

右の枠から作成したフィルターにチェックを入れ、
『OK』をクリックします。

すると、フィルターが適用され、PHPのファイルのみが表示された状態になります。
そこで、トップディレクトリーを右クリックし、
パーミッションウィンドウを開きます。

あとは、パーミッションを入力し、サブディレクトリの適用の有無、ディレクトリへの適用の有無などを指定し、『OK』をクリック。

wordpressのAdvanced Custom Fieldsでフィールドの値を取得して出力するテンプレート。

【基本的な方法】

Advanced Custom Fields

フィールドの値を取得して表示するには、「the_field()」を使います。

post_customなどのタグを使うと、プレビューなどが反映されないため、
Advanced Custom Fields特有のタグを使う必要がある。

the_field('field_name_01');

フィールドの値を取得して変数に代入して使う場合などは、「get_field()」を使います。

$hoge = get_field('field_name_01');

【フィールドタイプ:テキスト】

取得したフィールド(フィールド名:field_name_01)に何か入力されていたら、値を表示する場合の例。

$text = get_field('field_name_01');
if ( $text )  {
    echo $text;
}

【フィールドタイプ:テキストエリア】

改行で区切られたデータが入っているフィールド(フィールド名:field_name_01)の値を取得し、リスト形式に成形して表示する場合の例。

$fieldData = explode("\n",get_post_meta($post->ID,'field_name_01',true) );
$i = 0;
echo "<ul>";
foreach ($fieldData as $value){
    if ( $value ){
        echo '<li>' . $value . '</li>';
    }
    $i++;
echo "</ul>";
}

【フィールドタイプ:数値】
取得したフィールド(フィールド名:field_name_01)の値を、千位毎の区切り及び小数点以下第一位まで表示させる場合の例。

echo number_format( get_post_meta($post->ID,'field_name_01',true) , 1 );

【フィールドタイプ:Wysiwyg エディタ】

取得したフィールド(フィールド名:field_name_01)の値に画像にリンクを貼っている箇所が存在したら、aタグに「rel=”lightbox”」を付加する場合の例。

$pattern = "/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
$replacement = '<a$1href=$2$3.$4$5 rel="lightbox"$6>';

$dataText = get_field("field_name_01", $post->ID);
$dataText = preg_replace ( $pattern , $replacement , $dataText);

echo $dataText;

【フィールドタイプ:画像】

取得したフィールド(フィールド名:field_name_01)の画像をlargeサイズで表示する場合の例。(lightboxを使う前提で、aタグには「rel=”lightbox”」をつけています。)

※ フィールド名「field_name_01」を定義する時に、「返り値」は「画像 ID」を指定しておいてください。

<?php
    $attachment_id = get_field('field_name_01');
    $size = "large"; // (thumbnail, medium, large, full or custom size)
    $image = wp_get_attachment_image_src( $attachment_id, $size );
    $attachment = get_post( get_field('field_name_01') );
    $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
    $image_title = $attachment->post_title;
?>

<a href="<?php echo wp_get_attachment_url( get_field( 'field_name_01',$post->ID) ); ?>" rel="lightbox"><img src="<?php echo $image[0]; ?>" width="<?php echo $image[1]; ?>" height="<?php echo $image[2]; ?>" alt="<?php echo $alt; ?>" title="<?php echo $image_title; ?>" /></a>

【フィールドタイプ:画像IDを取得して表示】

//画像IDの取得
$image_id = post_custom('[画像アップロードのカスタムフィールド名]');
//画像IDから画像を表示 $sizeに表示サイズを設定(デフォルトは'thumbnail')
echo wp_get_attachment_image($image_id, $size); 

【フィールドの値をチェックして表示】

$text = get_field('my_custom_01');
if($text) :
echo $text;
endif;

WordPressの不要なリンクを削除する

テーマファイルの「function.php」を使うのが最も手軽でしょう。以下の記述を追記すればOKです。

if (function_exists(‘register_sidebar’))
register_sidebar();
remove_action(‘wp_head’,'index_rel_link’);
remove_action(‘wp_head’,'parent_post_rel_link’,10);
remove_action(‘wp_head’,'start_post_rel_link’,10);
remove_action(‘wp_head’,'adjacent_posts_rel_link_wp_head’,10);

WordPressのフィードを削除する

functions.php の

add_theme_support( 'automatic-feed-links' );

を削除し

remove_action('wp_head', 'feed_links_extra', 3);

を追加する。

その後 header.php に

<link rel="alternate" type="application/rss+xml" title="RSS" href="<?php bloginfo('rss2_url'); ?>" />

を追加する。

wp_list_categories()が出力するHTMLを変更したい。

従来のカテゴリーの場合

<?php
	$categories = get_categories('parent=0&hide_empty=0&orderby=id');
	if (is_array($categories)) {
		foreach($categories as $category):
			$v_cat_id = $category->cat_ID;
			$v_cat_Parent_title = $category->cat_name;
			$v_cat_Parent_t_a = wp_specialchars($v_cat_Parent_title);
			$v_cat_Parent_t_u = attribute_escape($v_cat_Parent_title);
			$v_cat_Parent_url = get_category_link($v_cat_id);
			$v_cat_child_list = wp_list_categories("orderby=id&hide_empty=0&title_li=&use_desc_for_title=0&child_of=$v_cat_id&depth=1&echo=0");
			echo "<h2><a href=\"$v_cat_Parent_url\" title=\"$v_cat_Parent_t_u\">$v_cat_Parent_t_a</a></h2>\n";
			if ( strpos($v_cat_child_list, __('No categories')) === false) {
				echo "<ul>\n$v_cat_child_list\n</ul>\n";
			}
		endforeach;
	}
?>

タクソノミーの場合
※コードはかなり汚い。

//	$categories = get_categories('parent=0&hide_empty=0&orderby=id');
//	$categories = get_terms( 'category' , 'parent=0&hide_empty=0&orderby=id');
//echo '<br /><br /><br /><br /><br />';
$get_terms_args_id = $taxonomy_id->term_id;
echo $get_terms_args_id;
$get_terms_args = 'parent=' . $get_terms_args_id . '&hide_empty=0&orderby=id';
//$get_terms_args = 'parent=128&hide_empty=0&orderby=id';
	$categories = get_terms( 'goods-cate' , $get_terms_args);
	$count = count($categories);
if ( $count > 0 ) {
	if (is_array($categories)) {
echo '<ul class="goodsTabs clear">';
		foreach($categories as $category):
//echo '<br /><br />';
			$v_cat_id = $category->term_id;
//echo $v_cat_id . '<br />';
			$v_cat_Parent_title = $category->name;
//echo $v_cat_Parent_title . '<br />';
			$v_cat_Parent_t_a = wp_specialchars($v_cat_Parent_title);
//echo $v_cat_Parent_t_a . '<br />';
			$v_cat_Parent_t_u = attribute_escape($v_cat_Parent_title);
//echo $v_cat_Parent_t_u . '<br />';
//			$v_cat_Parent_url = get_category_link($v_cat_id);
			$v_cat_Parent_slug = $category->slug;
//			$v_cat_Parent_url = get_term_link($v_cat_Parent_slug , 'category' );
//echo $v_cat_Parent_url . '<br />';
			$homeurl = home_url();
			$v_cat_child_list = wp_list_categories('orderby=id&hide_empty=0&title_li=&use_desc_for_title=0&child_of=' . $v_cat_id . '&depth=1&echo=0');
			echo '<li><a href="' .$homeurl . '/goods-cate/' .$v_cat_Parent_slug . '/">' . $v_cat_Parent_title . '</a></li>';
			if ( strpos($v_cat_child_list, __('No categories')) === false) {
//				echo "<ul>\n$v_cat_child_list\n</ul>\n";
			}
		endforeach;
echo '</ul>';
	}
}

WordPressでカスタム投稿もタクソノミーなどで絞り込みが出来る様にする。

WordPressでカスタム投稿もタクソノミーなどで絞り込みが出来る様にするには、
function.phpに下記タグを表記する。

// カスタムタクソノミーでフィルター (絞り込み機能)
add_action( 'restrict_manage_posts', 'add_post_taxonomy_restrict_filter' ); 
function add_post_taxonomy_restrict_filter() { 
    global $post_type; 
    if ( '●投稿タイプ英語●' == $post_type ) { 
        ?> 
        <select name="●タクソノミー英語●"> 
            <option value="">カテゴリー指定なし</option> 
            <?php 
            $terms = get_terms('●タクソノミー英語●'); 
            foreach ($terms as $term) { ?> 
                <option value="<?php echo $term->slug; ?>"><?php echo $term->name; ?></option> 
            <?php } ?> 
        </select> 
        <?php 
    } 
} 

WordPressで、カスタム分類ごとにカスタム投稿を表示する方法

WordPressで、カスタム分類ごとにカスタム投稿を表示する際のサンプルコード。
<?php
    $taxonomys = get_terms( "ここにtaxonomyを入力","orderby=slug&order=DESC&parent=ここに親カテゴリを指定する場合は入力");//"frontiercat"からタームを取り出す。数字が小さいものから大きいものの順に取り出す
    foreach($taxonomys as $value)://繰り返しその一つを$valueに代入
 ?>
<div id="<?php echo $value->slug; ?>" class="area">カテゴリ名:<?php echo $value->name;?> スラッグ名:<?php echo $value->slug; ?></div>
<?php query_posts( array( 'menu-cate' => $value->slug, 'order'=>'DESC' ) ); //記事を読み込む ?>
<?php if(have_posts()):
while(have_posts()): the_post(); ?>
<h1>タイトル<?php the_title(); ?></h1>
<p>抜粋:<?php the_excerpt(); ?></p>
<p>カスタムフィールド:<?php echo post_custom('menu-price'); ?></p>
<p>本文<?php the_content(); ?></p>

<?php endwhile; endif; ?>
 </dl>

<?php endforeach; ?>

jQueryでプラグインなしでモーダルウィンドウを実装

表示するコンテンツを増やす場合にはコピー&ペーストでwd2,wd3…と任意の数にしてください。
■jQuery

$(function(){
	$('.btns').click(function(){
		wn = '.' + $(this).attr('data-tgt');
		var mW = $(wn).find('.modalBody').innerWidth() / 2;
		var mH = $(wn).find('.modalBody').innerHeight() / 2;
		$(wn).find('.modalBody').css({'margin-left':-mW,'margin-top':-mH});
		$(wn).fadeIn(500);
	});
	$('.close,.modalBK').click(function(){
		$(wn).fadeOut(500);
	});
});

■HTML

<div class="modal wd1">
	<div class="modalBody">
		<p class="close">×close</p>
		<p>…..</p>
	</div>
	<div class="modalBK"></div>
</div>

<div class="modal wd2">
	<div class="modalBody">
		<p class="close">×close</p>
		<p>…..</p>
	</div>
	<div class="modalBK"></div>
</div>
<div class="modal wd3">
	<div class="modalBody">
		<p class="close">×close</p>
		<p>…..</p>
	</div>
	<div class="modalBK"></div>
</div>
<p data-tgt="wd1" class="btns">1</p>
<p data-tgt="wd2" class="btns">2</p>
<p data-tgt="wd3" class="btns">3</p>

■css

.modal{display:none;}
.modalBody{position: fixed; z-index:1000; background: #000; width:690px; left:50%; top:50%; height: 400px}
.modalBK{position: fixed; z-index:999; height:100%; width:100%;background:#000; opacity: 0.9;filter: alpha(opacity=90);-moz-opacity:0.90;}
.btns{font-size: 80px; width:150px; background:#111; height: 150px; line-height:150px; text-align:center; font-family: arial; color: #fff; float: left; margin:10px; cursor: pointer}
.close{cursor: pointer;}
.modal{width:690px; color: #eee;}
.modal p{font-size:12px; text-align:justify;}
.modal h1{font-weight:bold; font-size: 30px;}
.modalBody{padding: 10px;}

引用:http://zxcvbnmnbvcxz.com/jquery-easy-modalwindow/

Excel 2007 でパスワードをかける方法

左上のWindowsマークをクリック、
その後〔配置準備〕>〔ドキュメントの暗号化〕をクリック。
ここにパスワードを入力して完了。

しかし、パスワードを入力できない場合があるので、
その際は、コピー&ペーストで対応する。

なぜこうなるのでしょう・・。

Handbrakeの設定

『Video』で『Framerate』を29.97にする。
※音がずれる(音ズレ)を防ぐため

上記でだめだったら、
『Video』で『Video Codec』を『MPEG-4』、『Framerate』を29.97にする。

『Quality』を『30』にする。
※容量を少しでも少なくするため。
※『MPEG-4』の場合は『20』
※Nexus 7での画質

【バージョン 0.9.4 の場合】

Video Codec:H.264
Framerate:Same as sourse
Constant Quality:35

EC-Cubeトップページのtitleを修正する方法

data/Smarty/templates/default/site_frame.tplの
title内を

<title>
<!--{assign var=top value="`$smarty.const.ROOT_URLPATH`index.php"}-->
<!--{if $smarty.server.PHP_SELF==$top}-->
ここにトップページのタイトルを入れる
<!--{else}-->
<!--{$arrSiteInfo.shop_name|h}--><!--{if $tpl_subtitle|strlen >= 1}--> / <!--{$tpl_subtitle|h}--><!--{elseif $tpl_title|strlen >= 1}--> / <!--{$tpl_title|h}--><!--{/if}-->
<!--{/if}-->
</title>

に修正する。

Copyright © All Rights Reserved · Green Hope Theme by Sivan & schiy · Proudly powered by WordPress