I am trying to modify a portfolio template in a Wordpress theme. I'd like to apply a specific css class to a specific category of the portfolio, using its ID.
I've tried many things thanks to the different answers already brought here about conditional css (How to apply a CSS class depending on a value contained in PHP variable?), php variables, or about the use of the " foreach", but I wasn't able to find a solution :
May be I didn't put my condition at the right place, or may be is it because of the use of the foreach, or may is there a misplaced tag??
The result remains the same, a full blank page.
I hope you'll have few time to have a look on this and give me a little help. Here is the original code extract :
<?php $terms_array = array(); $id = $cat = null; ?>
<?php foreach ( $p_terms as $term ) { ?>
<?php $terms_array[$term->term_id] = array( 'name' => $term->name ); ?>
<?php } ?>
<?php if ( count( $terms_array ) > 0 ) { ?>
<div class="row">
<div class="col-md-12">
<ul id="ef-portfolio-filter" class="list-inline text-center">
<?php if ( count( $terms_array ) > 1 ) { ?>
<li class="cbp-filter-item-active"><a href="#" data-filter="*"><?php _e( 'All', EF_TDM ) ?>
<span class="cbp-filter-counter"></span>
</a>
</li>
<?php } ?>
<?php $cur = count( $terms_array ) == 1 ? ' class="cbp-filter-item-active"' : ''; ?>
<?php foreach ( $terms_array as $id => $cat ) { ?>
<?php echo '<li' . $cur . '><a data-filter=".cbp-filter-' . $id . '" href="' . esc_url( get_term_link( $id, EF_CPT_TAX_CAT ) ) . '">' . $cat['name'] . '<span class="cbp-filter-counter"></span></a></li>'; ?>
<?php } ?>
</ul><!-- #ef-portfolio-filter -->
</div><!-- .col-md-12 -->
</div><!-- .row -->
<?php } ?>
<?php } ?>
And here is one of my tries. I just paste an extract as I didn't change anything above it and just introduce my condition after the foreach :
<?php $cur = count( $terms_array ) == 1 ? ' class="cbp-filter-item-active"' : ''; ?>
<?php foreach ( $terms_array as $id => $cat ) { ?>
<?php
if ($id = myspecific id)
{echo '<li class="cbp-filter-item-custom"' . $cur . '><a data-filter=".cbp-filter-' . $id . '" href="' . esc_url( get_term_link( $id, EF_CPT_TAX_CAT ) ) . '">' . $cat['name'] . '<span class="cbp-filter-counter-custom"></span></a></li>';
}else{
echo '<li ' . $cur . '><a data-filter=".cbp-filter-' . $id . '" href="' . esc_url( get_term_link( $id, EF_CPT_TAX_CAT ) ) . '">' . $cat['name'] . '<span class="cbp-filter-counter"></span></a></li>' } ?>
</ul><!-- #ef-portfolio-filter -->
error_reporting()in your code.