SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: if term exists

  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    if term exists

    I am calling a template part if a term is not null, if it is, it does not call the template part. It does function for everything after the loop, but the <h3>Shows up no matter if the term is null or not. How could I do this without including the <h3> in the loop.

    The Call for template
    PHP Code:
    $term term_exists('the cat''category');
            if (
    $term !== null) {
            
    get_template_part('/_/inc/template'); 
    The Template

    Code:
    <h3>Head Line</h3>
        <ul id="clearfix">
            <?php
            $theloops = new WP_Query(array(
            'category__in' => array(1),
    		'showposts' => '12',
    		'post_type' => array(
    		'post',
    		'custom1',
    		'custom2',
    		'custom2'
    		)
    		));
            ?>
            <?php while ($theloops->have_posts()) : $theloops->the_post(); ?>
            <li>
               <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php echo get_the_post_thumbnail($id, 'thumbnail'); ?></a>
            </li>
            <?php endwhile; wp_reset_postdata(); ?>
        </ul>

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,071
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    It has been a while since I've done WordPress customizations, but I would think the following would work

    PHP Code:
            <?php
            $theloops 
    = new WP_Query(array(
            
    'category__in' => array(1),
            
    'showposts' => '12',
            
    'post_type' => array(
            
    'post',
            
    'custom1',
            
    'custom2',
            
    'custom2'
            
    )
            ));
            
    ?>
        <?php if ($thisloops->have_posts()) : ?>
        <h3>Head Line</h3>
        <ul id="clearfix">
            <?php while ($theloops->have_posts()) : $theloops->the_post(); ?>
            <li>
               <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php echo get_the_post_thumbnail($id'thumbnail'); ?></a>
            </li>
            <?php endwhile; wp_reset_postdata(); ?>
        </ul>
        <?php endif; ?>
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ha.. the if... Your are the hero of the day .. Thanks so much.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •