これは私が取り組んでいるワードプレスサイトから来ていますが、WP固有の質問ではありません。
ユーザーが私のサイトのホームページを見ているかどうかをチェックするif/elsePHPステートメントがあります。彼らがホームページを見ているなら、私はコードが何もしないことを望みます。そうでない場合は、構成にページタイトルを表示するようにします。
私が現在持っているコードは次のとおりです。
<div class="page-header">
<h1>
<?php
if ( is_front_page()){
echo ' ';
}
elseif (is_home()) {
if (get_option('page_for_posts', true)) {
echo get_the_title(get_option('page_for_posts', true));
} else {
_e('Latest Posts', 'roots');
}
} elseif (is_archive()) {
$term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
if ($term) {
echo $term->name;
} elseif (is_post_type_archive()) {
echo get_queried_object()->labels->name;
} elseif (is_day()) {
printf(__('Daily Archives: %s', 'roots'), get_the_date());
} elseif (is_month()) {
printf(__('Monthly Archives: %s', 'roots'), get_the_date('F Y'));
} elseif (is_year()) {
printf(__('Yearly Archives: %s', 'roots'), get_the_date('Y'));
} elseif (is_author()) {
global $post;
$author_id = $post->post_author;
printf(__('Author Archives: %s', 'roots'), get_the_author_meta('display_name', $author_id));
} else {
single_cat_title();
}
} elseif (is_search()) {
printf(__('Search Results for %s', 'roots'), get_search_query());
} elseif (is_404()) {
_e('File Not Found', 'roots');
} else {
the_title();
}
?>
</h1>
</div>
私echo ' ';
はおそらくかなり離れていることを知っていますが、私は絶対的なphp初心者です!現在、これにより空<div>
の<h4>
タグが作成されますが、ホームページをクリーンアップして何も作成しないようにします。
これを実現するために、上記のコードをどのように変更すればよいですか?