<div id="content">
<div class="blog">
<div class="entry">
<h2 class="entry-header"><?php single_cat_title(); ?></h2>
<div class="entry-body">
<p><?php echo category_description(); ?></p>
<ul> <?php if ($posts) : foreach ($posts as $post) : start_wp(); ?> <li id="catpost-<?php
the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent
Link: <?php the_title(); ?>"> <?php the_title(); ?></a><br /><?php the_excerpt();
?></li> <?php endforeach; else: ?> </ul> <p><?php _e('Sorry, no posts matched
your criteria.'); ?></p> <?php endif; ?>
</div>
</div>
</div>
これでいけた
2015年2月12日木曜日
2015年2月7日土曜日
サムネイルクリックで直リンク
つまりイケサイみたいなサイトを作るときのテンプレ
<dl class="studioimg">
<?php $posts = get_posts('numberposts=10&category=2&orderby=rand'); ?>
ーーーーーーーーーーーーー
numberposts 表示する投稿数
category=2 表示するカテゴリー
orderby=rand ランダム表示
ーーーーーーーーーーーーーーーー
<?php foreach($posts as $post): ?>
<dd class="imgdd">
<?php //リンク設定の有無で切り分け
$linknourl = get_post_meta( $post->ID, 'linkurl', true );
if ( !empty( $linknourl ) ) : ?>
<?php
//htmlを除去
$linknourl = htmlspecialchars($linknourl,ENT_QUOTES,'UTF-8');
?><span><a href="<?php echo $linknourl; ?>">
<?php the_post_thumbnail(array(150,113)); ?><?php the_title(); ?></a></span>
<?php else : ?>
<a href="<?php the_permalink(); ?>" >
<?php endif; ?>
<!-- /リンク設定の有無で切り分け -->
</dd>
<?php endforeach; ?>
</dl>
これでイケサイみたいな表示が可能
ゲットポストスをチェンジさせればいろいろ変更可能
とりあえずメモ書き
<dl class="studioimg">
<?php $posts = get_posts('numberposts=10&category=2&orderby=rand'); ?>
ーーーーーーーーーーーーー
numberposts 表示する投稿数
category=2 表示するカテゴリー
orderby=rand ランダム表示
ーーーーーーーーーーーーーーーー
<?php foreach($posts as $post): ?>
<dd class="imgdd">
<?php //リンク設定の有無で切り分け
$linknourl = get_post_meta( $post->ID, 'linkurl', true );
if ( !empty( $linknourl ) ) : ?>
<?php
//htmlを除去
$linknourl = htmlspecialchars($linknourl,ENT_QUOTES,'UTF-8');
?><span><a href="<?php echo $linknourl; ?>">
<?php the_post_thumbnail(array(150,113)); ?><?php the_title(); ?></a></span>
<?php else : ?>
<a href="<?php the_permalink(); ?>" >
<?php endif; ?>
<!-- /リンク設定の有無で切り分け -->
</dd>
<?php endforeach; ?>
</dl>
これでイケサイみたいな表示が可能
ゲットポストスをチェンジさせればいろいろ変更可能
とりあえずメモ書き
2015年2月5日木曜日
不動産カスタム投稿メモ
add_action('init', 'my_estate_init');
function my_estate_init()
{
$labels = array(
'name' => '登録物件',
'singular_name' => '物件',
'add_new' => '物件の追加',
'add_new_item' => '物件を追加する',
'edit_item' => '物件を編集する',
'new_item' => '新しい物件',
'view_item' => '物件表示',
'search_items' => '物件検索',
'not_found' => '検索物件が見つかりません',
'not_found_in_trash' => 'ゴミ箱に物件はありません',
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 5,
// 'supports' => array('title','editor','author','thumbnail','excerpt','comments')
'supports' => array('title','editor')
);
register_post_type('estate',$args);
flush_rewrite_rules( false );
}
/*** カスタムフィールド項目定義 ***
*
* $meta_arr[$id] = array($name,$array,$option);
* $id: キー
* $name: 項目名
* $array: 保存データ形式('array':配列、'single':テキスト)
* $option: オプション項目
* checkboxの場合は配列として登録される
*/
$meta_arr['esArea' ] = array('エリア', 'array', array('ビジネス街', '住宅街', '商店街', '歓楽街'));
$meta_arr['esCatchcopy'] = array('キャッチコピー', 'single');
$meta_arr['esProfeel' ] = array('物件紹介文', 'single');
$meta_arr['esRental' ] = array('賃料', 'single');
$meta_arr['esNotes' ] = array('備考', 'single');
/*** カスタムフィールドコンテンツの作り込み ***/
function my_meta_boxes() {
global $post, $meta_arr;
//metaの現在の登録値を取得(可変変数)
foreach($meta_arr as $meta => $meta_val) {
$true = ( $meta_val[1] == 'single' )? true: false;
$val = $meta.'Val';
$nam = $meta.'Nam';
$$nam = $meta_val[0];
$$val = get_post_meta( $post->ID, $meta, $true );
}
?>
<div class="postbox postbox_estate">
<h4>物件プロフィール</h4>
<dl>
<dt><?php echo $esAreaNam ?>:</dt>
<dd>
<?php foreach ($meta_arr['esArea'][2] as $optn): ?>
<label><input type="checkbox" name="esArea[]" value="<?php echo $optn ?>"<?php if ( is_array($esAreaVal[0]) ) {if ( in_array($optn, $esAreaVal[0]) ) echo ' checked="checked"';} ?> /> <?php echo $optn ?></label>
<?php endforeach ?></dd>
<dt><?php echo $esCatchcopyNam ?>:</dt>
<dd><textarea name="esCatchcopy" type="textfield" rows="2" style="width:90%"><?php echo $esCatchcopyVal ?></textarea><br />
見出しの下に表示されます。一行に収まる長さでご入力ください。</dd>
<dt><?php echo $esProfeelNam ?>:</dt>
<dd><textarea name="esProfeel" type="textfield" rows="4" style="width:90%"><?php echo $esProfeelVal ?></textarea></dd>
</dl>
</div>
<div class="postbox postbox_estate">
<h4>物件詳細データ</h4>
<dl>
<dt><?php echo $esRentalNam ?>:</dt>
<dd><input name="esRental" type="text" value="<?php echo $esRentalVal ?>" style="width:60%"><br />
○○円/月</dd>
<dt><?php echo $esNotesNam ?>:</dt>
<dd><textarea name="esNotes" type="textfield" rows="4" style="width:90%"><?php echo $esNotesVal ?></textarea></dd>
</dl>
</div>
<?
}
/*** カスタムフィールド入力値の保存 ***/
function save_postdata( $post_id ) {
global $post, $meta_arr;
foreach($meta_arr as $meta => $arr) {
$true = ( $arr == 'single' )? true: false;
$meta_cur = get_post_meta($post_id, $meta, $true);
$meta_new = $_POST[$meta];
if( $meta_cur == "" && $meta_new != "") {
add_post_meta($post_id, $meta, $meta_new, true);
} elseif ( $meta_cur != $meta_new ) {
update_post_meta($post_id, $meta, $meta_new);
} elseif ( $meta_new == "" ) {
delete_post_meta($post_id, $meta, get_post_meta($post_id, $meta_cur, true));
}
}
}
add_action('admin_menu', 'create_meta_box');
add_action('save_post', 'save_postdata');
/*** 投稿画面にカスタムフィールドのセクションを追加 ***/
function create_meta_box() {
if ( function_exists('add_meta_box') )
// add_meta_box('id', 'title', 'callback', 'page', 'context', 'priority');
add_meta_box( 'my-meta-boxes', '物件登録カスタムフィールド', 'my_meta_boxes', 'estate', 'normal', 'high' );
}
function my_estate_init()
{
$labels = array(
'name' => '登録物件',
'singular_name' => '物件',
'add_new' => '物件の追加',
'add_new_item' => '物件を追加する',
'edit_item' => '物件を編集する',
'new_item' => '新しい物件',
'view_item' => '物件表示',
'search_items' => '物件検索',
'not_found' => '検索物件が見つかりません',
'not_found_in_trash' => 'ゴミ箱に物件はありません',
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 5,
// 'supports' => array('title','editor','author','thumbnail','excerpt','comments')
'supports' => array('title','editor')
);
register_post_type('estate',$args);
flush_rewrite_rules( false );
}
/*** カスタムフィールド項目定義 ***
*
* $meta_arr[$id] = array($name,$array,$option);
* $id: キー
* $name: 項目名
* $array: 保存データ形式('array':配列、'single':テキスト)
* $option: オプション項目
* checkboxの場合は配列として登録される
*/
$meta_arr['esArea' ] = array('エリア', 'array', array('ビジネス街', '住宅街', '商店街', '歓楽街'));
$meta_arr['esCatchcopy'] = array('キャッチコピー', 'single');
$meta_arr['esProfeel' ] = array('物件紹介文', 'single');
$meta_arr['esRental' ] = array('賃料', 'single');
$meta_arr['esNotes' ] = array('備考', 'single');
/*** カスタムフィールドコンテンツの作り込み ***/
function my_meta_boxes() {
global $post, $meta_arr;
//metaの現在の登録値を取得(可変変数)
foreach($meta_arr as $meta => $meta_val) {
$true = ( $meta_val[1] == 'single' )? true: false;
$val = $meta.'Val';
$nam = $meta.'Nam';
$$nam = $meta_val[0];
$$val = get_post_meta( $post->ID, $meta, $true );
}
?>
<div class="postbox postbox_estate">
<h4>物件プロフィール</h4>
<dl>
<dt><?php echo $esAreaNam ?>:</dt>
<dd>
<?php foreach ($meta_arr['esArea'][2] as $optn): ?>
<label><input type="checkbox" name="esArea[]" value="<?php echo $optn ?>"<?php if ( is_array($esAreaVal[0]) ) {if ( in_array($optn, $esAreaVal[0]) ) echo ' checked="checked"';} ?> /> <?php echo $optn ?></label>
<?php endforeach ?></dd>
<dt><?php echo $esCatchcopyNam ?>:</dt>
<dd><textarea name="esCatchcopy" type="textfield" rows="2" style="width:90%"><?php echo $esCatchcopyVal ?></textarea><br />
見出しの下に表示されます。一行に収まる長さでご入力ください。</dd>
<dt><?php echo $esProfeelNam ?>:</dt>
<dd><textarea name="esProfeel" type="textfield" rows="4" style="width:90%"><?php echo $esProfeelVal ?></textarea></dd>
</dl>
</div>
<div class="postbox postbox_estate">
<h4>物件詳細データ</h4>
<dl>
<dt><?php echo $esRentalNam ?>:</dt>
<dd><input name="esRental" type="text" value="<?php echo $esRentalVal ?>" style="width:60%"><br />
○○円/月</dd>
<dt><?php echo $esNotesNam ?>:</dt>
<dd><textarea name="esNotes" type="textfield" rows="4" style="width:90%"><?php echo $esNotesVal ?></textarea></dd>
</dl>
</div>
<?
}
/*** カスタムフィールド入力値の保存 ***/
function save_postdata( $post_id ) {
global $post, $meta_arr;
foreach($meta_arr as $meta => $arr) {
$true = ( $arr == 'single' )? true: false;
$meta_cur = get_post_meta($post_id, $meta, $true);
$meta_new = $_POST[$meta];
if( $meta_cur == "" && $meta_new != "") {
add_post_meta($post_id, $meta, $meta_new, true);
} elseif ( $meta_cur != $meta_new ) {
update_post_meta($post_id, $meta, $meta_new);
} elseif ( $meta_new == "" ) {
delete_post_meta($post_id, $meta, get_post_meta($post_id, $meta_cur, true));
}
}
}
add_action('admin_menu', 'create_meta_box');
add_action('save_post', 'save_postdata');
/*** 投稿画面にカスタムフィールドのセクションを追加 ***/
function create_meta_box() {
if ( function_exists('add_meta_box') )
// add_meta_box('id', 'title', 'callback', 'page', 'context', 'priority');
add_meta_box( 'my-meta-boxes', '物件登録カスタムフィールド', 'my_meta_boxes', 'estate', 'normal', 'high' );
}
ファンクションPHpでエラーはいてたのでメモ
文字コードのチェックも空白改行のチェックもしていたのになぜかエラー
あーめんどくさいと思いながらもなぜ文字化けエラーするのか延々と考えていたらようやく解決
http://harumo.net/how-to-safely-edit-functions-php/
上記のブログで発見
?>
これか
これなくせば表示できて解決
あ^-簡単
これは私的メモなので簡素
あーめんどくさいと思いながらもなぜ文字化けエラーするのか延々と考えていたらようやく解決
http://harumo.net/how-to-safely-edit-functions-php/
上記のブログで発見
?>
これか
これなくせば表示できて解決
あ^-簡単
これは私的メモなので簡素
登録:
投稿 (Atom)