Wordpress初心者です。
カスタム投稿タイプの投稿者別ページに記事が表示されず、タイトルも変になります。
functions.php
php
1add_action( 'init', 'create_post_type' ); 2function create_post_type() { 3 register_post_type( 4 'test1', 5 array( 6 'labels' => array( 7 'name' => __( 'テスト1' ), 8 'singular_name' => __( 'テスト1' ) 9 ), 10 'public' => true, 11 'menu_position' =>5, 12 ) 13 ); 14 register_post_type( 15 'test2', 16 array( 17 'labels' => array( 18 'name' => __( 'テスト2' ), 19 'singular_name' => __( 'テスト2' ) 20 ), 21 'public' => true, 22 'menu_position' =>5, 23 ) 24 ); 25} 26
author.php
php
1<?php get_header(); ?> 2<div class="contentInner"> 3<main id="main"> 4 <h2><?php echo get_the_archive_title(); ?></h2> 5 <?php if(have_posts()): while(have_posts()): the_post(); ?> 6 <a href="<?php the_permalink(); ?>"> 7 <time datetime="<?php echo get_the_date( 'Y-m-d' ); ?>"><?php echo get_the_date( 'Y-m-d' ); ?></time> 8 <div class="xxx"><?php if(mb_strlen($post->post_title)>20){$title= mb_substr($post->post_title,0,20) ;echo $title . '...';}else{echo $post->post_title;} ?></div> 9 <div class="xxx"><?php $str = get_the_excerpt();echo na_trim_words($str,70); ?></div> 10 </a> 11 <?php endwhile; ?><?php else: ?> 12 <div class="search_notfound"><p>該当する記事が見つかりませんでした。</p></div> 13 <?php endif; ?> 14 <div class="pagination">省略</div> 15</main> 16<?php get_sidebar(); ?> 17</div> 18<?php get_footer(); ?>
分からないなりに調べて、上記のように書きました。
ですが、「該当する記事が見つかりませんでした。」となってしまいます。
サンプルで3人「投稿者」としてユーザーを追加して、それぞれ2つずつ記事を書いたのですが、3人とも表示されません。
トップページに
php
1<?php 2$query = new WP_Query( 3 array( 4 'post_type' => 'test1', 5 'posts_per_page' => 5, 6 ) 7); 8if ( $query->have_posts() ) : ?> 9<div class="xxx"><dl> 10<?php while ( $query->have_posts() ) : $query->the_post();?> 11<a href="<?php the_permalink() ?>"><dt><?php echo get_the_date() ?><span><?php echo get_the_author() ?></span></dt><dd><?php the_title_attribute() ?></dd></a> 12<?php endwhile; ?> 13</dl></div> 14<?php endif; wp_reset_postdata(); ?>
と書いていますが、こちらはちゃんと表示されます。
ですが、ユーザー別にこれを表示したいです。
記事のページに「<?php the_author_posts_link(); ?>」としたら「ドメイン/author/ユーザー名」ページに飛ぶのですが、これを表示するのは「author.php」で間違っていないですか?
また、「author.php」で「<?php echo get_the_archive_title(); ?>」としているところが「作者別: <span class="vcard"></span>」と表示され、名前も表示されません。
そもそもvcardって何でしょうか?
どこが間違っているのかもよくわからないのですが、分かる方がみえましたら、よろしくお願いいたします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。