Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am a big fan of Advanced Custom Field by Elliot Condon http://www.advancedcustomfields.com/

This is what I am trying to chive without success so far:

I have a website with posts and archive.php displays my archive posts page. Now, I would like to display different template for certain categories. I don't have the name of the category which I want to display this template for, I would like to do it dynamically so whenever my user creates a post he can choose a special custom field from within that post (true, false preferably) e.g - this post belongs to "projects" category and if the checkbox is checked - archive.php will call different layout using include file.

if this option is unchecked. archive.php show the regular template

I was thinking about simply creating a custom field called "is_project_category" and assign it to a post page but when I tried to use it in archive.php it didn't work at all

I used this code:

<?php
 $is_projects_category = get_field('is_projects_category');
 if('is_projects_category' == true){?>

// include the special category template for projects

<?php } else{ ?>

// display normal archive template

<?php } ?>

it didn't work..

any idea how to use it outside the loop of single.php and show it in archive.php (or anywhere in the theme)?

Thanks

share|improve this question
    
How did you "try to use it"? Post your code please. –  s_ha_dum Apr 26 at 19:37
    
I edited my question with the code. –  gil hamer Apr 26 at 19:56
    
This looks like a PHP syntax error. You need to check against the variable you created and not against a static string-- if($is_projects_category == true){ –  s_ha_dum Apr 26 at 19:59
    
You were right about the PHP error. however, I fixed it and it's still not working. the Custom Field is assigned to a category. maybe Custom Field is not working on archive.php? is it possible? –  gil hamer Apr 26 at 20:27
    
Please update the code in the question with your most recent version. –  s_ha_dum Apr 26 at 20:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.