WordPress

条件分岐

'19.02.24

TOPページとその他ページの内容を分ける

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php if ( is_home() || is_front_page() ) : ?>
TOPページに表示したい内容
<?php else : ?>
TOPページ以外に表示したい内容
<?php endif; ?>
<?php if ( is_home() || is_front_page() ) : ?> TOPページに表示したい内容 <?php else : ?> TOPページ以外に表示したい内容 <?php endif; ?>
<?php if ( is_home() || is_front_page() ) : ?>
TOPページに表示したい内容
<?php else : ?>
TOPページ以外に表示したい内容
<?php endif; ?>

 

親カテゴリで条件分岐

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php $cat = get_the_category(); $parent_id = $cat[0]->category_parent;?>
<?php if (is_category(1)||$parent_id == 1):?>
ここに処理を記述
<?php endif;?>
<?php $cat = get_the_category(); $parent_id = $cat[0]->category_parent;?> <?php if (is_category(1)||$parent_id == 1):?> ここに処理を記述 <?php endif;?>
<?php $cat = get_the_category(); $parent_id = $cat[0]->category_parent;?>
<?php if (is_category(1)||$parent_id == 1):?>
  ここに処理を記述
<?php endif;?>

 

(View:2112)