rooofl Posted August 8, 2015 Posted August 8, 2015 (edited) I try to display all the pages `news` with a checkbox `show_in_slide` unchecked. Here is my code: $news_list = $pages->find("template=news, sort=name, show_in_slide=0"); if ($news_list) { echo "There is at least one news not shown in slide"; }else{ echo "No news"; } This works if I have such a news, but “There is at least one news not shown in slide” appears also if it is not the case. What I am doing wrong? Edited August 8, 2015 by rooofl
Raymond Geerts Posted August 8, 2015 Posted August 8, 2015 try show_in_slide!=1 If i recall correctly the checkbox has no default value of 0 so it could be empty
Raymond Geerts Posted August 8, 2015 Posted August 8, 2015 Well, show_in_slide= will miss the ones that have value 0 while show_in_slide=0 will miss the ones that have no value but show_in_slide!=1 will fetch all that are empty and those with value 0 (or anything that has not value 1 for that matter) @rooofl i like your avatar, you realy wrapped your head around it 1
rooofl Posted August 8, 2015 Author Posted August 8, 2015 Thank you for your quick replied, but none of the solutions seams to work. Let me correct my first post: In the case the condition should display “no news”, it displays “There is at least one news not shown in slide”, and not nothing as I wrote before. Sorry for this confusion.
rooofl Posted August 23, 2015 Author Posted August 23, 2015 I still have trouble to find how to solve this issue, can anyone help me?
LostKobrakai Posted August 23, 2015 Posted August 23, 2015 Your problem isn't the selector, but the if condition. $news_list is an object of the class PageArray. Objects always equal true in php. You need to check if there are entries in that object. $news_list = $pages->find("template=news, sort=name, show_in_slide!=1"); if ($news_list->count()) { echo "There is at least one news not shown in slide"; }else{ echo "All news items are shown in the slide"; }
rooofl Posted August 23, 2015 Author Posted August 23, 2015 Thank you LostKobrakai, it works perfectly by testing count(), my final code is: $news_list = $pages->find("template=news, sort=name, show_in_slide!=1"); if ($news_list->count()) { echo "There is at least one news not shown in slide"; }else{ echo "All news items are shown in the slide"; }
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now