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 want to show the projects that has had it's checkbox ticked as Branding, if it's on the Branding page (i.e the page title is Branding).

To explain the code a bit:

This line show's all the checkboxes that have been ticked for each project so it will output "Branding", "Web", "Print" if they have been ticked.

implode(', ',get_field('categories')

This next line is just checking the page title is "Branding":

implode(', ',get_field('categories')

I'm trying to put these both in an if statement where it would just output the checked boxes and if they match the title then output them.

<?php if(implode(', ',get_field('categories')) && $grid_title == "Branding"); {
echo "testing"; 
}
?>

The code above shows what I want to do but it doesn't quite work.

IMPORTANT: I'm using this plugin to create the custom checkboxes so please bear that in mind.

share|improve this question
    
@Rob: This looks like it can be handled with a hierarchial custom taxonomy. You get almost everything "for free" that way. Is there a reason you are not using that? (Use @Jan when you reply in a comment and I get a notification) –  Jan Fabry May 18 '11 at 12:43
    
@Jan I'm not really sure what that is to be honest!! I just used the custom field plugin to create all my custom data for each project. I'm completely open to anything that'll do the job. –  Rob May 18 '11 at 12:45
    
@Rob: Can you come to the chat room so we can explain it there? It's really simple, but I can't just explain it in comments. –  Jan Fabry May 18 '11 at 12:48
    
Why do you want to match the title? Do you have dynamic titles or do you just want to output meta box conditionals based on custom pages/tags/categories. Your question seems odd. –  Wyck May 18 '11 at 16:20
    
I have no idea, I just want to show the projects that branding has been ticked in it's checkbox to show on the branding page. No one seems to be reading the part where it says I'm using a plugin to create the custom fields i.e the checkboxes. –  Rob May 18 '11 at 17:35

1 Answer 1

up vote 0 down vote accepted

I managed to figure it out myself reading around, solved it with this:

   <div id="grid">
<?php $args = array(
    'depth'        => 0,
    'child_of'     => 411 );
$pages = get_pages(array('child_of'));
$grid_title = $post->post_title;

foreach($pages as $post)
{
setup_postdata($post);
$fields = get_fields();?>

<?php if($fields->company_name != "") : ?>
<!-- Any new tags will need to be added below -->
<?php if((in_array("Branding", get_field('categories')) && $grid_title == "Branding") || (in_array("Creative", get_field('categories')) && $grid_title == "Creative") || (in_array("Development", get_field('categories')) && $grid_title == "Development") || (in_array("Exhibition", get_field('categories')) && $grid_title == "Exhibition") || (in_array("Packaging", get_field('categories')) && $grid_title == "Packaging") || (in_array("Print", get_field('categories')) && $grid_title == "Print") || (in_array("SEO", get_field('categories')) && $grid_title == "SEO") || (in_array("Usability", get_field('categories')) && $grid_title == "Usability") || (in_array("Web", get_field('categories')) && $grid_title == "Web") || (in_array("Campaign", get_field('categories')) && $grid_title == "Campaign") || (in_array("Copywriting", get_field('categories')) && $grid_title == "Copywriting") || (in_array("Feasibility", get_field('categories')) && $grid_title == "Feasibility") || (in_array("Research", get_field('categories')) && $grid_title == "Research") || (in_array("Social Media", get_field('categories')) && $grid_title == "Social Media")){
     echo "
        <div class=\"grid-box\" onclick=\"location.href='" . get_page_link($post->ID) ."';\" style=\"cursor: pointer;\">
        <div class=\"phase-1\">
           <img class=\"grid-image\" src=\"" . $fields->thumb_image . "\" alt=\"" . $fields->company_name ."\" height=\"152\" width=\"210\" />
           <div class=\"grid-heading\">
                <h2>". $fields->company_name ."</h2>
                <h3>" . implode(', ',get_field('categories')) ."</h3>
            </div> 
        </div>
        <div class=\"phase-2\">
            <div class=\"grid-info\">
                <h4>". $fields->project_name ."</h4>
                <p>". $fields->description ."</p>
            </div>
            <div class=\"grid-heading-hover\">
                <h2>". $fields->company_name ."</h2>
                <h3>". implode(', ',get_field('categories')) ."</h3>
            </div> 
        </div>
    </div>
     ";
}
else {
    echo "  <div class=\"grid-box\" onclick=\"location.href='" . get_page_link($post->ID) ."';\" style=\"cursor: pointer;\">
        <div class=\"phase-1\">
           <img class=\"grid-image\" src=\"" . $fields->thumb_image . "\" alt=\"" . $fields->company_name ."\" height=\"152\" width=\"210\" />
           <div class=\"grid-heading\">
                <h2>". $fields->company_name ."</h2>
                <h3>" . implode(', ',get_field('categories')) ."</h3>
            </div> 
        </div>
        <div class=\"phase-2\">
            <div class=\"grid-info\">
                <h4>". $fields->project_name ."</h4>
                <p>". $fields->description ."</p>
            </div>
            <div class=\"grid-heading-hover\">
                <h2>". $fields->company_name ."</h2>
                <h3>". implode(', ',get_field('categories')) ."</h3>
            </div> 
        </div>
    </div>";
}

else : ?>
<?php endif; ?>    

<?php
}

wp_reset_query();
?>        
</div>
share|improve this answer

Your Answer

 
discard

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

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