フォーラムへの返信

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

    (@takamaniax)

    <?php if(empty($post->post_content)): ?>
    	<li><?php the_title(); ?></li>
    <?php else(): ?>
    	<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endif; ?>

    自己解決しました。
    単純に上記のようにしたら希望通りになりました。
    ありがとうございました。

    トピック投稿者 takamaniax

    (@takamaniax)

    何度もご丁寧に教えていただきありがとうございます。
    ただ、教えていただいた方法でも無理でした。白紙になります。

    function create_post_type_materials() {
    	$labels = array(
    		'name'=> '成分',
    		'all_items' => '成分の一覧',
    	);
    	$args = array(
    		'labels' => $labels,
    		'supports' => array('title','editor','excerpt','thumbnail'),
    		'public' => true, // 公開するかどうか
    		'show_ui' => true, // メニューに表示するかどうか
    		'menu_position' => 5, // メニューの表示位置
    		'has_archive' => true, // アーカイブページの作成
    	);
    	register_post_type( 'materials', $args );
    }
    add_action( 'init', 'create_post_type_materials', 0 );
    
    // 成分タクソノミー
    function create_custom_taxonomy_materials() {
    	register_taxonomy(
    		'materials-cat', // カスタム分類名
    		'materials', // カスタム分類を使用する投稿タイプ名
    		array(
    			'hierarchical' => true,
    			'label' => '成分カテゴリー',
    			'singular_label' => '成分カテゴリー',
    			'public' => true,
    			'show_ui' => true,
    		)
    	);
    }

    今回、上記のようなカスタム投稿タイプをfunctions.phpに書き込んで投稿してます。

    <h2>あ行</h2>
    <ul>
    <?php query_posts( 'materials-cat=a_column' ); ?>
    <?php if(have_posts()) : while (have_posts()) : the_post(); ?>
    <li><a><?php the_title(); ?></a></li>
    <?php endwhile; else: endif?>
    <?php wp_reset_query(); ?>
    </ul>
    
    <h2>か行</h2>
    <ul>
    <?php query_posts( 'materials-cat=ka_column' ); ?>
    <?php if(have_posts()) : while (have_posts()) : the_post(); ?>
    <li><a><?php the_title(); ?></a></li>
    <?php endwhile; else: endif?>
    <?php wp_reset_query(); ?>
    </ul>
    
    <h2>さ行</h2>
    <ul>
    <?php query_posts( 'materials-cat=sa_column' ); ?>
    <?php if(have_posts()) : while (have_posts()) : the_post(); ?>
    <li><a><?php the_title(); ?></a></li>
    <?php endwhile; else: endif?>
    <?php wp_reset_query(); ?>
    </ul>
    
    :
    :
    :

    上記のやり方でリンク付きのリストは問題なく表示できております。
    この表記自体間違ってるのでしょうか?

    トピック投稿者 takamaniax

    (@takamaniax)

    <ul>
    <?php query_posts( 'カスタム分類=fruits' ); ?>
    <?php if(have_posts()) : while (have_posts()) {
    	the_post();
    	$naiyou = get_the_content();
    
    	if( ! empty( $naiyou ) ) {
    		?><li><a href="<?php the_permalink();?>"><?php the_title(); ?></a></li><?php
    	} else {
    		?><li><?php the_title(); ?></li><?php
    	}
    } endwhile; else: endif?>
    <?php wp_reset_query(); ?>
    </ul>

    ということでしょうか?
    無知で申し訳ございません。
    白紙になってしました。

    トピック投稿者 takamaniax

    (@takamaniax)

    りんごというカスタムタグを持つ投稿がないのですか?
    それとも、投稿はあるんだけれど、本文が空欄という意味ですか?

    そうです。『みかん』には本文があるのですが、『りんご』には本文がありません。
    よって、『みかん』に関しては詳細ページにリンクしても問題ないですが、
    『りんご』には詳細ページへのリンクは必要ないということです。

    また、リンクをつける付けないの部分が出来ないのですか? リンクを付けた一覧の表示は出来ているのですか?

    一覧表示はリンク付きで出来てます。
    リンクの有り無しの分岐ができません。
    わかりづらくて申し訳ございません。
    よろしくお願いします。

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