Adam
asked on
Wordpress: Hide title if there is less then one post...??
This seems like a dumb question but I can't seem to figure it out.
I have created a query post that will list the last 5 posts based on some custom fields data. However, its a new site so it might be a little bit before any posts show up in the list. Above the query post, I have added a title (i.e. "Latest Posts") but want the title to not appear if there are no posts in the list. Obviously, if I put it within the while loop that generates the list, it will get repeated each time.
So how do I remove my title from outside the loop if there is less then one post in the list? Again, it seems like a real simple concept but I think my brain is a little fried at the moment and I can't quite figure it out.
I have created a query post that will list the last 5 posts based on some custom fields data. However, its a new site so it might be a little bit before any posts show up in the list. Above the query post, I have added a title (i.e. "Latest Posts") but want the title to not appear if there are no posts in the list. Obviously, if I put it within the while loop that generates the list, it will get repeated each time.
So how do I remove my title from outside the loop if there is less then one post in the list? Again, it seems like a real simple concept but I think my brain is a little fried at the moment and I can't quite figure it out.
Make sure that you set the @count variable directly after the select statement that returns your rows. The @@ROWCOUNT counts the number of rows in the previous SQL statement and if it isn't a select statement, it will not work as expected.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
And I have no idea why the snippet doubled up, but enjoy it.
ASKER
Worked like a charm. Thanks!
declare @count int
set @count = 0
While <condition exists>
begin
<your code here>
set @count = @count + @@ROWCOUNT
end
If @count < 1
begin
<hide title>
else
<display title>
I am not as familiar with MySQL, but here is a reference for the functions.
http://dev.mysql.com/doc/refman/5.0/en/information-functions.html