フォーラムへの返信

8件の返信を表示中 - 1 - 8件目 (全8件中)
  • トピック投稿者 hachinicov

    (@hachinicov)

    自己解決いたしました。お騒がせ致しました。

    下記で希望の表示を行う事ができました。

    <?php
    if ($terms = get_the_terms($post->ID, 'タクソノミー名')) {
        foreach ( $terms as $term ) {
            echo '<p>' . esc_html($term->description) . '</p>';
        }
    }
    ?>

    一応参考ページを残させていただきます。

    ■構文参考
    http://msweb.moo.jp/wordpress/1292/
    http://memocarilog.info/wordpress/theme-custom/5066
    ■返り値参考
    http://elearn.jp/wpman/function/get_the_terms.html

    トピック投稿者 hachinicov

    (@hachinicov)

    pluto1234さま

    ありがとうございます!
    以下にて無事表示することができました。

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
    <?php if(have_posts()): ?>
        <?php if ($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; ?>

    <?php if (get_query_var($taxonomy_name) == 1) : ?>
    は用法としておかしいものだったのですね…。色々と根本的に理解ができていないようなので、この機会に知る事ができてよかったです!
    頂いたコードをきちんと理解できるように、色々調べてみたいと思います。

    この度も貴重なお時間を割いて頂き、まことにありがとうございました。

    トピック投稿者 hachinicov

    (@hachinicov)

    pluto1234さま
    何度もありがとうございます!

    頂いたコードを参考に作ってみたのですが、最新一件のみ表示されません。
    使用方法が間違っているのでしょうか…。

    <?php
    $query_obj = get_queried_object();
    $taxonomy_obj = get_taxonomy($query_obj->taxonomy);
    $taxonomy_name = ($taxonomy_obj->label);
    ?>
    <?php if(have_posts()): ?>
        <?php if (get_query_var($taxonomy_name) == 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 wp_pagenavi(); ?>
        <!-- /ページネーション -->
    <?php endif; ?>
    トピック投稿者 hachinicov

    (@hachinicov)

    EisukeAkimotoさま
    ご回答ありがとうございます!

    サブループで1件画像などを含む記事を取得して、その下からoffsetを指定したループで定義リストを生成する

    すみません。勉強不足で理解しきれていないのですが、追ってしっかり習得したいと思います。

    taikikenさま
    いえ、ご回答いただけて嬉しいです。ありがとうございます!

    pluto1234さま
    またお世話になります。ご回答ありがとうございます。
    できればページネーションをつける形で表示したいと思うのですが、
    頂いた後者のコードの場合
    get_query_var('paged')
    pagedがタクソノミー名(引数?)になるかと思うのですが、
    そのタクソノミーの値を取得する方法が良くわからないので聞いてもよろしいでしょうか?
    色々と調べたのですが、現在表示しているページ(taxonomy.php)でのタクソノミー名取得は下記のような感じで良いのでしょうか…?

    $term = get_term_by(
      'slug',
      get_query_var( 'term' ),
      get_query_var( 'taxonomy' )
    );

    上記を

    <?php echo $term; ?>

    したところCatchable fatal error: Object of class stdClass could not be converted to string in〜と出てしまい、値が取れているのかも不明です。

    初歩的な質問ばかりで申し訳ありませんが、ご回答をいただけますと幸いです。

    トピック投稿者 hachinicov

    (@hachinicov)

    ご回答ありがとうございます!

    なるほど、パフォーマンスの上で変わってくるのですね。
    考えがそこまで至っていなかったので、とても勉強になりました。
    これを機に、もう一歩踏み込んでphpを学びたいと思います。

    この度は貴重な時間を割いて頂き、まことにありがとうございました。

    トピック投稿者 hachinicov

    (@hachinicov)

    何度もすみません、ご丁寧にありがとうございます!
    ミスが多すぎて大変お恥ずかしいです…

    厚かましくもさらにお尋ねさせていただきたいのですが、

    ※追加:get_field(‘top_banner_img’) を何度も呼び出していますが、1回呼び出せばいいはずです。

    は以下のように変数に置き換えれば良い。という意味合いでしょうか?(以下でも動作しました)
    もしよろしければご回答頂ければ幸いです。

    <?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 href="<?php the_permalink(); ?>">
    	<?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; ?>" />
    	<?php else : ?>
    	<?php the_post_thumbnail(array(115,115)); ?>
    	<?php endif; ?>
    
    	</a><span><a href="<?php the_permalink(); ?>"><?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(); ?>
    トピック投稿者 hachinicov

    (@hachinicov)

    たびたび申し訳ありません…一番最初に書いたコードで表示が行えました (´;ω;`)
    Advanced Custom Fieldsの設定をいじっている間に、登録していた画像が設定から外れていたようです。
    お騒がせいたしました。
    pluto1234さん、誠にありがとうございました!

    一応コードを置いておきますので、どなたかの参考になれば幸いです。

    <?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 if ($the_query->have_posts()):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; endif; ?>
    <?php endif; ?>
    <?php wp_reset_query(); ?>

    トピック投稿者 hachinicov

    (@hachinicov)

    ご回答ありがとうございます。
    時間が空いてしまい申し訳ありません。

    どこに書いているのですか?本当に index.php ですか?

    index.phpになります。

    <?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 if ($the_query->have_posts()):while($the_query->have_posts()):$the_query->the_post(); ?>
    	<li><a href="<?php the_permalink(); ?>">
    
    	<?php echo $post->ID;
    	$attachment_id = get_field('top_banner_img',$post->ID);
    	echo $attachment_id; ?>
    
    	</a><span><a href="<?php the_permalink(); ?>"><?php echo mb_substr($post->post_title, 0, 25).'...'; ?></a></span><?php echo mb_substr(get_the_excerpt(), 0, 50).'...'; ?></li>
    	<?php endwhile; endif; ?></ul>
    <?php endif; ?>
    <?php wp_reset_query(); ?>

    頂きましたコードを上記のように致しましたところ、ポストIDらしき数字が表示されました。
    しかしtop_banner_imgの値は表示されていないようでしたので、頂いたコードを分割して表示を行ってみました。

    【1】表示結果→数字

    echo $post->ID;

    【2】表示結果→なし

    $attachment_id = get_field('top_banner_img',$post->ID);
    echo $attachment_id;

    となり、idは入っているようなのですが、フィールドの値を受け取れていないようです…

    引き続きお力を貸して頂けると幸いです。
    よろしくお願い致します。

8件の返信を表示中 - 1 - 8件目 (全8件中)