1

I've been trying to get this to work all day. I want add some custom HTML depending on what category the post is in Wordpress from a separate directory to keep things clean. I can't seem to load the html file.

The relevant code is:

        <div class="container">
    <?php while ( have_posts() ) : the_post(); ?>
        <div class="row clearfix">  
            <?php if (function_exists('breadcrumbs')) breadcrumbs(); ?>
            <div class="title clearfix">
                <a href="javascript:window.history.back();" class="back-list"></a>
            <?php global $post; $category = get_the_category($post->ID); setPostViews($post->ID);  ?>
                <h1><?php echo $category[0]->name;?></h1>
            </div>
            <div class="detailBlock clearfix">
                <h1><?php the_title()?></h1>
                <div class="detail-inner">
                <?php $featured_img = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full', true);
                    if($featured_img) {
                        echo "<div class='detail-img'><img src='$featured_img[0]' alt='".get_the_title()."'></div>";
                        echo $category[0]->ID ;
                    }
                    the_content(); 

                ?>
                <?php 
                /* TEST CODE */
                 global $post; $category = get_the_category($post->ID);
                 if($category[0] == '6'){
                 include( get_template_directory_uri() '/call-to-actions/cta-weight-loss-fem.html');
                 }
                            ?>

                </div>


        </div>
        <?php endwhile;?>
    </div>

1 Answers1

0

Change:

if($category[0] == '6'){

to

if($category[0]->ID == '6'){

and that should work.

Note: you don't need the line above to get the category as you already have it from before. A better idea would be to store the value as a variable.

Simon Pollard
  • 2,476
  • 1
  • 17
  • 26
  • Awesome thanks for the quick reply! Another issue is the include statement. I couldn't get this to work properly. I dont want to have all my HTML files in the same folder as this would create a mess. I want to be able to include them from their own folder. However the method Im trying using Wordpress' get_template_directory_uri() is not working properly inside the include statement. I've tried many ways and most of the examples are inside script tags. Not in this specific way I need it to work. Thanks in Advance for everyone's help, you're all superstars! – Glen Coffey Jul 10 '15 at 01:47
  • There are a few include paths you can use - also look at get_stylesheet_directory() you will need this if using a child theme for example. If in doubt varm_dump or echo out the value you get from the function and check the rest of your path is correct. And if all that fails just put in a relative paths '/wp-content/themes/....' etc. – Simon Pollard Jul 10 '15 at 08:12
  • Thanks Simon much appreciated – Glen Coffey Jul 11 '15 at 06:51
  • No worries Glen - if you could you mark my answer as being correct that would be great thanks - and if you need any further help with this let me know. – Simon Pollard Jul 13 '15 at 09:47