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
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
add a comment |
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
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
add a comment |
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
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
php wordpress
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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# -->
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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# -->
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
add a comment |
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# -->
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
add a comment |
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# -->
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# -->
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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