Display content in the correct category

0

I'm doing a web with ACF, and I'm having complications in how to create a loop so that a part of the content is only loaded on the page of categories with the slug: "rates-all".

To do it, what I did was create a Custom field (a slider) and I told him to load it only in that section (which appears in the image as a store):

Then I told him in the loop-archive.php to load it:

<?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 I load it in all the categories, and I just want it to be loaded in one.

What can I do?

    
asked by Antonio Ángel Estrada Pérez 15.03.2017 в 12:59
source

1 answer

1

To achieve this, you must use a conditional that allows showing or not showing the code that shows the slide.

Taking the names of your concrete example as reference, this would be:

if (has_term ('tarifas-internet', 'tipos-de-tarifas')) {
    //tu código
}

Keep in mind that this conditional, written like this, will only work within the loop.

I hope it has helped you. Greetings!

    
answered by 15.03.2017 / 18:51
source