• On my website I created a custom metabox that is being displayed in the post type “page”. The metabox will display a checkbox and 4 url fields. The checkbox will control the visibility of a div (section#footerLinks) and the url fields will control the 4 links that will appear with the div links.

    Ability

    The checkbox once clicked (on) will display my div with the four links, once I uncheck the box (off) it will hide the div.

    The Problem

    When I click the checkbox on and fill in the custom fields information it works perfectly. But this gets assign to all of my pages not just the one I have assigned. If I click the checkbox “on” for another page it displays two of the same divs.

    Is there a way I can have each page control the div independently and only display one div?

    Example

    Page 1 should display the div with its own information and hide on all other pages.

    Page 2 should display the div with its own information and hide on all other pages.

    Below is my code I am using the hide the div and control the meta_value of my checkbox selection on

    <?php
      $args = array(
        'post_type'     => 'page',
        'meta_key'      => '_cmb_linkCheckbox',
        'meta_value'    => 'On',
        'showposts'     =>  1,
     );
     $links = new WP_Query( $args );
     ?>
     <?php if ( $links->have_posts() ) : while ( $links->have_posts() ) : $links->the_post(); ?>
     <section id="footerLinks">
      <article id="footerIcons">
    
    <ul>
    <li>
    <ul><!-- CONTACT US -->
    
    <li><a>ID, "_cmb_contactURL", true); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/contactUs.png" /></a></li>
    <li><h4>Contact Us</h4></li>
    </ul>
    </li>
    <li>
    <ul><!-- REQUEST INFO -->
    
    <li><a>ID, "_cmb_requestURL", true); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/requestInfo.png" /></a></li>
    <li><h4>Rquest Info</h4></li>
    </ul>
    </li>
    <li>
    <ul><!-- VISIT -->
    
    <li><a>ID, "_cmb_visitURL", true); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/visit.png" /></a></li>
    <li><h4>Visit</h4></li>
    </ul>
    </li>
    <li>
    <ul><!-- APPLY -->
    
    <li><a>ID, "_cmb_applyURL", true); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/apply.png" /></a></li>
    <li><h4>Apply</h4></li>
    </ul>
    </li>
    </ul>
      </article>
      </section>
     <?php endwhile; endif; ?>
  • The topic ‘Displaying a div from an assigned meta_value’ is closed to new replies.