0
 <?php get_header(); ?>

 <div id="containerHOME">
<div id="left-div">
<!--Begin Sidebar-->
<div id="left-inside">
  <?php if (get_option('earthlytouch_featured') == 'on') get_template_part('includes/featured'); ?>
  <div class="clear">&nbsp;</div>

  <div class="home-squares">
    <div class="home-headings">
      <?php esc_html_e('Whats New?','EarthlyTouch'); ?>
    </div>
    <?php $args = array(
      'category_name' => 'whats', 
      'orderby' => 'DESC',
      'ignore_sticky_posts' => true,
      'posts_per_page' => 3 
    );
    $qry = new WP_Query($args);
    if ($qry->have_posts()) {
      while ($qry->have_posts() ) { 
        get_template_part('content','blocks');
      }
      }?>
    <!-- end .home-squares -->
    <div class="home-squares">
      <div class="home-headings">
        <?php esc_html_e('Recipes','EarthlyTouch'); ?>
      </div>
      <?php $args = array(
      'category_name' => 'recipes', 
      'orderby' => 'DESC',
      'ignore_sticky_posts' => true, 
      'posts_per_page' => 3 
    );
    $query = new WP_Query($args);
    if ($query->have_posts()) {
      while ($query->have_posts() ) { 
        get_template_part('content','blocks');
      }
    } ?>
      <!-- end .home-squares -->
      <?php }; ?>  // if I take this out I get an error down at the bottom of the page
      <!-- movie -->
      <div class="movie"> <a href="http://www.youtube.com/embed/tojlpK9zFPs"> <img src="images/video-front.jpg" width="530" height="299" alt="video" class="popmake-2673" /></a> </div>
    </div>
    <!-- end movie --> 
    <!-- end #left-inside --> 

    <!--Begin Sidebar-->
    <?php get_sidebar(); ?>
    <!--End Sidebar-->
    <div id="sup-hold">
      <div id="supplementary" style="background-color:#FFFFFF;">
        <?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Header Widget Area')) :
endif; ?>
      </div>
      <div id="mc-mobilecause-widget"> <a href="//www.mobilecause.com/feature/subscription-widget" id="powered-by-mobilecause">Mobile messaging powered by Mobilecause</a><script>!function(d,s){var s=d.createElement("script"),h=(document.head||d.getElementsByTagName('head')[0]);s.src="https://app.mobilecause.com/public/messaging_widgets/opvd3d/source";h.appendChild(s);}(document);</script> 
      </div>
      <div id="footer"> Copyright &copy;
        <?php
echo date("Y");
?>
        JustOneTree.org All Rights Reserved | <a href="/contact">Contact Us</a> | <a href="/terms">Policies and Terms of Use</a> | <a target="_blank" href="http://www.boplinger.com">webmaster: boplinger.com</a></div>
      <!-- end #footer --> 
  </div>
    <!-- end #footer -->
    <?php get_template_part('includes/scripts'); ?>
    <?php wp_footer(); ?>
  </div> // error here
  <!-- end #sup-hold --> 
</div>
<!-- end #container -->
  • Please post the original code and copied code here so we can see what you're working with. – mrwweb Jun 11 '15 at 2:00
  • Never use $wp_query as your query variable, you are breaking the main query object. Also, you need to reset postdata after every custom instance of WP_Query. You also have syntax errors according to the syntax highlighter. Fix these faults and you should be good to go – Pieter Goosen Jun 12 '15 at 4:38
  • Please correct your markup, and what is your question. Everything is a big unreadable mess – Pieter Goosen Jun 15 '15 at 5:44
  • @PieterGoosen the moderator cleaned it up the code for me, I don't know why mine pastes in as a mess. Even this interface is a mystery. I am not a php programmer. My question is. What code to I put into the content-blocks file based on his previous instructions. I'll try to paste in the original file that we were working from. – barb Jun 15 '15 at 23:49
  • 1
    I will fix this for you tonight @barb, but you really need to understand PHP well enough to patch in suggestions and corrections rather than require the rewriting of an entire template. – s_ha_dum Jun 16 '15 at 20:02
2

The relevant code is here:

query_posts("cat=25&orderby=DESCd&showposts=3&$randomArticlesNum&caller_get_posts=1");

That is the query that is pulling the posts, and that is what you want to alter.

Your previous theme builder also did something that should never be done-- used query_posts(). Also, both showposts and caller_get_posts have been replaced. That is very old code or your previous programer did not keep up with changes to the core. Let's clean this up:

$args = array(
  'cat' => 25, 
  'orderby' => 'DESC',
  'ignore_sticky_posts' => true, // used to be caller_get_posts
  'posts_per_page' => 3 // used to be showposts
);
$qry = new WP_Query($args);
if ($qry->have_posts()) {
  while ($qry->have_posts() ) { 
    $width = 40;
    $height = 40;
    $classtext = 'no-border';
    $titletext = get_the_title();
    $thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext);
    $thumb = $thumbnail["thumb"]; ?>
    <div class="random"><?php 
      $width = 40;
      if($thumb != '') { ?>
        <div class="random-image"> "><?php 
          print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
        </div><?php 
      } 
      // something is broken here. the start of the following tag is missing
      ?>" rel="bookmark" title="<?php printf(esc_attr__('Permanent Link to %s','EarthlyTouch'), the_title()) ?>"><?php 
        truncate_title(40);
        truncate_post(50); ?>
    </div>
    <!-- end .random --><?php
  }
}

I swapped query_posts() for a new WP_Query object, and I reordered for readability, eliminating as much PHP tag SPAM as I could at a quick once-over.

I don't know what $randomArticlesNum was supposed to do but looking at the argument list to query_posts() I don't see how it could have actually done anything.

You want to do the same thing again for your next Loop but change the cat argument. As is, both Loops have cat=25 so there is no way that could have worked either.

You also have a broken tag in there. See the comments to the code.

One other trick: The code looks to be identical for both Loops but you are maintaining the same code in two places. That is a headache and is prone to error. Move most of the Loop code to another file and load it via get_template_part():

$args = array(
  'cat' => 25, 
  'orderby' => 'DESC',
  'ignore_sticky_posts' => true, // used to be caller_get_posts
  'posts_per_page' => 3 // used to be showposts
);
$qry = new WP_Query($args);
if ($qry->have_posts()) {
  while ($qry->have_posts() ) { 
    get_template_part('content','blocks');
  }
}

That will load a file called content-blocks.php from the theme root-- the same directory as the themes' stylesheet and functions.php.


I took a look at the edits you made and you didn't quite get it all right. Here is some code with notes:

// $randomArticlesNum does nothing, as noted previously. I am not even sure what it was supposed to do.    
// You can remove it
$randomArticlesNum = (int) get_option('earthlytouch_randomposts_num'); 
$args = array(
  // use one or the other, but not both, of the following and delete the one you don't use
  // Your original code use `cat` and the ID
  'cat' => 123, // 'cat' needs to be an ID-- a number-- not a word, 
  'category_name' => 'whats', // for a word, use 'category_name' and quote the value
  'orderby' => 'DESC',
  'ignore_sticky_posts' => true, // used to be caller_get_posts
  'posts_per_page' => 3 // used to be showposts
);
$query = new WP_Query($args);
if ($query->have_posts()) {
  while ($query->have_posts() ) { 
    get_template_part('content','blocks');
  }
} // you were missing the PHP closing tag --> ?> 

The same errors are in both Loops. Also, after the second one, you have a spurious closing bracket:

<!-- end .home-squares -->

      <?php }; ?>

Remove it:

<!-- end .home-squares -->

Also, get yourself a decent code editor-- something like Textwrangler (on a Mac and I'm guessing you are :)) or Notepad++.


I edited and reformatted your template:

<?php
get_header(); ?>

<div id="containerHOME">
  <div id="left-div">
  <!--Begin Sidebar-->
    <div id="left-inside"><?php 
      if (get_option('earthlytouch_featured') == 'on') {
        get_template_part('includes/featured'); 
      } ?>
      <div class="clear">&nbsp;</div>
      <div class="home-squares">
        <div class="home-headings"><?php 
          esc_html_e('Whats New?','EarthlyTouch'); ?>
        </div><?php 
        $args = array(
          'category_name' => 'whats', 
          'orderby' => 'DESC',
          'ignore_sticky_posts' => true,
          'posts_per_page' => 3 
        );
        $qry = new WP_Query($args);
        if ($qry->have_posts()) {
          while ($qry->have_posts() ) { 
            get_template_part('content','blocks');
          }
        } ?>
        <!-- end .home-squares -->
        <div class="home-squares">
          <div class="home-headings">
            <?php esc_html_e('Recipes','EarthlyTouch'); ?>
          </div>
          <?php 
          $args = array(
            'category_name' => 'recipes', 
            'orderby' => 'DESC',
            'ignore_sticky_posts' => true, 
            'posts_per_page' => 3 
          );
          $query = new WP_Query($args);
          if ($query->have_posts()) {
            while ($query->have_posts() ) { 
              get_template_part('content','blocks');
            }
          } ?>
          <!-- end .home-squares -->
          <!-- movie -->
          <div class="movie"> <a href="http://www.youtube.com/embed/tojlpK9zFPs"> <img src="images/video-front.jpg" width="530" height="299" alt="video" class="popmake-2673" /></a> </div>
        </div>
        <!-- end movie --> 
        <!-- end #left-inside --> 

        <!--Begin Sidebar--><?php 
        get_sidebar(); ?>
        <!--End Sidebar-->
        <div id="sup-hold">
          <div id="supplementary" style="background-color:#FFFFFF;"><?php 
            if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Header Widget Area')) : endif; ?>
          </div>
          <div id="mc-mobilecause-widget"> <a href="//www.mobilecause.com/feature/subscription-widget" id="powered-by-mobilecause">Mobile messaging powered by Mobilecause</a><script>!function(d,s){var s=d.createElement("script"),h=(document.head||d.getElementsByTagName('head')[0]);s.src="https://app.mobilecause.com/public/messaging_widgets/opvd3d/source";h.appendChild(s);}(document);</script> 
          </div>
          <div id="footer"> Copyright &copy; <?php echo date("Y"); ?> JustOneTree.org All Rights Reserved | <a href="/contact">Contact Us</a> | <a href="/terms">Policies and Terms of Use</a> | <a target="_blank" href="http://www.boplinger.com">webmaster: boplinger.com</a></div>
          <!-- end #footer --> 
      </div>
    <!-- end #footer --> <?php 
      get_template_part('includes/scripts'); 
      wp_footer(); ?>
  </div> 
  <!-- end #sup-hold --> 
</div>
<!-- end #container -->

I do not get errors but it is difficult to test something like this without setting up a complete parallel environment. I notice that your template doesn't use get_footer(). Why not?

  • Yes, if you trouble come back I'll see what I do. – s_ha_dum Jun 11 '15 at 18:43
  • I gave you an almost drop- in replacement. Just tack the new code in under the old code in the question above. – s_ha_dum Jun 11 '15 at 20:08
  • I did drop in your code as best I could understand, and placed all the altered code above. Including creating a content-block.php. but as you can see above it's lost its formatting. – barb Jun 12 '15 at 3:17
  • I'll fix that formatting later tonight if no one beats me to it :) – s_ha_dum Jun 12 '15 at 3:18
  • Why are you using $wp_query as your query variable, you are breaking the main query object. Also, you are nowhere trying to reset your postdata after your custom query. Most probably why everything fails at the end – Pieter Goosen Jun 12 '15 at 4:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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