pluto1234
フォーラムへの返信
-
フォーラム: 使い方全般
返信が含まれるトピック: プラグインを使わずに人気記事を表示したいhttp://ja.forums.wordpress.org/topic/5294?replies=6
ここに、WP-PostViews でカウントアップした値(値はカスタムフィールド ‘views’ に保存される)を使って、ランキングする方法が載っています。
WP-PostViews:カウントアップのために使用
ランキング表示部:自由にカスタマイズフォーラム: 使い方全般
返信が含まれるトピック: プラグインを使わずに人気記事を表示したい素直に get_posts() を使った方が良いと思います。この場合、人気=コメントの多い順です。
★ functions.phpfunction comments_rank_where( $where = '' ) { $where .= " AND comment_count > 0"; return $where; }<?php global $post; $args = array( 'orderby' => 'comment_count', 'order' => 'DESC', 'suppress_filters' => false, 'numberposts' => 3 ); add_filter( 'posts_where' , 'comments_rank_where' , 10 , 1 ); $my_posts = get_posts( $args ); remove_filter( 'posts_where', 'comments_rank_where' ); if ($my_posts) : echo '<ul>'.PHP_EOL; foreach ($my_posts as $post) : setup_postdata($post); $commentcount = $post->comment_count; ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <?php echo $commentcount; ?></li> <?php endforeach; wp_reset_postdata(); echo '</ul>'.PHP_EOL; endif; ?>※ Popular Posts や Post Views は、コメントの多さで人気を決めているのではないと思いますが・・。
フォーラム: 使い方全般
返信が含まれるトピック: カスタム投稿タイプにて、特定のターム除外およびページネーションする引数に ‘paged’ の指定がないからでは?
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?> <?php $args=array( 'tax_query' => array( array( 'taxonomy' => 'タクソノミー名', 'field' => 'slug', //ターム名をスラッグで指定する 'terms' => array( 'cat00','cat05','cat06','cat07' ) //表示したいタームをスラッグで指定 ) ), 'post_type' => 'カスタム投稿タイプ名', 'paged' => $paged, // ★★★ 'posts_per_page' => 3 //表示件数(-1で全ての記事を表示) ); ?> <?php query_posts( $args ); ?> <?php if (have_posts()) : ?> <?php while (have_posts()) :the_post(); ?> ... 内容 ... <?php endwhile; ?> <?php wp_pagenavi(); ?> <?php endif; ?>フォーラム: プラグイン
返信が含まれるトピック: Advanced Custom Fields Repeater Fieldで投稿がない場合の処理<?php if(get_field('親フィールド')): ?> <ul> <?php while( has_sub_field('親フィールド') ): ?> <?php $url = get_sub_field('子フィールド1'); $title = get_sub_field('子フィールド2'); ?> <?php if (empty($url)) : ?> <?php if (empty($title)) : ?> <!-- どちらもなし --> <li></li> <?php else : ?> <!-- タイトルの入力のみ--> <li><?php echo $title; ?></li> <?php endif; ?> <?php else : ?> <?php if (empty($title)) : ?> <!-- URLの入力のみ --> <li><img src="<?php echo $url; ?>" /></li> <?php else : ?> <!-- 両方入力 --> <li><img src="<?php echo $url; ?>" /><?php echo $title; ?></li> <?php endif; ?> <?php endif; ?> <?php endwhile; ?> </ul> <?php else : ?> <!-- 入力なし --> <?php endif; ?>フォーラム: プラグイン
返信が含まれるトピック: Advanced Custom Fields Repeater Fieldで投稿がない場合の処理「子フィールドの入力が一つもない」ときは、それで合ってます。
しかし、質問の意図は違うと思われます。「子フィールドに入力がなかった場合」というのは、
1) 子フィールド1 の入力がない
2) 子フィールド2 の入力がない
3) 子フィールド1 または 子フィールド2 どちらかの入力がない
4) 子フィールド1 と 子フィールド2 どちらも入力がない
のいずれの条件になりますか?フォーラム: 使い方全般
返信が含まれるトピック: 最新1件全文表示・その他リスト表示の際のdlタグの開始・閉じタグのそこは、さっき修正を追加しておきました。
それにしても
<?php if (get_query_var($taxonomy_name) == 1) : ?>は、まったくおかしいです。
フォーラム: 使い方全般
返信が含まれるトピック: 最新1件全文表示・その他リスト表示の際のdlタグの開始・閉じタグのタクソノミー名なら
<?php $query_obj = get_queried_object(); $taxonomy_obj = get_taxonomy($query_obj->taxonomy); echo esc_html($taxonomy_obj->label); ?>ターム名なら
<?php single_term_title(); ?> もしくは、 <?php $query_obj = get_queried_object(); echo esc_html($query_obj->name); ?>修正
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; <?php if(have_posts()): ?> <?php if ($paged == 1) : ?> :フォーラム: 使い方全般
返信が含まれるトピック: 最新1件全文表示・その他リスト表示の際のdlタグの開始・閉じタグの先頭と2番目以降を分けただけです。
<?php if(have_posts()): the_post(); ?> <?php if( $attachment_id = get_field('top_banner_img') ): ?> <?php $attachment = get_post( $attachment_id ); $size = "full"; // (thumbnail, medium, large, full or custom size) $image = wp_get_attachment_image_src( $attachment_id, $size ); $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true); $image_title = $attachment->post_title; ?> <img src="<?php echo $image[0]; ?>" alt="<?php echo $alt; ?>" title="<?php echo $image_title; ?>" width="250" /> <?php else : ?> <?php the_post_thumbnail(array(250,250)); ?> <?php endif; ?> <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> <?php the_time("Y.n.j") ?> <p><?php echo mb_substr(get_the_content(), 0, 150).'...'; ?></p> <?php endif; ?> <?php if(have_posts()): ?> <dl class="newEntry"> <?php while(have_posts()): the_post(); ?> <dt><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><span><?php the_time("Y.n.j") ?></span></dt> <dd><?php the_excerpt(); ?></dd> <?php endwhile; ?> </dl> <?php endif; ?>ページネーションを付けることを考えると、こちらの方がいいかもしれません。
<?php if(have_posts()): ?> <?php if (get_query_var('paged') == 1) : ?> <?php the_post(); ?> <?php if( $attachment_id = get_field('top_banner_img') ): ?> <?php $attachment = get_post( $attachment_id ); $size = "full"; // (thumbnail, medium, large, full or custom size) $image = wp_get_attachment_image_src( $attachment_id, $size ); $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true); $image_title = $attachment->post_title; ?> <img src="<?php echo $image[0]; ?>" alt="<?php echo $alt; ?>" title="<?php echo $image_title; ?>" width="250" /> <?php else : ?> <?php the_post_thumbnail(array(250,250)); ?> <?php endif; ?> <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> <?php the_time("Y.n.j") ?> <p><?php echo mb_substr(get_the_content(), 0, 150).'...'; ?></p> <?php endif; ?> <?php if(have_posts()): ?> <dl class="newEntry"> <?php while(have_posts()): the_post(); ?> <dt><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><span><?php the_time("Y.n.j") ?></span></dt> <dd><?php the_excerpt(); ?></dd> <?php endwhile; ?> </dl> <?php endif; ?> <!-- ページネーション --> <?php endif; ?>フォーラム: 使い方全般
返信が含まれるトピック: 特定のポストタイプに属する記事一覧にカスタムフィールドの画像を表示>以下のように変数に置き換えれば良い。という意味合いでしょうか?
そうです。
今の時代はコンピュータは高速で、特に Web の場合は、PHP をちょっと変更ところで、全体的なパフォーマンスに影響はありませんが・・。1マイクロ秒くらいは速くなるかもしれません。フォーラム: 使い方全般
返信が含まれるトピック: 特定のポストタイプに属する記事一覧にカスタムフィールドの画像を表示その他、幾つか気になったので書いておきます。
1) if($the_query->have_posts()): が重なっています。
2) 閉じる方の /ul が足りません。
3) 最後は、wp_reset_postdata(); で十分です($wp_query は破壊していないので)。<?php $args = array( 'post_type' => 'article', 'showposts' => 4, ); ?> <?php $the_query = new WP_Query( $args ); ?> <?php if($the_query->have_posts()): ?> <ul class="newlistDouble"> <?php while($the_query->have_posts()):$the_query->the_post(); ?> <li><a>"> <?php if( get_field('top_banner_img') ): ?> <?php $attachment_id = get_field('top_banner_img'); $size = "full"; // (thumbnail, medium, large, full or custom size) $image = wp_get_attachment_image_src( $attachment_id, $size ); $attachment = get_post( get_field('top_banner_img') ); $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true); $image_title = $attachment->post_title; ?> <img src="<?php echo $image[0]; ?>" alt="<?php echo $alt; ?>" title="<?php echo $image_title; ?>" /> <?php else : ?> <?php the_post_thumbnail(array(115,115)); ?> <?php endif; ?> </a><span><a>"><?php echo mb_substr($post->post_title, 0, 25).'...'; ?></a></span><?php echo mb_substr(get_the_excerpt(), 0, 50).'...'; ?></li> <?php endwhile; ?> </ul> <?php endif; ?> <?php wp_reset_postdata(); ?>※追加:get_field(‘top_banner_img’) を何度も呼び出していますが、1回呼び出せばいいはずです。
フォーラム: 使い方全般
返信が含まれるトピック: wp_list_categoriesのカテゴリーという文字を消したい。テキトウに書いても PHP は動きません。
$args に複数の引数を指定する方法は(複数あるのが普通)、
http://wpdocs.sourceforge.jp/%E3%83%86%E3%83%B3%E3%83%97%E3%83%AC%E3%83%BC%E3%83%88%E3%82%BF%E3%82%B0/wp_list_categories
にサンプルが載っています。フォーラム: テーマ
返信が含まれるトピック: カテゴリをリスト表示する際に親と子でクラスを分けたい。wp_list_categories() で ‘walker’ を使えば良いと思います。
http://ja.forums.wordpress.org/topic/10238?replies=5フォーラム: 使い方全般
返信が含まれるトピック: 特定のポストタイプに属する記事一覧にカスタムフィールドの画像を表示このコードは、どこに書いているのですか?本当に index.php ですか?sidebar.php とかじゃないですか?
index.php なら、きちんとポストIDが入っているか調べてみてください。
echo $post->ID; $attachment_id = get_field('top_banner_img',$post->ID); echo $attachment_id;フォーラム: 使い方全般
返信が含まれるトピック: WP_Queryでwp_pagenaviが2ページ目から404エラーになりますフォーラム: 使い方全般
返信が含まれるトピック: カスタム分類の記事詳細ページの作り方について