デフォルトの「投稿」が一件もないとユーザプロフィールが表示されない
-
jim912様
コメントありがとうございます。
失礼致しました。
確認が不十分でした。現在ユーザの権限グループによって
author.php内で出力を分けているつもりなのですが
指定権限グループ(以下の例ですと「center_user」)
のユーザが投稿をしていないと以下の出力の出し分けが
有効にならず「center_user」の場合も「author」の
部分で出力されてしまうのです。author.php
<!-- 権限が「center_user」のユーザ情報を出力 --> <?php // 記事を投稿した人のユーザIDからユーザ情報の取得 $user = new WP_User( get_the_author_meta( 'ID' ) ); // 権限が「center_user」だったら出力 if( in_array( 'center_user', $user->roles ) ) { echo(types_render_usermeta_field("name_center", array())); } ?> <!-- END 権限が「center_user」のユーザ情報を出力 --> <!-- 投稿者-authorの場合に表示 --> <?php $user = new WP_User( get_the_author_meta( 'ID' ) ); // 記事を投稿した人のユーザIDからユーザ情報の取得 ?> <?php if( in_array( 'author', $user->roles ) ) : // 投稿者の場合だけ出力 ?> <h3 class="tit">投稿記者紹介</h3> <div class="author_wrapper"> <div class="div_author_1"> <div class="left"> <p><img src="<?php bloginfo( template_url ); ?>/images/page/tit_prof.jpg" width="423" height="15" /></p> <p class="name"><?php the_author_meta( nickname, $author ); ?></p> <p class="birthday">生年月日;<?php the_author_meta( bd, $author ); ?></p> <p class="from">出身地;<?php the_author_meta( from, $author ); ?></p> <p class="prof"><?php the_author_meta( description, $author ); ?></p> <!--floatL--></div> <div class="right"><?php echo get_simple_local_avatar($author,225); ?></div> <!--div_author_1--></div> <div class="div_author_2"> <p><img src="<?php bloginfo( template_url ); ?>/images/page/tit_article.jpg" width="703" height="15" /></p> <ul> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <li> <p class="date"><?php the_time('Y/n/j'); ?></p> <p class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p> </li> <?php endwhile; ?> <?php endif; ?> </ul> </div> <!--div_author_2--> </div> <!--author_wrapper--> <?php endif; ?> <!-- // 投稿者-authorの場合に表示 -->
記述の仕方に問題があるのでしょうか。
get_the_author_meta( 'ID' )
だと、投稿の作成者のIDを取得するようになっているので、投稿がない場合は正しい値を返しません。
author.php であれば、
get_query_var( 'author' )
で、投稿がなくともユーザーのIDが取れるはずです。
jim912様
コメントありがとうございます。
示していただいた記述で投稿がない場合でも
プロフィールページにアクセス出来るようになりました。
ありがとうございます。権限が「author」の場合とそれ以外で出力する内容を
分けようとしており、以下でそれは出来ることが確認できました。<?php $user = new WP_User( get_query_var( 'author' ) ); ?> <?php if( in_array( 'author', $user->roles ) ) : // 投稿者の場合だけ出力 ?> <?php echo 'author'; ?> <?php else : ?> <?php echo 'other'; ?> <?php endif; ?>
が、権限を「寄稿者=contributor」で指定すると
なぜか望む結果が得られず(下記コード)
寄稿者ユーザでもそれ以外でも「other」を出力してしまうのです。<?php $user = new WP_User( get_query_var( 'contributor' ) ); ?> <?php if( in_array( 'contributor', $user->roles ) ) : // 投稿者の場合だけ出力 ?> <?php echo 'contributor'; ?> <?php else : ?> <?php echo 'other'; ?> <?php endif; ?>
ですが、本トピックについてはおかげ様で
解決できましたので、解決済とさせていただきます。
上記の問題については引き続き調べてみようと思います。また別トピックでお世話になるかもしれませんが
このたびはありがとうございました。今後ともよろしくお願い申し上げます。
上記コメント、とんでもなく勘違いをしていました。
以下を読んでその勘違いがわかりました。以下の記述で確認しました。
投稿が一件もなくてもプロフィールページに
アクセスすることができ、登録内容が表示されます。<?php $user = new WP_User( get_the_author_meta( 'ID', get_query_var( 'author' ) ) ); ?> <?php // 権限が「center_user」のプロフィールを出力 if( in_array( 'center_user', $user->roles ) ) : ?> <?php echo 'center_user'; ?> <?php // 権限が「contributor」のプロフィールを出力 elseif( in_array( 'contributor', $user->roles ) ) : ?> <?php echo 'contributor'; ?> <?php endif; ?>
jim912様、あらためてお礼申し上げます。
ありがとうございました。
- トピック「デフォルトの「投稿」が一件もないとユーザプロフィールが表示されない」には新たに返信することはできません。