SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot darkwarrior's Avatar
    Join Date
    Dec 2010
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Query returning posts if it doesn't find the posts it is looking for

    Hi all, I'm basically attempting to use a Featured Post banner combined with javascript for a slide function. Besides it acting different for some reason between my local hosted version and the online version, its being difficult to manage.

    I'm running the below code, but it appears to be returning posts IF it doesn't find sticky posts, so it shows the featured banner (empty). How do I make the query just stop if it doesn't find exactly what I have asked for?

    PHP Code:
      <?php if(is_front_page() && !is_paged()) {
                
    $featured_args = array(
                                
    'post__in' => get_option'sticky_posts' ),
                                
    'post_status' => 'publish',
                                
    'no_found_rows' => true
                            
    );  ?> 
                                       
               
                <?php $featured = new WP_Query($featured_args);
                       if ( 
    $featured->have_posts() ) { ?>
                                        
                                        
                                        
                               <div id="featured">
                                   <div id="featbanner" class="maxwidth">    
                                    <div id="featcontainer" >

                                    <?php while ($featured->have_posts()) : $featured->the_post(); ?>
                                     <?php if (!is_sticky($featured->ID)) continue; ?>
                                        
                                        <article class="sticky ">
                                            <div class="desc">
                                                <h2><?php the_title(); ?></h2>
                                
                                                       <div class="entry-content">
                                                        <?php excerpt('26'); ?>
                                                    </div>
                                                    <div class="post-info">
                                                        <a href="<?php the_permalink(); ?>" class="call-to-action-alt">Continue Reading</a>
                                                    </div>
                                            </div>
                                                
                                                <?php
                                                        
    if (has_post_thumbnail()) {
                                                            
    the_post_thumbnail(('large'),
                                                                array(
                                                                    
    'class' => 'thumbnail',
                                                                    
    'alt' => 'post thumbnail',
                                                                    
    'title' => 'my custom title'));                                
                                                        }
                                                    
    ?>      
                                        </article>
                                    <?php endwhile; ?>
                            
                                    </div><!--featcontainer-->
                            
                                                    <?php wp_reset_postdata(); ?>
                  
                                          <div id="banner-nav"></div>
                                </div><!--featbanner-->
                               </div><!--featured-->
               <?php }?>

  2. #2
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?php if(is_front_page() && !is_paged()) {
    think thats your issue should be !is_page(){

    I think you can streamline your code. Are you doing this in the header.php ?
    this is how I would do it.

    <?php if (!is_page('gallery') && !is_page('map') && !is_page('contact') && !is_single()) {?>

    your html

    <?php };?>

  3. #3
    SitePoint Zealot darkwarrior's Avatar
    Join Date
    Dec 2010
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well the idea is for it to only show on the front page. The !is_paged is to stop it showing on any paginated versions of the front page.

    It is being done in the header.


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
  •