• Resolved Astilla VGR

    (@astilla222)


    Hi All,

    in the archive view, Im only showing an image. They are being show in a unique column but I want to have them in 3.

    My approach is to create a div for each line (3 elements in each line). So in archive.php im doing this:

    			while ( have_posts() ) : the_post();
    
    				/*
    				 * Include the Post-Format-specific template for the content.
    				 * If you want to override this in a child theme, then include a file
    				 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
    				 */
    				echo "<div class=line>";
    				get_template_part( 'template-parts/content', get_post_format() );
    				the_post();
    				get_template_part( 'template-parts/content', get_post_format() );
    				the_post();
    				get_template_part( 'template-parts/content', get_post_format() );
    				echo "</div>";
    
    			endwhile;

    And in content file I have this:

    
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    	<header class="entry-header">
    		<?php
    
    		if ( 'post' === get_post_type() ) : ?>
    		<div class="entry-meta">
    			<?php foundation_css_framework_posted_on(); ?>
    		</div><!-- .entry-meta -->
    		<?php
    		endif; ?>
    	</header><!-- .entry-header -->
    
    	<div class="entry-content grid-x">
    			<?php 
    				$span = '<span class=large-4>';
    				$inicio = '<a href="';
    				$link = get_permalink();
    				$intermedio = '">';
    				$portada=types_render_field( "portada");
    				$fin= '</a>';
    				$finspan = '</span>';
    				$portadaenlace = $span . $inicio . $link . $intermedio . $portada . $fin . $finspan;
    				echo $portadaenlace; 
    			?>
    
    	</div><!-- .entry-content -->
    
    	<footer class="entry-footer">
    		<?php foundation_css_framework_entry_footer(); ?>
    	</footer><!-- .entry-footer -->
    </article><!-- #post-<?php the_ID(); ?> -->
    

    On the CSS im trying this:

    
    .line span{
    	display: inline;
    }
    

    But i guess this is redundant since span already should be inline.

    Thanks in advance for your feedback.

    Kind Regards
    VíctorR

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    If it works, don’t fix it? 🙂

    Do you have a specific question? I’m assuming you are looking for general comments and advice.

    Some possible improvements:
    Use the for loop to repeatedly execute repetitive code. Then it’s very easy to change the column count if you change your mind. You do need to deal with the possibility the post coount is not divisible by 3. Use conditionals to verify data is available before trying to output it.

    Or don’t bother breaking the posts into rows. Instead simply output each post in a single long list. Then you needn’t be concerned with not divisible by three issues. Achieve 3 across by floating the post containers left and setting the container’s width to 33%. This sort of list is often placed in a ul/li structure, but it’s not required, regular divs are fine. You can easily control the column count by simply changing the width percentage.

    Or you can let the screen size manage the column count by setting the container width to a fixed size, such as 30rem. The browser will place as many posts across as will fit. But this invariably leaves white space left over.

    I personally do the float left list with percentage widths in these situations.

    Thread Starter Astilla VGR

    (@astilla222)

    Hi @bcworkz Indeed i worked in the posted link and once you checked it it was already solved. BUT YES! I really appreciate your advice coding.

    My main issue, to use a loop, is that I do not uderstand how to deal with “open the line” “close the line”. I suposse I need to include a conditional rule so if it is 0 module division I have to include “open line” and if it is 2 module division (let say we want 3 rows) I have to include “close line”.

    If I am in the right way, could you suggest a codification guide lines or a little example?

    Thanks in advance. Make it works its ok, but to have an efficient and elegant code makes me happy 🙂

    Thread Starter Astilla VGR

    (@astilla222)

    The best option is not to create a Div for each “line”, so it is not needed to open-close en each line.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘archive.php in several columns’ is closed to new replies.