0

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

6
  • How did you "try to use it"? Post your code please.
    – s_ha_dum
    Commented Apr 26, 2014 at 19:37
  • I edited my question with the code.
    – gil hamer
    Commented Apr 26, 2014 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
    Commented Apr 26, 2014 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
    Commented Apr 26, 2014 at 20:27
  • Please update the code in the question with your most recent version.
    – s_ha_dum
    Commented Apr 26, 2014 at 20:47

1 Answer 1

0

I achieved this recently with the following code in archive.php

add_action('genesis_loop', 'blah_search_results');
function blah_search_results() { 
 while (have_posts()) : the_post();
  if (is_category('in-the-news')) {
   // Get article URL
   $article_url = get_field('original_article_url');
   // rest of theme goes here
  }
 endwhile;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.