Enea Dhiamandi
Forum Replies Created
-
Thanks Sumit thats much better.
I found the solution.. u just need to use the modulo operator.
5 % 2 = 1
9 % 3 = 0
11 % 7 = 4<div id="container"> <?php if (have_posts()) : $count = 0; while (have_posts()) : the_post(); $count++; ?> <?php if($count % 11 == 1) : ?> <div class="block bn1">< ..(this is a post).. ></div> <?php endif; ?> <?php if($count % 11 == 2) : ?> <div class="block bn2">< ..(this is a post).. ></div> <?php endif; ?> <?php if($count % 11 == 3) : ?> <div class="block bn3">< ..(this is a post).. ></div> <?php endif; ?> etc.... <?php endwhile; endif;?> </div>This will repeat the cycle after the 10th post in the loop by hardcodyng only 10 divs.
Thank you.. I’ve thought using this method but unfortunately it does not help in my situation because i need the cycle of bn# to start over from bn1 and not continue counting.
I also have to hardcode at least the first 10 divs because i have some in between code. Writing just one line is not an option for this situation.
Again thanks alot Sumit
Lets say i have some divs that have a certain style and they have to be repeated in the exact same way inside a loop.
HTML:
<div id="container"> <div class="block bn1">< ..(this is a post).. ></div> <div class="block bn2">< ..(this is a post).. ></div> <div class="block bn3">< ..(this is a post).. ></div> <div class="block bn4">< ..(this is a post).. ></div> <div class="block bn5">< ..(this is a post).. ></div> <div class="block bn6">< ..(this is a post).. ></div> <div class="block bn7">< ..(this is a post).. ></div> <div class="block bn8">< ..(this is a post).. ></div> <div class="block bn9">< ..(this is a post).. ></div> <div class="block bn10">< ..(this is a post).. ></div> </div>As you can see the block divs have a different bn# that will give a different style to each post
PHP:
What i have achieved so far is not a great solution because i have to hardcode each div in advance.. i need a more dynamic code that will cycle my divs
<div id="container"> <?php if (have_posts()) : $count = 0; while (have_posts()) : the_post(); $count++; ?> <?php if ($count == 1) : ?> <div class="block bn1">< ..(this is a post).. ></div> <?php endif; ?> <?php if ($count == 2) : ?> <div class="block bn2">< ..(this is a post).. ></div> <?php endif; ?> <?php if ($count == 3) : ?> <div class="block bn3">< ..(this is a post).. ></div> <?php endif; ?> <?php if ($count == 4) : ?> <div class="block bn4">< ..(this is a post).. ></div> <?php endif; ?> <?php if ($count == 5) : ?> <div class="block bn5">< ..(this is a post).. ></div> <?php endif; ?> <?php if ($count == 6) : ?> <div class="block bn6">< ..(this is a post).. ></div> <?php endif; ?> <?php if ($count == 7) : ?> <div class="block bn7">< ..(this is a post).. ></div> <?php endif; ?> <?php if ($count == 8) : ?> <div class="block bn9">< ..(this is a post).. ></div> <?php endif; ?> <?php if ($count == 9) : ?> <div class="block bn9">< ..(this is a post).. ></div> <?php endif; ?> <?php if ($count == 10) : ?> <div class="block bn10">< ..(this is a post).. ></div> <?php endif; ?> <!== After this point it has to cycle each bn# div ==!> <?php if ($count == 11) : ?> <div class="block bn1">< ..(this is a post).. ></div> <?php endif; ?> <?php if ($count == 12) : ?> <div class="block bn2">< ..(this is a post).. ></div> <?php endif; ?> <?php if ($count == 13) : ?> <div class="block bn3">< ..(this is a post).. ></div> <?php endif; ?> <?php if ($count == 14) : ?> <div class="block bn4">< ..(this is a post).. ></div> <?php endif; ?> etc.... <?php endwhile; endif;?> </div>I hope i make sense Sumit and thank you for your time.
Forum: Plugins
In reply to: WP Paginate doesn't work in my Custom Post Type Archive PageI did what you said man and it worked.. changed the temp to archive and re-changed my permalinks and everything worked like a charm.. fixed the pagination and several bugs I couldn’t fix.. thanks alot man!
Forum: Plugins
In reply to: WP Paginate doesn't work in my Custom Post Type Archive PageI added this in functions.php :
register_post_type( 'consumables', array( 'labels' => array( 'name' => __( 'Consumables' ), 'singular_name' => __( 'Consumable' ) ), 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'has_archive' => true, 'hierarchical' => false, 'menu_position' => null, 'supports' => array( 'title', 'editor', 'thumbnail') ) );And created the archive-consumables.php template as you said but I can’t find the way to see the result of the template.. what url should a post type archive generate with %Postname% permalinks set in the wordpress options?
I have tried adding archive templates before but I needed a easy way for my client to access and add the archives in the navigation without much frustration, so I enabled categories in the custom post type to make it easier to add in custom menu and it messed my custom tags for good.. that’s why i chose Page Template!
Thanks for your effort man,
i appreciate it!