I am making a website with ACF, and I am having complications in how to create a loop so that a part of the content is loaded only on the categories page with the slug: "rates-all".
To do so, what I have done has been to create a Custom field (a slider) and I have told it to load it only in that section (which appears as a store in the image):
Then I have told it in the loop-archive.php to load it for me:
<?php if ( ! have_posts() ) : ?>
<h1><?php _e( 'Not Found', 'limon' ); ?></h1>
<p><?php _e( 'Apologies, but the page you requested could not be found. Perhaps searching will help.', 'limon' ); ?></p>
<?php endif; ?>
<div id="slide_home" class="full marginBottom_2em marginTop_1em">
<?php include('slide_nuevo.php')?>
</div>
<?php while ( have_posts() ) : the_post(); ?>
<div class="marginBottom_1em marginTop_1em">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header>
<?php $url=get_permalink();?>
</header>
<div class="marginTop_1em">
<?php
$id = $post->ID;
$categorias = get_the_terms($id, 'tipos-de-tarifas');
$count = 0;
foreach($categorias as $categoria){
$count ++;
if($count == 1){
$name = $categoria->slug;
$id = $categoria->term_id;
$name_id = 'tipos-de-tarifas_'.$id;
$prueba = get_field('color', $name_id);
}
}
;?>
<div class="grid_3 white paddingBottom_1em">
<a style="width:280px;min-height:200px!important;max-height:200px!important;" class="link" href="<?php echo $url;?>" ><br /></a>
<h3 class="white padding_1em"><?php the_field('velocidad'); ?></h3>
<div class="precio whitecolor padding_1em" style="background:<?php echo $prueba;?>;">
<p class="digitos"><?php the_field('precio'); ?></p>
<p class="decimales">,<?php the_field('decimales_precio'); ?></p>
<p class="euros">€/mes</p>
<p class="condiciones"><?php the_field('condiciones'); ?></p>
<div class="clear"></div>
</div>
</div>
<div class="grid_9">
<h2 class="title left paddingTop_05em">
<a title="<?php printf( esc_attr__( 'Permalink to %s', 'limon' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h2>
<div class="right">
<?php
$id = $post->ID;
$categorias = get_the_terms($id, 'tipos-de-tarifas');
$count = 0;
foreach($categorias as $categoria){
$count++;
//var_dump($categoria);
$id = $categoria->term_id;
$parent = $categoria->parent;
if($count > 1){
break;
}
//$ids = array_fill(0, 6, $id);
//var_dump($ids);
if($id == 15){
}elseif($parent == 15){ }else{echo __('<a class="coberturas_button" href="#">Ver cobertura</a>', 'limon');}
}
?>
<a id="contratar_button" class="inline cboxElement" href="#formulario"><?php echo __('Alta online', 'limon');?></a>
</div>
<div class="clear"></div>
<ul class="caracteristicas">
<?php $caracteristicas = get_field('caracteristicas');
$velocidad = get_field('velocidad_de_bajada_y_subida');
$count = 0;
if (!empty($caracteristicas)){
foreach( $caracteristicas as $caracteristica){
$count ++;
$caracteristica = $caracteristica['caracteristica'];
$par = $count%2;
if($par != 0){
echo '<li class="grid_5 alpha omega izq"><p class="padding_1em">'.$caracteristica.'. </p></li>';
}else{
echo '<li class="grid_4 right alpha omega der"><p class="padding_1em">'.$caracteristica.'. </p></li>';
}
}
}?>
<div class="clear"></div>
</ul>
<?php if($velocidad){
echo '<ul class="caracteristicas"><li class=""><p class="padding_1em"><strong>Velocidad de bajada/subida: '.$velocidad.'</strong></p></li></ul>';
}?>
</div><!--grid_9-->
<div class="clear"></div>
</div><!--marginTop_1em-->
<footer>
</footer>
</article>
<div class="clear"></div>
</div><!--marginBottom_1em-->
<?php endwhile; // End the loop. Whew. ?>
<div class="clear"></div>
<!-- <nav class="grid_8 textAlignRight"> Ocultar paginacion
<?php wp_pagenavi(); ?>
</nav> -->
<div class="clear"></div>
<?php wp_reset_query();?>
</div>
But it loads me in all the categories, and I only want it to load it in one.
What I can do?
To achieve this, you must use a conditional that allows you to show or not show the code that shows the slide.
Taking the names of your specific example as a reference, this would be:
Note that this conditional, written like this, will only work inside the loop.
I hope it could help you. Cheers!