treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Wordpress Blog View on Homepage, exclude passworded posts

  • working with a theme that shows homepage blog post on the homepage towards the bottom just above the signup for newsletter section. http://inkthemes.com/wptheme/blackbird-interior/

    The homepage section shows everything from the blog, I need to be sure passworded posts do not show at all. The theme options panel only has off or on for that section. Solution options are to show only a certain category like Featured-News, or to add something to exclude the passworded posts. Right now a password posts appears with the text asking for the password.

    Thanks for any suggestions guidance and/or code suggestions.

              <!--Start news in blog-->
         <?php
          $home_page_blog = inkthemes_get_option('inkthemes_home_blog_option');
          $home_page_blog_on = "on";
          if ($home_page_blog === $home_page_blog_on) {
              ?>
              <div class="feature-post">
        <?php if ( inkthemes_get_option('inkthemes_blog_heading') !='' ) {  ?>
        <h2><span class="titlebg"><?php echo stripslashes(inkthemes_get_option('inkthemes_blog_heading')); ?></span></h2>
        <?php } else {  ?>
                 <h2><span class="titlebg">NEWS IN BLOG</span></h2>
           <?php } ?>
        <?php
        $args = array(
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'caller_get_posts' => 1,
        'order' => 'DESC'
        );
        $query = new WP_Query($args); 
        $count=0;
        ?>
        <?php while ($query->have_posts()) : $query->the_post(); ?>
        <?php
        $content = $post->post_content;
        $searchimages = '~<img [^>]* />~';
        /*Run preg_match_all to grab all the images and save the results in $pics*/
        preg_match_all( $searchimages, $content, $pics );
        // Check to see if we have at least 1 image
        $iNumberOfPics = count($pics[0]);
        if (($iNumberOfPics > 0) && ($count <5) ){ 
        $count++;
        ?>
                 <div class="feature-box">
                    <div class="feature-post-inner"> <a href="<?php the_permalink() ?>"><?php inkthemes_get_image(165, 130); ?> </a> 
                       <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
                                  <?php
                                  $tit = the_title('', '', FALSE);
                                  echo substr($tit, 0, 25);
                                  if (strlen($tit) > 25)
                                      echo "...";
                                  ?>
                              </a></h2>
                       <?php echo inkthemes_custom_trim_excerpt(15); ?>
                    </div>
                 </div>
          <?php
      }
      endwhile;
      ?>
                              <?php
                              // Reset Query
                              wp_reset_query();
                              ?>
              </div>
         <?php } else {
    
          } ?>
              <!--End news in blog-->
    
  • Ahhh... came up with a fix for this. The site is going to be using the magical plugin 'Smart Passworded Pages'

    http://wordpress.org/extend/plugins/smart-passworded-pages/ This was awesome, to keep thing simple and not have each site member needing a login even, they just need their own password.

    As an added layer of protection then we can make each password group also require a login, even though it will not need to be a unique login, just a login per group.

    So by making the posts 'Private' they stop showing on the homepage of the site, where it was showing the post and asking for a Password.

    The caveat I just thought of though (so maybe still a problem) is logged in users will still see the posts on the homepage, which was pretty much breaking the homepage layout because the images were not formatting thumbnailing correctly... hmmmm... What to do? Adjusting the above code to show only Feature posts would probably still be best and then modify the front-page.php show blog posts code.