• Resolved starwag

    (@starwag)


    I have a search results page that connects to a loop.php. Currently, when I type the word “roses” into my search box, I should be getting 5 post results, but I am only able to see 4 posts. I know this is not being chopped off at the top, because I have checked the order of the posts. The posts should display thus, from first to last: “Fire Blight”, “Autumn: Better”, “Bouquets and”, “Autumn Musings”, and “Last Projects and Plant Arrivals”. (If I type any search word that yields more than 4 results this will do the same, but for the purpose of this experiment I am limiting the search to “roses” because I still have much of the site marked private.)

    The search results are supposed to replace the blogfeed found in the gray box to the right of the screen, but are currently displaying a chopped up version in the gray box and yet are fully displayed in the blue section in the center of the screen. That center portion is reserved for whatever post the reader happens to be viewing, and the results should only display in the gray box, replacing the blog feed.

    I have looked at the CSS, and there doesn’t seem to be any trouble there. I also have played around a bit with the function code, which seems to either make no difference or make it worse. I also have the Reading section of the site marked to display at least 10 posts. I am almost 100% certain I have made a rookie error in either the search.php file or the loop.php file, but I am not sure what it is. I am including both codes here, as well as the pagination.php file. Thanks for the help in advance.

    Search

    <?php get_header(); ?>
    <div id="mySidenav" class="sidenav" style="background-image: url('gard.jpg')">
      <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
    	<?php wp_nav_menu( array( 'theme_location' => 'header-menu' ) ); ?>
    </div>
    <div id="sidebar">
    	<div id="top">
    		<div id="menucontainer" cursor:"pointer" onclick="openNav()">
    		<p> Menu </p>
    		<div class="bar"></div>
    		<div class="bar"></div>
    		<div class="bar"></div>
    </div>
    	</div>
    	<div id="middle" style="background-image: url('gard.jpg')"></div>
    	<div id="bottom"></div>
    </div>
    <div id="center">
    	<header>
    	<!-- post title -->
    		<div id="excerptbox">
    		
    				<?php theme1wp_excerpt('theme1wp_index'); ?>
    			
    		</div>	
    		<div id="borderboxtext">
    	<!-- post title -->
    		<div id="titletextbox">
    				<?php the_title(); ?>
    			<?php $subtitle = get_post_meta($post->ID, 'subtitle', true); if ($subtitle !== '') {echo '<p>' . $subtitle . '</p>';
    } ?>
    
    		</div>	
    		<!-- /post title -->
    		</div>
    		<!-- /post title -->
    			<!-- post thumbnail -->
    		<div id="headpic">
    					<?php if ( has_post_thumbnail()) : // Check if Thumbnail exists ?>
    				<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
    					<?php the_post_thumbnail(); // Fullsize image for the single post ?>
    				</a>
    			<?php endif; ?>
    			</div>
    		<!-- /post thumbnail -->
    
    	</header>
    <div id="post">
    	
    	<?php if (have_posts()): while (have_posts()) : the_post(); ?>
    
    		<!-- article -->
    		<span id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
    			<!-- post details -->
    			<span class="date"><?php the_time('F j, Y'); ?></span>
    			<!-- /post details -->
    
    			<?php the_content(); // Dynamic Content ?>
    
    			<?php the_tags( __( 'Tags: ', 'theme1' ), ', ', '<br>'); // Separated by commas with a line break at the end ?>
    
    		</span>
    		<!-- /article -->
    
    	<?php endwhile; ?>
    
    	<?php else: ?>
    
    		<!-- article -->
    		<article>
    
    			<h1><?php _e( 'Sorry, nothing to display.', 'theme1' ); ?></h1>
    
    		</article>
    		<!-- /article -->
    
    	<?php endif; ?>
    		</div>
    	<div id="comments">
    		<?php comments_template(); ?>
    	</div>
    </div>
    
    	<footer>
    				<p class="copyright">
    				&copy; 2016 - <?php echo date('Y'); ?> Copyright <?php bloginfo('name'); ?>.
    		</p>
    		<p>
    			This site is meant for entertainment purposes only and is not intended to replace professional knowledge.
    		</p>
    	</footer>
    </div>
    
    	<div id="rightcontainer">
    	<button id="down" onclick="scrollDown()" onmouseenter="Highlight1()">&#9660</button>
    <button id="up" onclick="scrollUp()" onmouseenter="Highlight2()">&#9650</button>
    
    			<h1><?php echo sprintf( __( '%s Search Results for ', 'theme1' ), $wp_query->found_posts ); echo get_search_query();?></h1>
    					<?php get_template_part('loop'); ?>
    
    	
    	<?php get_template_part('pagination'); ?>
    </div>
    </div>
    <?php get_footer(); ?>

    Loop

    <div id="blogcontainer" onmouseover="RollOff1()" onmouseout="RollOff2()">
    <?php if (have_posts()): while (have_posts()) : the_post(); ?>
    
    	<div id="postcontainer">
    		
    
    		<!-- post thumbnail -->
    		<div class="thumb">
    		<?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
    			<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
    				<?php the_post_thumbnail(array(100,100)); // Declare pixel size you need inside the array ?>
    			</a>
    		<?php endif; ?>
    		</div><!-- /post thumbnail -->
    		<div class="topblock">
    		<div class="titleblock">
    			<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    		</div>
    			<div class="moreblock">	<a href="<?php the_permalink(); ?>">MORE ></a></div>
    		</div>
    <div class="block">
    	<div class="date"><p><span class="date"><?php the_time('F j, Y'); ?></span></p></div>
    		<?php html5wp_excerpt('theme1wp_index'); // Build your custom callback length in functions.php ?>
    
    		</div>
    			<!-- /post details -->
    	</div>
    	<!-- /article -->
    
    <?php endwhile; ?>
    
    <?php else: ?>
    	<!-- article -->
    	
    		<h2><?php _e( 'Sorry, nothing to display.', 'theme1' ); ?></h2>
    	
    
    <?php endif; ?>
    	</div>
    </div>
    
    <?php get_footer(); ?>
    
    

    Pagination

    <div class="pagination">
    	<?php theme1wp_pagination(); ?>
    </div>'

    This is the pagination function in the function.php file

    function theme1wp_pagination()
    {
        global $wp_query;
        $big = 999999999;
        echo paginate_links(array(
            'base' => str_replace($big, '%#%', get_pagenum_link($big)),
            'format' => '?paged=%#%',
            'current' => max(1, get_query_var('paged')),
            'total' => $wp_query->max_num_pages
        ));
    }
    

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    All 5 of your posts are in the gray area, except the top one is hidden under the “5 search results for roses” header. If you look at your page’s HTML source, you’ll see 5 different divs with ID=”postcpontainer”, each having a different post. So essentially you have a CSS issue where the posts container runs underneath the header z-index wise, instead of below it, y-axis wise.

    Use your browser’s CSS inspector tool to help you figure out how to size the header and gray container so they coexist instead of one layering on top of the other.

    The blue area should not be running a loop, because the main query is for search results. The loop displays whatever the main query returns. The blue area’s code should somehow determine what post is being viewed and display that one post. Perhaps by getting the one post with get_post(), assuming the ID of the currently viewed post is known.

    Not a big deal right now, but the gray area has 5 divs with all the same ID attribute. This is invalid HTML. Only one element per page can have a particular ID attribute. I think you probably want “postcontainer” to be a class instead of ID.

    Thread Starter starwag

    (@starwag)

    Would using AJAX to load the search results keep the results from replacing the post in the blue area, or would it still require using get_post() regardless?

    Thread Starter starwag

    (@starwag)

    What I mean is, if I chopped down my search.php file to just be the gray box, and then used AJAX to load the search.php in place of the gray blog feed box on my single post page, would that still necessitate using get_post(), or could I avoid having to use it? My goal was to eventually load search results in place of the blog feed on any page without having to refresh, which means I won’t know what post or page someone is clicking/reading when they decide to use the search form.

    Moderator bcworkz

    (@bcworkz)

    If all post content is available on the page somewhere, you don’t need to use get_post(), or Ajax for that matter. You just need script to grab the correct content and display it in the blue area. Here is what seems feasible to me, assuming I’ve correctly understood the user experience you are after:

    User does a search and the results are displayed in the gray area. Only the post title and excerpt is displayed, but the entire content is also part of HTML, hidden from view. Initially, the first post is highlighted and its full content is shown in the blue area. So far, no script is needed, all the output is achieved with PHP. When the user clicks another post, or arrows down, the highlight changes accordingly and the blue area content along with it. This of course is where script is needed to handle user actions.

    Since the post content is available on the page, you do not need Ajax to go back to the server to fetch more data. If your posts are really extensive or contain lots of images, it may not be practical to load full content of all 5 search results. In that case Ajax should be used to fetch the chosen post’s content. In this case, your Ajax handler server side will need to call get_post() or something similar to get the data from the DB and to relay it back to the server. But I think there is a good chance this will not be necessary. Try the non-Ajax version first and see how it works out. It’ll probably be fine.

    Thread Starter starwag

    (@starwag)

    The CSS solution did help with cutting the results short. However, I’m going to mark this as answered and address the other half of this issue in a separate posting. I feel I am getting into something different than just the search results getting cut short, and no one else is going to get the benefit of the solutions if I bury them in this thread. Thanks again.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Search Results Cut Short’ is closed to new replies.