Enjoy an ad free experience by logging in. Not a member yet?
Register .
11-21-2012, 09:03 PM
PM User |
#1
Regular Coder
Join Date: Dec 2010
Posts: 124
Thanks: 17
Thanked 6 Times in 6 Posts
Wordpress Search Loop Statement
Ok, I have a search function and two seperate ways to display the posts.
If in a certain category then post this way else do this.
Anyway, with the else I want to add a clear if the post count =1. How would I do this ?
The loop
PHP Code:
<?php if ( have_posts ()) : while ( have_posts ()) : the_post (); ?> <?php if ( in_category ( '362' )) { ?> <article id="article-articles" class="drop-shadow curved curved-hz-1"> <header class="inspir-header"> <div class="inspir-title"> <h1><a href="<?php the_permalink () ?> " rel="bookmark" title="Permanent Link to <?php the_title (); ?> "><?php the_title (); ?> </a></h1> </div> <!--inspir-title--> <div class="inspir-date"> <?php the_time ( 'j F, y' ) ?> </div> <!--inspir-date--> <div style="clear: both;"></div> </header> <!--inspir-header--> <footer class="inspir-footer"> <div class="inspir-cat"> by <?php the_author (); ?> </div> <!--inspir-cat--> <div class="inspir-tags"> <p><?php the_excerpt (); ?> </p> </div> <!--inspir-tags--> <a href="<?php echo get_permalink (); ?> ">read more..</a> <div style="clear: both;"></div> </footer> <!--inspir-footer--> </article> <!--article-inspir--> <div style="clear:both;"></div><?php } else { ?> <article class="article-inspir drop-shadow curved curved-hz-1"> <?php the_content (); ?> <header class="inspir-header"> <div class="inspir-title"> <h1><?php the_title (); ?> </h1> </div> <!--inspir-title--> <div class="inspir-date"> <?php the_time ( 'j F, y' ) ?> </div> <!--inspir-date--> <div style="clear: both;"></div> </header> <!--inspir-header--> <footer class="inspir-footer"> <div class="inspir-cat"> <?php the_category ( ', ' ) ?> </div> <!--inspir-cat--> <div class="inspir-tags"> <?php the_tags ( '<span>' , '</span><span>' , '</span>' ); ?> </div> <!--inspir-tags--> </footer> <!--inspir-footer--> <div class="inspir-comments"> </div><!--inspir-comments--> </article> <!--article-inspir--><?php } ?> <?php endwhile; else: ?> <p>Sorry, no posts matched your criteria.</p> <?php endif; ?>
Just above
Code:
<article class="article-inspir drop-shadow curved curved-hz-1">
Could I put something along the lines of
PHP Code:
<?php if ( is_search ()) { global $wp_query ; if class. "article-inspir" ( $wp_query -> post_count == 1 ) { echo '<div style="clear:both;"></div>' } } } ?>
I know the above isn't correct but that's why I'm asking for help.
11-21-2012, 11:40 PM
PM User |
#2
Master Coder
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,042
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
Just a guess ...
PHP Code:
<?php if ( have_posts ()) : while ( have_posts ()) : the_post (); ?>
<?php
if ( in_category ( '362' )) { ?>
<article id="article-articles" class="drop-shadow curved curved-hz-1">
<header class="inspir-header">
<div class="inspir-title">
<h1><a href="<?php the_permalink () ?> " rel="bookmark" title="Permanent Link to <?php the_title (); ?> "><?php the_title (); ?> </a></h1>
</div> <!--inspir-title-->
<div class="inspir-date">
<?php the_time ( 'j F, y' ) ?>
</div> <!--inspir-date-->
<div style="clear: both;"></div>
</header> <!--inspir-header-->
<footer class="inspir-footer">
<div class="inspir-cat">
by <?php the_author (); ?>
</div> <!--inspir-cat-->
<div class="inspir-tags">
<p><?php the_excerpt (); ?> </p>
</div> <!--inspir-tags-->
<a href="<?php echo get_permalink (); ?> ">read more..</a>
<div style="clear: both;"></div>
</footer> <!--inspir-footer-->
</article> <!--article-inspir-->
<div style="clear:both;"></div>
<?php
}
else {
if( $wp_query -> post_count == 1 ){
echo '<div style="clear:both;"></div>' ;
}
?>
<article class="article-inspir drop-shadow curved curved-hz-1">
<?php the_content (); ?>
<header class="inspir-header">
<div class="inspir-title">
<h1><?php the_title (); ?> </h1>
</div> <!--inspir-title-->
<div class="inspir-date">
<?php the_time ( 'j F, y' ) ?>
</div> <!--inspir-date-->
<div style="clear: both;"></div>
</header> <!--inspir-header-->
<footer class="inspir-footer">
<div class="inspir-cat">
<?php the_category ( ', ' ) ?>
</div> <!--inspir-cat-->
<div class="inspir-tags">
<?php the_tags ( '<span>' , '</span><span>' , '</span>' ); ?>
</div> <!--inspir-tags-->
</footer> <!--inspir-footer-->
<div class="inspir-comments">
</div><!--inspir-comments-->
</article> <!--article-inspir-->
<?php }
?>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
11-25-2012, 10:43 PM
PM User |
#3
Regular Coder
Join Date: Dec 2010
Posts: 124
Thanks: 17
Thanked 6 Times in 6 Posts
Isn't that saying is the search = 1 then do the clear.
But I want if article-inspir = odd number then add clear to last div.
Edit: I've just re-read my OP and I clearly ask for what you've put. However I need what I've said in this post.
11-26-2012, 12:10 AM
PM User |
#4
Master Coder
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,042
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
You can check whether the count is odd or even.
I'm just not sure if I'm inserting in the correct place ...
Is this closer?
PHP Code:
<?php if ( have_posts ()) : while ( have_posts ()) : the_post (); ?>
<?php
if ( in_category ( '362' )) { ?>
<article id="article-articles" class="drop-shadow curved curved-hz-1">
<header class="inspir-header">
<div class="inspir-title">
<h1><a href="<?php the_permalink () ?> " rel="bookmark" title="Permanent Link to <?php the_title (); ?> "><?php the_title (); ?> </a></h1>
</div> <!--inspir-title-->
<div class="inspir-date">
<?php the_time ( 'j F, y' ) ?>
</div> <!--inspir-date-->
<div style="clear: both;"></div>
</header> <!--inspir-header-->
<footer class="inspir-footer">
<div class="inspir-cat">
by <?php the_author (); ?>
</div> <!--inspir-cat-->
<div class="inspir-tags">
<p><?php the_excerpt (); ?> </p>
</div> <!--inspir-tags-->
<a href="<?php echo get_permalink (); ?> ">read more..</a>
<div style="clear: both;"></div>
</footer> <!--inspir-footer-->
</article> <!--article-inspir-->
<div style="clear:both;"></div>
<?php
}
else {
// check if the post_count is even or odd.
// it will do the clear both if the count is odd ...
if( $wp_query -> post_count & 1 ){
echo '<div style="clear:both;"></div>' ;
}
?>
<article class="article-inspir drop-shadow curved curved-hz-1">
<?php the_content (); ?>
<header class="inspir-header">
<div class="inspir-title">
<h1><?php the_title (); ?> </h1>
</div> <!--inspir-title-->
<div class="inspir-date">
<?php the_time ( 'j F, y' ) ?>
</div> <!--inspir-date-->
<div style="clear: both;"></div>
</header> <!--inspir-header-->
<footer class="inspir-footer">
<div class="inspir-cat">
<?php the_category ( ', ' ) ?>
</div> <!--inspir-cat-->
<div class="inspir-tags">
<?php the_tags ( '<span>' , '</span><span>' , '</span>' ); ?>
</div> <!--inspir-tags-->
</footer> <!--inspir-footer-->
<div class="inspir-comments">
</div><!--inspir-comments-->
</article> <!--article-inspir-->
<?php }
?>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
.
11-26-2012, 08:07 PM
PM User |
#5
Regular Coder
Join Date: Dec 2010
Posts: 124
Thanks: 17
Thanked 6 Times in 6 Posts
No that's not working. I only want to count the loop for the first instance. Not the whole loop count.
11-26-2012, 08:15 PM
PM User |
#6
Master Coder
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,042
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
doh!
I apologize that I cannot seem to understand.
Do you have a working example, or a screenshot of the output and then point to what you mean?
I think I'm getting lost in the fact that it's a loop, but perhaps at times there is only one thing in the loop, not several?
11-26-2012, 08:16 PM
PM User |
#7
Regular Coder
Join Date: Dec 2010
Posts: 124
Thanks: 17
Thanked 6 Times in 6 Posts
http://admiretheweb.com/?s=aaa
As you can see its trying to display article-inspir with out a clear.
Another search with more than one article-inspir works
11-26-2012, 08:40 PM
PM User |
#8
Regular Coder
Join Date: Dec 2010
Posts: 124
Thanks: 17
Thanked 6 Times in 6 Posts
I've just thought, I don't want it on the odd divs. I want it on the last div, even if it's 1234567.
So this should essentially work, but it doesn't.
Code:
<script type="text/javascript">
$(document).ready(function() {
$(".article-inspir:last-child").after("<div style='clear:both;'></div>");
});
</script>
11-26-2012, 11:51 PM
PM User |
#9
Master Coder
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,042
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
Let's do this ...
Put everything back to original, so that a search is a search.
I want to see how every combination looks.
An even number of finds.
An odd number of finds.
A single find.
No finds.
Then, after all results come out as designed, give me a search example
of what should be different. By that I mean, give me search word that
comes from the category that should render differently in the result.
And describe how it would look different than the other search results.
What I'm seeing now ...
I think there is a situation now that is messing things up.
When I search for "AAA", I'm getting two results. I'm guessing one of
them is from the "special category" and the other is not. My guess is
that "AAA" should really only render one result. Why is the other
result showing up? That's why I want you to put the whole script
back to its original state.
When I search for "inspirations", I get one result (full width).
When I search for "test", I get many results (looks good).
When I search for something with odd number of results (looks good).
.
Last edited by mlseim; 11-26-2012 at 11:54 PM ..
11-27-2012, 08:51 PM
PM User |
#10
Regular Coder
Join Date: Dec 2010
Posts: 124
Thanks: 17
Thanked 6 Times in 6 Posts
Wow, I appreciate the time your giving for this, immensely.
Anyway, you've got it right with the combinations, i'll try and explain.
We'll separate them with wide (wide article/100%) inspir (short inspiration/50%).
Wide always has clear float after, so that's not a problem.
Inspir doesn't have a clear after, as they just stack up. However when introducing wide on the same page, it needs a clear after. I have done this by adding a clear after 2n (every two inspir's).
However, when 1 inspir is displayed, it's fine. But when one inspir and a wide displays, it needs a clear float after. Again it can only have a clear float after 1 inspir if there is only 1 inspir, or if it is the last one otherwise inspir will stack and not go in 2's.
Combinations:
1 or 1+ wide and 1 inspir.(problem as 1 inspir isn't cleared)
1 or 1+ wide and 2+ inspirs. FINE (add clear float on 2n inspir, wide always cleared)
1 inspir. FINE (obvious)
1 wide. FINE (obvious)
1+ wide. FINE (always clear after wide)
1+ inspir. FINE (no clear, but stack as all the same width)
Oh, and the reason "aaa"" is coming up for wide, is because "aaa" is featured in that wide article. So the perfect one to test on.
What I've just written is mega confusing, but I hope you understand. The simple way to fix this is to have wide as the same width as inspir, but that's boring, as you say, when it works, it looks great.
12-11-2012, 11:59 PM
PM User |
#11
Regular Coder
Join Date: Dec 2010
Posts: 124
Thanks: 17
Thanked 6 Times in 6 Posts
Anybody ?
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 01:15 PM .
Advertisement
Log in to turn off these ads.