WP Query Code to display unique div classes and WP Functions Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag?add 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

Can a non-EU citizen traveling with me come with me through the EU passport line?

Is the address of a local variable a constexpr?

Is there a Spanish version of "dot your i's and cross your t's" that includes the letter 'ñ'?

What do you call a plan that's an alternative plan in case your initial plan fails?

Storing hydrofluoric acid before the invention of plastics

Why does Python start at index -1 when indexing a list from the end?

What are the pros and cons of Aerospike nosecones?

Single word antonym of "flightless"

I am not a queen, who am I?

Why don't the Weasley twins use magic outside of school if the Trace can only find the location of spells cast?

Do I really need recursive chmod to restrict access to a folder?

Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?

When to stop saving and start investing?

Why was the term "discrete" used in discrete logarithm?

How to find all the available tools in macOS terminal?

Should I call the interviewer directly, if HR aren't responding?

Is a manifold-with-boundary with given interior and non-empty boundary essentially unique?

What LEGO pieces have "real-world" functionality?

How to deal with a team lead who never gives me credit?

Right-skewed distribution with mean equals to mode?

ListPlot join points by nearest neighbor rather than order

Antler Helmet: Can it work?

What does the "x" in "x86" represent?

G-Code for resetting to 100% speed



WP Query Code to display unique div classes and WP Functions



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?add 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



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








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,2891917




1,2891917












  • 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

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved