WP Query Code to display unique div classes and WP Functions The Next CEO of Stack Overflowadd a page to sidebarsimple php counter3 column WordPress layout help neededCan't Create Nested DIVsWordPress Paradox - Normal posts not being queriedHow to better implement Like/Unlike System using mysqlCustom page template displaying loop of posts (Wordpress queries)WordPress custom post type pagination links return 404PHP iterating through a count shows incorrect sequenceForm to pull page elements using file_get_contents and getElementsByClassName in PHP

When you upcast Blindness/Deafness, do all targets suffer the same effect?

Why doesn't UK go for the same deal Japan has with EU to resolve Brexit?

Why isn't the Mueller report being released completely and unredacted?

Rotate a column

Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?

Does Germany produce more waste than the US?

The past simple of "gaslight" – "gaslighted" or "gaslit"?

Necessary condition on homology group for a set to be contractible

How to delete every two lines after 3rd lines in a file contains very large number of lines?

Is it my responsibility to learn a new technology in my own time my employer wants to implement?

Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis

Bartok - Syncopation (1): Meaning of notes in between Grand Staff

Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?

Is micro rebar a better way to reinforce concrete than rebar?

Is there a difference between "Fahrstuhl" and "Aufzug"

If Nick Fury and Coulson already knew about aliens (Kree and Skrull) why did they wait until Thor's appearance to start making weapons?

Find non-case sensitive string in a mixed list of elements?

Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?

Method for adding error messages to a dictionary given a key

Is French Guiana a (hard) EU border?

What was the first Unix version to run on a microcomputer?

Why do remote US companies require working in the US?

Is it okay to majorly distort historical facts while writing a fiction story?

Why do airplanes bank sharply to the right after air-to-air refueling?



WP Query Code to display unique div classes and WP Functions



The Next CEO of Stack Overflowadd a page to sidebarsimple php counter3 column WordPress layout help neededCan't Create Nested DIVsWordPress Paradox - Normal posts not being queriedHow to better implement Like/Unlike System using mysqlCustom page template displaying loop of posts (Wordpress queries)WordPress custom post type pagination links return 404PHP iterating through a count shows incorrect sequenceForm to pull page elements using file_get_contents and getElementsByClassName in PHP










1















I am trying to add a WP Query code that will list all the post in my wordpress blog.



This code will be in a custom template under my created page in my wordpress blog.



The purpose of this wp query code is to display all post on a unique div classes and has a different html/php structure. For example, Post # 1 will display the title and the excerpt while the Post # 2 will display the title and the content and so on.



Below is the aforementioned code:



<?php /*** Template Name: Custom Page - Blog */ get_header(); ?>

<!-- START of WP Query -->

<?php $the_query = new WP_Query( array("post_type"=>'post')); ?>

<?php if ( $the_query->have_posts() ) : ?>

<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>

<?php $count++; ?>

<?php if ($count == 1) : ?>
<div class="item1">
<span>Post 1 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count == 2) : ?>
<div class="item2">
<span>Post 2 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count == 3) : ?>
<div class="item3">
<span>Post 3 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count == 4) : ?>
<div class="item4">
<span>Post 4 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count == 5) : ?>
<div class="item5">
<span>Post 5</span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count <= 7) : ?>
<div class="item6">
<span>Post 6 to 7 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 8 && $count <= 16) : ?>
<div class="item6">
<span>Post 8 to 15 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 17) : ?>
<div class="item6">
<span>Post 16 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->


<?php
global $wp_query;

$big = 999999999; // need an unlikely integer

echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
?>


<?php else : ?>

<?php endif; ?>
<?php endwhile; ?>
<?php else : ?>
<p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

<!-- END of WP Query -->


The issue with the code above is its not properly displaying what I want. It displays the post # 1 to 5 but after that it doesnt follow the conditions $count >= 5 || $count <= 7, $count >= 8 || $count <= 15, $count >= 8 || $count <= 15 and $count >= 16.



Also the code for numbered pagination doesn't work. It don't display anything:



<?php
global $wp_query;

$big = 999999999; // need an unlikely integer

echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
?>


Also, here's the link of my webpage so you can see what's happening when the code is implemented.



any ideas? any help that you can offer is very much appreciated. Thank you very much!










share|improve this question
























  • You should be using && for the second-to-last condition, otherwise it will be pulling in everything greater than 8 OR less than 15 (including the last condition of >= 16). Try <?php elseif ($count >= 8 && $count <= 15) : ?> Otherwise, please provide example data and the output that you are getting.

    – mtr.web
    Mar 8 at 16:26
















1















I am trying to add a WP Query code that will list all the post in my wordpress blog.



This code will be in a custom template under my created page in my wordpress blog.



The purpose of this wp query code is to display all post on a unique div classes and has a different html/php structure. For example, Post # 1 will display the title and the excerpt while the Post # 2 will display the title and the content and so on.



Below is the aforementioned code:



<?php /*** Template Name: Custom Page - Blog */ get_header(); ?>

<!-- START of WP Query -->

<?php $the_query = new WP_Query( array("post_type"=>'post')); ?>

<?php if ( $the_query->have_posts() ) : ?>

<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>

<?php $count++; ?>

<?php if ($count == 1) : ?>
<div class="item1">
<span>Post 1 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count == 2) : ?>
<div class="item2">
<span>Post 2 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count == 3) : ?>
<div class="item3">
<span>Post 3 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count == 4) : ?>
<div class="item4">
<span>Post 4 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count == 5) : ?>
<div class="item5">
<span>Post 5</span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count <= 7) : ?>
<div class="item6">
<span>Post 6 to 7 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 8 && $count <= 16) : ?>
<div class="item6">
<span>Post 8 to 15 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 17) : ?>
<div class="item6">
<span>Post 16 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->


<?php
global $wp_query;

$big = 999999999; // need an unlikely integer

echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
?>


<?php else : ?>

<?php endif; ?>
<?php endwhile; ?>
<?php else : ?>
<p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

<!-- END of WP Query -->


The issue with the code above is its not properly displaying what I want. It displays the post # 1 to 5 but after that it doesnt follow the conditions $count >= 5 || $count <= 7, $count >= 8 || $count <= 15, $count >= 8 || $count <= 15 and $count >= 16.



Also the code for numbered pagination doesn't work. It don't display anything:



<?php
global $wp_query;

$big = 999999999; // need an unlikely integer

echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
?>


Also, here's the link of my webpage so you can see what's happening when the code is implemented.



any ideas? any help that you can offer is very much appreciated. Thank you very much!










share|improve this question
























  • You should be using && for the second-to-last condition, otherwise it will be pulling in everything greater than 8 OR less than 15 (including the last condition of >= 16). Try <?php elseif ($count >= 8 && $count <= 15) : ?> Otherwise, please provide example data and the output that you are getting.

    – mtr.web
    Mar 8 at 16:26














1












1








1








I am trying to add a WP Query code that will list all the post in my wordpress blog.



This code will be in a custom template under my created page in my wordpress blog.



The purpose of this wp query code is to display all post on a unique div classes and has a different html/php structure. For example, Post # 1 will display the title and the excerpt while the Post # 2 will display the title and the content and so on.



Below is the aforementioned code:



<?php /*** Template Name: Custom Page - Blog */ get_header(); ?>

<!-- START of WP Query -->

<?php $the_query = new WP_Query( array("post_type"=>'post')); ?>

<?php if ( $the_query->have_posts() ) : ?>

<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>

<?php $count++; ?>

<?php if ($count == 1) : ?>
<div class="item1">
<span>Post 1 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count == 2) : ?>
<div class="item2">
<span>Post 2 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count == 3) : ?>
<div class="item3">
<span>Post 3 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count == 4) : ?>
<div class="item4">
<span>Post 4 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count == 5) : ?>
<div class="item5">
<span>Post 5</span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count <= 7) : ?>
<div class="item6">
<span>Post 6 to 7 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 8 && $count <= 16) : ?>
<div class="item6">
<span>Post 8 to 15 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 17) : ?>
<div class="item6">
<span>Post 16 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->


<?php
global $wp_query;

$big = 999999999; // need an unlikely integer

echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
?>


<?php else : ?>

<?php endif; ?>
<?php endwhile; ?>
<?php else : ?>
<p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

<!-- END of WP Query -->


The issue with the code above is its not properly displaying what I want. It displays the post # 1 to 5 but after that it doesnt follow the conditions $count >= 5 || $count <= 7, $count >= 8 || $count <= 15, $count >= 8 || $count <= 15 and $count >= 16.



Also the code for numbered pagination doesn't work. It don't display anything:



<?php
global $wp_query;

$big = 999999999; // need an unlikely integer

echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
?>


Also, here's the link of my webpage so you can see what's happening when the code is implemented.



any ideas? any help that you can offer is very much appreciated. Thank you very much!










share|improve this question
















I am trying to add a WP Query code that will list all the post in my wordpress blog.



This code will be in a custom template under my created page in my wordpress blog.



The purpose of this wp query code is to display all post on a unique div classes and has a different html/php structure. For example, Post # 1 will display the title and the excerpt while the Post # 2 will display the title and the content and so on.



Below is the aforementioned code:



<?php /*** Template Name: Custom Page - Blog */ get_header(); ?>

<!-- START of WP Query -->

<?php $the_query = new WP_Query( array("post_type"=>'post')); ?>

<?php if ( $the_query->have_posts() ) : ?>

<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>

<?php $count++; ?>

<?php if ($count == 1) : ?>
<div class="item1">
<span>Post 1 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count == 2) : ?>
<div class="item2">
<span>Post 2 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count == 3) : ?>
<div class="item3">
<span>Post 3 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count == 4) : ?>
<div class="item4">
<span>Post 4 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count == 5) : ?>
<div class="item5">
<span>Post 5</span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count <= 7) : ?>
<div class="item6">
<span>Post 6 to 7 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 8 && $count <= 16) : ?>
<div class="item6">
<span>Post 8 to 15 </span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 17) : ?>
<div class="item6">
<span>Post 16 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->


<?php
global $wp_query;

$big = 999999999; // need an unlikely integer

echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
?>


<?php else : ?>

<?php endif; ?>
<?php endwhile; ?>
<?php else : ?>
<p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

<!-- END of WP Query -->


The issue with the code above is its not properly displaying what I want. It displays the post # 1 to 5 but after that it doesnt follow the conditions $count >= 5 || $count <= 7, $count >= 8 || $count <= 15, $count >= 8 || $count <= 15 and $count >= 16.



Also the code for numbered pagination doesn't work. It don't display anything:



<?php
global $wp_query;

$big = 999999999; // need an unlikely integer

echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
?>


Also, here's the link of my webpage so you can see what's happening when the code is implemented.



any ideas? any help that you can offer is very much appreciated. Thank you very much!







php wordpress






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 16:57

























asked Mar 8 at 16:07







user11003760



















  • You should be using && for the second-to-last condition, otherwise it will be pulling in everything greater than 8 OR less than 15 (including the last condition of >= 16). Try <?php elseif ($count >= 8 && $count <= 15) : ?> Otherwise, please provide example data and the output that you are getting.

    – mtr.web
    Mar 8 at 16:26


















  • You should be using && for the second-to-last condition, otherwise it will be pulling in everything greater than 8 OR less than 15 (including the last condition of >= 16). Try <?php elseif ($count >= 8 && $count <= 15) : ?> Otherwise, please provide example data and the output that you are getting.

    – mtr.web
    Mar 8 at 16:26

















You should be using && for the second-to-last condition, otherwise it will be pulling in everything greater than 8 OR less than 15 (including the last condition of >= 16). Try <?php elseif ($count >= 8 && $count <= 15) : ?> Otherwise, please provide example data and the output that you are getting.

– mtr.web
Mar 8 at 16:26






You should be using && for the second-to-last condition, otherwise it will be pulling in everything greater than 8 OR less than 15 (including the last condition of >= 16). Try <?php elseif ($count >= 8 && $count <= 15) : ?> Otherwise, please provide example data and the output that you are getting.

– mtr.web
Mar 8 at 16:26













1 Answer
1






active

oldest

votes


















1














You should review PHP Logical Operators. The || operator in the elseif ($count >= 5 || $count <= 7) condition will pull anything >= 5 OR anything <=7, which is any and all numbers. The same applies to the following condition with 8 and 15, so the following solution should fix your problem:





Post 1



<?php elseif ($count == 2) : ?> 
<div class="item2">
<span>Post 2</span><?php the_title(); ?><?php the_content(); ?>
</div><!-- .item# -->

<?php elseif ($count == 3) : ?>
<div class="item3">
<span>Post 3</span><?php the_title(); ?><?php the_author(); ?>
</div><!-- .item# -->

<?php elseif ($count == 4) : ?>
<div class="item4">
<span>Post 4</span><?php the_title(); ?><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count == 5) : ?>
<div class="item5">
<span>Post 5</span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 5 && $count <= 7) : ?>
<div class="item6">
<span>Post 6 to 7</span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 8 && $count <= 15) : ?>
<div class="item6">
<span>Post 8 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 16) : ?>
<div class="item6">
<span>Post 8 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->


NOTE:
The better solution is to omit the second part of these comparisons, because we already know that it is >= 5 for the first one and >= 8 for the second one. Easiest, cleanest solution looks like this:



...

<?php elseif ($count <= 7) : ?>
<div class="item6">
<span>Post 6 to 7</span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count <= 15) : ?>
<div class="item6">
<span>Post 8 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->

...





EDIT
The question has changed, and the above code may hold some value, so I am keeping it, but the last two conditions should look like this:



From the previous conditions, we already know that $count is >= 8, so removing that portion of the second-to-last condition will work fine:



<?php elseif ($count <= 16) : ?> 
<div class="item6">
<span>Post 8 to 16 </span><?php the_title(); ?>
</div><!-- .item# -->


From the previous conditions, we already know that all remaining values for $count will be >= 17, so a simple 'else' will work fine:



<?php else : ?> 
<div class="item6">
<span>Post 16 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->





share|improve this answer

























  • I wanted to say that your thoughtful and well-written post was very helpful, and I appreciate what you do. Take my upvote!

    – dmanexe
    Mar 8 at 16:35











  • thank you @mtr.web for your help. I've corrected the codes but there's still issues. the last three conditions $count >= 8 && $count >= 16 and $count > 17 doesn't work. It doesn't display the post # 16 onwards. What seems to be the problem? I have updated my codes from my question above.

    – user11003760
    Mar 8 at 16:59











  • @DanicaEscola, I edited the answer. If it works for you, don't forget to accept/upvote. Otherwise, let me know what is/isn't happening now, and I will edit the answer to fit.

    – mtr.web
    Mar 8 at 18:30











  • I'm not sure why $count <= 16 is only displaying 3 post which in fact it should display post 8, 9, 10 to 16. what's the issue with $count <=16?

    – user11003760
    Mar 9 at 3:22











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55066909%2fwp-query-code-to-display-unique-div-classes-and-wp-functions%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown
























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You should review PHP Logical Operators. The || operator in the elseif ($count >= 5 || $count <= 7) condition will pull anything >= 5 OR anything <=7, which is any and all numbers. The same applies to the following condition with 8 and 15, so the following solution should fix your problem:





Post 1



<?php elseif ($count == 2) : ?> 
<div class="item2">
<span>Post 2</span><?php the_title(); ?><?php the_content(); ?>
</div><!-- .item# -->

<?php elseif ($count == 3) : ?>
<div class="item3">
<span>Post 3</span><?php the_title(); ?><?php the_author(); ?>
</div><!-- .item# -->

<?php elseif ($count == 4) : ?>
<div class="item4">
<span>Post 4</span><?php the_title(); ?><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count == 5) : ?>
<div class="item5">
<span>Post 5</span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 5 && $count <= 7) : ?>
<div class="item6">
<span>Post 6 to 7</span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 8 && $count <= 15) : ?>
<div class="item6">
<span>Post 8 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 16) : ?>
<div class="item6">
<span>Post 8 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->


NOTE:
The better solution is to omit the second part of these comparisons, because we already know that it is >= 5 for the first one and >= 8 for the second one. Easiest, cleanest solution looks like this:



...

<?php elseif ($count <= 7) : ?>
<div class="item6">
<span>Post 6 to 7</span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count <= 15) : ?>
<div class="item6">
<span>Post 8 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->

...





EDIT
The question has changed, and the above code may hold some value, so I am keeping it, but the last two conditions should look like this:



From the previous conditions, we already know that $count is >= 8, so removing that portion of the second-to-last condition will work fine:



<?php elseif ($count <= 16) : ?> 
<div class="item6">
<span>Post 8 to 16 </span><?php the_title(); ?>
</div><!-- .item# -->


From the previous conditions, we already know that all remaining values for $count will be >= 17, so a simple 'else' will work fine:



<?php else : ?> 
<div class="item6">
<span>Post 16 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->





share|improve this answer

























  • I wanted to say that your thoughtful and well-written post was very helpful, and I appreciate what you do. Take my upvote!

    – dmanexe
    Mar 8 at 16:35











  • thank you @mtr.web for your help. I've corrected the codes but there's still issues. the last three conditions $count >= 8 && $count >= 16 and $count > 17 doesn't work. It doesn't display the post # 16 onwards. What seems to be the problem? I have updated my codes from my question above.

    – user11003760
    Mar 8 at 16:59











  • @DanicaEscola, I edited the answer. If it works for you, don't forget to accept/upvote. Otherwise, let me know what is/isn't happening now, and I will edit the answer to fit.

    – mtr.web
    Mar 8 at 18:30











  • I'm not sure why $count <= 16 is only displaying 3 post which in fact it should display post 8, 9, 10 to 16. what's the issue with $count <=16?

    – user11003760
    Mar 9 at 3:22















1














You should review PHP Logical Operators. The || operator in the elseif ($count >= 5 || $count <= 7) condition will pull anything >= 5 OR anything <=7, which is any and all numbers. The same applies to the following condition with 8 and 15, so the following solution should fix your problem:





Post 1



<?php elseif ($count == 2) : ?> 
<div class="item2">
<span>Post 2</span><?php the_title(); ?><?php the_content(); ?>
</div><!-- .item# -->

<?php elseif ($count == 3) : ?>
<div class="item3">
<span>Post 3</span><?php the_title(); ?><?php the_author(); ?>
</div><!-- .item# -->

<?php elseif ($count == 4) : ?>
<div class="item4">
<span>Post 4</span><?php the_title(); ?><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count == 5) : ?>
<div class="item5">
<span>Post 5</span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 5 && $count <= 7) : ?>
<div class="item6">
<span>Post 6 to 7</span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 8 && $count <= 15) : ?>
<div class="item6">
<span>Post 8 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 16) : ?>
<div class="item6">
<span>Post 8 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->


NOTE:
The better solution is to omit the second part of these comparisons, because we already know that it is >= 5 for the first one and >= 8 for the second one. Easiest, cleanest solution looks like this:



...

<?php elseif ($count <= 7) : ?>
<div class="item6">
<span>Post 6 to 7</span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count <= 15) : ?>
<div class="item6">
<span>Post 8 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->

...





EDIT
The question has changed, and the above code may hold some value, so I am keeping it, but the last two conditions should look like this:



From the previous conditions, we already know that $count is >= 8, so removing that portion of the second-to-last condition will work fine:



<?php elseif ($count <= 16) : ?> 
<div class="item6">
<span>Post 8 to 16 </span><?php the_title(); ?>
</div><!-- .item# -->


From the previous conditions, we already know that all remaining values for $count will be >= 17, so a simple 'else' will work fine:



<?php else : ?> 
<div class="item6">
<span>Post 16 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->





share|improve this answer

























  • I wanted to say that your thoughtful and well-written post was very helpful, and I appreciate what you do. Take my upvote!

    – dmanexe
    Mar 8 at 16:35











  • thank you @mtr.web for your help. I've corrected the codes but there's still issues. the last three conditions $count >= 8 && $count >= 16 and $count > 17 doesn't work. It doesn't display the post # 16 onwards. What seems to be the problem? I have updated my codes from my question above.

    – user11003760
    Mar 8 at 16:59











  • @DanicaEscola, I edited the answer. If it works for you, don't forget to accept/upvote. Otherwise, let me know what is/isn't happening now, and I will edit the answer to fit.

    – mtr.web
    Mar 8 at 18:30











  • I'm not sure why $count <= 16 is only displaying 3 post which in fact it should display post 8, 9, 10 to 16. what's the issue with $count <=16?

    – user11003760
    Mar 9 at 3:22













1












1








1







You should review PHP Logical Operators. The || operator in the elseif ($count >= 5 || $count <= 7) condition will pull anything >= 5 OR anything <=7, which is any and all numbers. The same applies to the following condition with 8 and 15, so the following solution should fix your problem:





Post 1



<?php elseif ($count == 2) : ?> 
<div class="item2">
<span>Post 2</span><?php the_title(); ?><?php the_content(); ?>
</div><!-- .item# -->

<?php elseif ($count == 3) : ?>
<div class="item3">
<span>Post 3</span><?php the_title(); ?><?php the_author(); ?>
</div><!-- .item# -->

<?php elseif ($count == 4) : ?>
<div class="item4">
<span>Post 4</span><?php the_title(); ?><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count == 5) : ?>
<div class="item5">
<span>Post 5</span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 5 && $count <= 7) : ?>
<div class="item6">
<span>Post 6 to 7</span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 8 && $count <= 15) : ?>
<div class="item6">
<span>Post 8 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 16) : ?>
<div class="item6">
<span>Post 8 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->


NOTE:
The better solution is to omit the second part of these comparisons, because we already know that it is >= 5 for the first one and >= 8 for the second one. Easiest, cleanest solution looks like this:



...

<?php elseif ($count <= 7) : ?>
<div class="item6">
<span>Post 6 to 7</span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count <= 15) : ?>
<div class="item6">
<span>Post 8 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->

...





EDIT
The question has changed, and the above code may hold some value, so I am keeping it, but the last two conditions should look like this:



From the previous conditions, we already know that $count is >= 8, so removing that portion of the second-to-last condition will work fine:



<?php elseif ($count <= 16) : ?> 
<div class="item6">
<span>Post 8 to 16 </span><?php the_title(); ?>
</div><!-- .item# -->


From the previous conditions, we already know that all remaining values for $count will be >= 17, so a simple 'else' will work fine:



<?php else : ?> 
<div class="item6">
<span>Post 16 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->





share|improve this answer















You should review PHP Logical Operators. The || operator in the elseif ($count >= 5 || $count <= 7) condition will pull anything >= 5 OR anything <=7, which is any and all numbers. The same applies to the following condition with 8 and 15, so the following solution should fix your problem:





Post 1



<?php elseif ($count == 2) : ?> 
<div class="item2">
<span>Post 2</span><?php the_title(); ?><?php the_content(); ?>
</div><!-- .item# -->

<?php elseif ($count == 3) : ?>
<div class="item3">
<span>Post 3</span><?php the_title(); ?><?php the_author(); ?>
</div><!-- .item# -->

<?php elseif ($count == 4) : ?>
<div class="item4">
<span>Post 4</span><?php the_title(); ?><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count == 5) : ?>
<div class="item5">
<span>Post 5</span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 5 && $count <= 7) : ?>
<div class="item6">
<span>Post 6 to 7</span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 8 && $count <= 15) : ?>
<div class="item6">
<span>Post 8 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->

<?php elseif ($count >= 16) : ?>
<div class="item6">
<span>Post 8 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->


NOTE:
The better solution is to omit the second part of these comparisons, because we already know that it is >= 5 for the first one and >= 8 for the second one. Easiest, cleanest solution looks like this:



...

<?php elseif ($count <= 7) : ?>
<div class="item6">
<span>Post 6 to 7</span><?php the_title(); ?>
</div><!-- .item# -->

<?php elseif ($count <= 15) : ?>
<div class="item6">
<span>Post 8 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->

...





EDIT
The question has changed, and the above code may hold some value, so I am keeping it, but the last two conditions should look like this:



From the previous conditions, we already know that $count is >= 8, so removing that portion of the second-to-last condition will work fine:



<?php elseif ($count <= 16) : ?> 
<div class="item6">
<span>Post 8 to 16 </span><?php the_title(); ?>
</div><!-- .item# -->


From the previous conditions, we already know that all remaining values for $count will be >= 17, so a simple 'else' will work fine:



<?php else : ?> 
<div class="item6">
<span>Post 16 onwards - </span><?php the_title(); ?><?php the_excerpt(); ?>
</div><!-- .item# -->






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 8 at 17:22

























answered Mar 8 at 16:33









mtr.webmtr.web

1,2741917




1,2741917












  • I wanted to say that your thoughtful and well-written post was very helpful, and I appreciate what you do. Take my upvote!

    – dmanexe
    Mar 8 at 16:35











  • thank you @mtr.web for your help. I've corrected the codes but there's still issues. the last three conditions $count >= 8 && $count >= 16 and $count > 17 doesn't work. It doesn't display the post # 16 onwards. What seems to be the problem? I have updated my codes from my question above.

    – user11003760
    Mar 8 at 16:59











  • @DanicaEscola, I edited the answer. If it works for you, don't forget to accept/upvote. Otherwise, let me know what is/isn't happening now, and I will edit the answer to fit.

    – mtr.web
    Mar 8 at 18:30











  • I'm not sure why $count <= 16 is only displaying 3 post which in fact it should display post 8, 9, 10 to 16. what's the issue with $count <=16?

    – user11003760
    Mar 9 at 3:22

















  • I wanted to say that your thoughtful and well-written post was very helpful, and I appreciate what you do. Take my upvote!

    – dmanexe
    Mar 8 at 16:35











  • thank you @mtr.web for your help. I've corrected the codes but there's still issues. the last three conditions $count >= 8 && $count >= 16 and $count > 17 doesn't work. It doesn't display the post # 16 onwards. What seems to be the problem? I have updated my codes from my question above.

    – user11003760
    Mar 8 at 16:59











  • @DanicaEscola, I edited the answer. If it works for you, don't forget to accept/upvote. Otherwise, let me know what is/isn't happening now, and I will edit the answer to fit.

    – mtr.web
    Mar 8 at 18:30











  • I'm not sure why $count <= 16 is only displaying 3 post which in fact it should display post 8, 9, 10 to 16. what's the issue with $count <=16?

    – user11003760
    Mar 9 at 3:22
















I wanted to say that your thoughtful and well-written post was very helpful, and I appreciate what you do. Take my upvote!

– dmanexe
Mar 8 at 16:35





I wanted to say that your thoughtful and well-written post was very helpful, and I appreciate what you do. Take my upvote!

– dmanexe
Mar 8 at 16:35













thank you @mtr.web for your help. I've corrected the codes but there's still issues. the last three conditions $count >= 8 && $count >= 16 and $count > 17 doesn't work. It doesn't display the post # 16 onwards. What seems to be the problem? I have updated my codes from my question above.

– user11003760
Mar 8 at 16:59





thank you @mtr.web for your help. I've corrected the codes but there's still issues. the last three conditions $count >= 8 && $count >= 16 and $count > 17 doesn't work. It doesn't display the post # 16 onwards. What seems to be the problem? I have updated my codes from my question above.

– user11003760
Mar 8 at 16:59













@DanicaEscola, I edited the answer. If it works for you, don't forget to accept/upvote. Otherwise, let me know what is/isn't happening now, and I will edit the answer to fit.

– mtr.web
Mar 8 at 18:30





@DanicaEscola, I edited the answer. If it works for you, don't forget to accept/upvote. Otherwise, let me know what is/isn't happening now, and I will edit the answer to fit.

– mtr.web
Mar 8 at 18:30













I'm not sure why $count <= 16 is only displaying 3 post which in fact it should display post 8, 9, 10 to 16. what's the issue with $count <=16?

– user11003760
Mar 9 at 3:22





I'm not sure why $count <= 16 is only displaying 3 post which in fact it should display post 8, 9, 10 to 16. what's the issue with $count <=16?

– user11003760
Mar 9 at 3:22



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55066909%2fwp-query-code-to-display-unique-div-classes-and-wp-functions%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived