Home > Net >  Wordpress - show div id with template part if it matches page id otherwise dont
Wordpress - show div id with template part if it matches page id otherwise dont

Time:11-28

Looking for a simple if/else statement in Wordpress to show a code that includes a template-part IF it's on page id's 30 and 40 but don't show it on any other page.

My Code:

<div id="tg-menu" >
    <h3>Menu</h3>
    <?php get_template_part('template-parts/menus', 'lunch-menu',array('child_id' => $args['child_id'])); ?>
</div> 

Also, this code would need to be targeted to the same ID's to show if they meet the 2 page id's otherwise don't show on any other pages.

<a href="#tg" target="_blank"  style="margin-top: 30px">
        <span >Menu</span>
</a>

Any help would be appreciated.

CodePudding user response:

us the is_page() function and use your Id's as the parameters

<?php if ( is_page(30) || is_page(40) ): ?>
    <div id="tg-menu" >
        <h3>Menu</h3>
        <?php get_template_part('template-parts/menus', 'lunch-menu', array('child_id' => $args['child_id'])); ?>
    </div>

    <a href="#tg" target="_blank"  style="margin-top: 30px">
            <span >Menu</span>
    </a>
<?php endif;?>
  • Related