I have a parts template for a custom theme on wordpress.
It is currently calling in content from a custom field ‘case _studies_extra_box’.
$extra_block = get_field( ‘case_studies_extra_box’, ‘options’ );
Then later displaying that content if conditions are met:
code block
$has_extra_block = $c % 2 != 0;
if ( $has_extra_block ) {
if ( isset( $extra_block['content'] ) && $extra_block['content'] ) {
$extra_block_class = is_front_page() ? 'case-study-extra-block--compact' : '';
?>
<div class="small-12 medium-6 column <?php echo $column_class ?>">
<div class="case-study-extra-block <?php echo $extra_block_class ?>">
<div data-mh="case-study-card-wrapper">
<div class="case-study-extra-block__content">
<?php echo $extra_block['content'] ?>
<a class="case-study-extra-block__button button button--dark-blue"
href="<?php the_permalink( $extra_block['button_target'] ); ?>">
<?php echo $extra_block['button_title']; ?>
<?php echo insert_button_arrow() ?>
</a>
</div>
</div>
</div>
</div>
<?php }
code block
I would like to change this so that it calls in content from a different custom field if part is displaying on a particular page.
I have put in changes for the div classes (if they are on that page):
code block
$has_extra_block = $c % 2 != 0;
if ( $has_extra_block ) {
if ( isset( $extra_block['content'] ) && $extra_block['content'] ) {
$extra_block_class = is_front_page() ? 'case-study-extra-block--compact' : '';
$extra_block_class = is_page_template( $template = 'page-template-adults.php' ) ? 'case-study-extra-block-adults' : '';
$extra_block_button_class = is_page_template( $template = 'page-template-adults.php' ) ? 'case-study-extra-block-adults_button' : '';
?>
<div class="small-12 medium-6 column <?php echo $column_class ?>">
<div class="case-study-extra-block <?php echo $extra_block_class ?>">
<div data-mh="case-study-card-wrapper">
<div class="case-study-extra-block__content">
<?php echo $extra_block['content'] ?>
<a class="case-study-extra-block__button button button--dark-blue <?php echo $extra_block_button_class ?>"
href="<?php the_permalink( $extra_block['button_target'] ); ?>">
<?php echo $extra_block['button_title']; ?>
<?php echo insert_button_arrow() ?>
</a>
</div>
</div>
</div>
</div>
code block
However, I don’t know how to change this so that it calls the actual content from a different custom field, if the user is on that page.
So, if they are on : page-template-adults.php
I want it to : get_field( ‘case_studies_extra_box’, ‘options’ );
This is probably very simple. However I am VERY new to this. So please go gentle with me.
Thanks