Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2012
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Wordpress help 4 posts per row

    Hello guys, can someone help fix this code ?
    Where is problem ? Any ideas ? It doesn't show anything.
    PHP Code:
    <?php get_header(); ?>
    <?php $counter
    =1;global $query_string;query_posts($query_string.'&caller_get_posts=1&posts_per_page=9');if(have_posts()):while(have_posts()):the_post();if($counter==1):?>

    <div class="post_row">
    <div class="post_class"><?php elseif($counter==2): ?><div class="post_class"><?php elseif($counter==3): ?><div class="post_class"><?php elseif($counter=4): ?><div class="post_class"><?php endif; ?>

    <a href="<?php the_permalink();?>"><?php the_post_thumbnail('default-thumb')?></a>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php the_excerpt() ?>
    </div><!-- /.col -->

    <?php if($counter==2): ?></div><!-- /.row cols2 -->
    <?php if($counter==3): ?></div><!-- /.row cols2 -->
    <?php if($counter==4): ?></div><!-- /.row cols2 -->
    <?php $counter=0;endif;$counter++;endwhile;if($counter==4):?></div><!-- /.row cols2 --><?php endif;endif; ?>
    <?php get_footer
    (); ?>

  • #2
    New Coder
    Join Date
    Dec 2012
    Location
    USA
    Posts
    82
    Thanks
    3
    Thanked 17 Times in 17 Posts
    My god that is some BUTT UGLY code...

    Please for the love of god format your code in a readable fashion...

    Try this:
    This is assuming this code is within a function, since you are declaring a global variable...
    PHP Code:
    <?php
        get_header
    ();
        
    $counter 1;
        global 
    $query_string;
        
    query_posts($query_string.'&caller_get_posts=1&posts_per_page=9');
        if(
    have_posts()){
            while(
    have_posts()){
                
    the_post();
                if(
    $counter == 1){ ?>
                    <div class="post_row"> 
    <?php    ?>
                        <div class="post_class">
                            <a href="<?php the_permalink();?>">
                                <?php the_post_thumbnail('default-thumb')?>
                            </a>
                            <h2>
                                <a href="<?php the_permalink(); ?>">
                                    <?php the_title(); ?>
                                </a>
                            </h2> 
                            <?php the_excerpt() ?> 
                        </div>
    <?php
                
    if($counter == 4){ ?>
                    </div>
    <?php
                    $counter 
    0;
                }
                
    $counter++;
            }
        }
        
    get_footer();
    ?>
    If this doesn't work it's because your code is literally crap (sorry for being blunt). Please post every line of code that this is related to, including the parent function/class/whatever
    Last edited by TFlan; 01-10-2013 at 04:49 PM.

  • Users who have thanked TFlan for this post:

    aiva286 (01-10-2013)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •