Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Semi-Complex PHP Loop

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #41628
    TWG
    Participant

    I’m stuck on trying to write a loop for a wordpress template. I’m wanting to use the wordpress loop to show mini snippets of blog posts. I wanted to show three items per row and every two rows, have an add show up. Could anyone help me with this?

    This is what my code looks like in HTML.

    	<div class="entry">
    <?php query_posts('cat=23'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div class="one-third column">
    <img src="<?php the_post_thumbnail();?>" alt="<?php post_title(); ?>" />
    <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
    </div>
    <?php endwhile; endif; // end of the loop. ?>
    <?php wp_reset_query(); ?>
    <div class="clear"></div>
    </div><!--/ .entry -->

    #119155

    Could you clarify? Are your “three items” referring to three snippets of blog posts, and what is an “add”?

    #119156
    Anonymous
    Inactive

    I guess you could try something like this:

    $count = 0;
    global $count;
    ?>






    EDIT: Failing with “code” markdown… Can’t seeem to fix it. Check it out on codepen:
    http://codepen.io/joe/pen/Jcfbj

    #119159
    istefan
    Member

    You could make a function like this in your functions.php file:

    http://pastebin.com/h3G44H2a

    and you would call it in your theme as:

    where 23 is your category id, 2 is the number of posts to offset (assuming you would call the function with 0 before and place an ad between) and 3 would be the number of posts to show. this would save you prom copy-pasting the same code.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Back End’ is closed to new topics and replies.