Simple single "loop.php" Word Press theme function


/ Published in: PHP
Save to your folder(s)

Instead of requiring the loop.php file in your custom themes you can use there two functions, placed in your functions.php file to not only automatically include it, but make a dead simple to filter sections out on a page by page basis negating the need for special loops for specific page types (like a search loop or a main index loop)

The first section is the code you put into your functions file.

The second is how you would call the new "the_loop()" function, simple but all the individual sections you want filtered out as variables, one after another.

The third sections is how you would go about filtering items out.

More information at the link, questions or comments can be posted here or there and I'll get back to you whenever I can.


Copy this code and paste it in your HTML
  1. // in the functions.php file
  2. function the_loop(){
  3. $GLOBALS['h']=array();
  4. foreach(func_get_args()as$k=>$v){$i++;$GLOBALS['h'][$v]=false;}
  5. require 'loop.php';
  6. }
  7. function display($v){
  8. global $h;
  9. if(array_key_exists($v,$h)){
  10. return $h[$v];
  11. }else{
  12. return true;
  13. }
  14. }
  15.  
  16. // how you call the new loop on your theme page
  17. the_loop('comments','meta');
  18.  
  19. // how you'd go about filtering items out of the loop, in this case comments and meta would be filtered
  20. if(display('title')){
  21. // Your title display code
  22. }
  23. if(display('meta')){
  24. // Your meta display code
  25. }
  26. if(display('content')){
  27. // Your content display code
  28. }
  29. if(display('comments')){
  30. // Your comments display code
  31. }

URL: http://fatfolderdesign.com/308/unimportant/simpler-single-loop-wordpress-theme-creation

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.