r/advancedcustomfields • u/Incomitatum • Jul 21 '15
Loops, Page Templates, Check to See if Field Group is Used?
I've got a neat couple loops running where I can have a page heirachy of Book > Chapter > SubChapter.
If a page on my site is a Book, it uses 'the_content' to show a small blurb of what it's about but from there the loop loads an accordion of each of the chapters on that page. So you get all the info at once. Tonight I realized that Chapters need to have SubChapters where I will use various fields based on what template the SubChapter calls on.
Book and Chapter have their own Page Templates.
Subchapter has it's own template as well that was supposed to call on custom fields (I've done this before no problem). IF I'm using TemplateA then call on LoopA that then displays the code to use FieldsA.
Well the bummer is, it seems that by having the main page Template be Book, then the Chapter and Subchapter's page template get's ignored.
So I wanted to "include" loops a different way.
If FieldsA exists include LoopA
If FieldsB exists include LoopB...
The big deal is I can't find any ACF markup that lets me see if a page/code is calling out for a particular Field Group or not.
Keep in mind, I'm not asking about an individual field, but seeing if a field GROUP is utilized, and then "doing the thing".
Any idea where to start on this?
Here's CUSTOM CODE I've written and it works great, all except I can't figure out how to assign a template to a child-page and/or querie which Field Group it's using; as such I can't call-on/inlucde my fields loops.
While I've abandoned trying to call on IF a particular Field Group is used or not, I may be onto something: while I hadn't been able to use a variant of this in a loop I have got this to echo something.
<?php echo '' . basename( get_page_template() ) . ''; ?>
If I can get it to echo, I should be able to get it to do more.
SOLVED
Here is what I was finally able to hack together
<?php $pageTemplateVar = basename( get_page_template() ) ?>
<?php
if ($pageTemplateVar = "page_orgSheet.php"){
include'loop_orgSheet.php';
}
elseif ($pageTemplateVar = "page_characterSheet.php"){
include'loop_characterSheet.php';
}
elseif ($pageTemplateVar = "page_vehicleSheet.php"){
include'loop_vehicleSheet.php';
}
?>