• Resolved starwag

    (@starwag)


    On the website I am working on, the loop was working great until I styled it. To do this I separated off aspects of the loop by placing them in divs. However, once I did this, and the loop was looking pretty close to how I wanted it, the loop began displaying only one post. I have checked and rechecked the functions file, and nothing is different there from what it was when the loop was working fine. I also checked the Settings -Reading section and made sure the max post was set to 5, but it still continues to show just the last post made.

    I also realize that there is another loop on this page to display the post, but this problem is the same across all pages, even those without another loop to be bothered with. It is also worth noting that, even on this page, the loop was working fine and displaying 5 posts before I styled it.

    I had a look on another forum where someone was having this same problem 4 years ago, but that person never got an answer. Any ideas anyone? I am including the code for the page I am working on here. The section that is giving me trouble would be under blogcontainer:

    <?php get_header(); ?>
    <div id="mySidenav" class="sidenav" style="background-image: url('http://mysite.com/wp-content/uploads/year/month/image.jpg')">
      <a href="void(0)">&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('http://mysite.com/wp-content/uploads/year/month/image.jpg')"></div>
    	<div id="bottom"></div>
    </div>
    <div id="center">
    	<header>
    	<!-- post title -->
    			<h1>
    				<a>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    			</h1>
    			<!-- /post title -->
    			<!-- post thumbnail -->
    			<?php if ( has_post_thumbnail()) : // Check if Thumbnail exists ?>
    				<a>" title="<?php the_title(); ?>">
    					<?php the_post_thumbnail(); // Fullsize image for the single post ?>
    				</a>
    			<?php endif; ?>
    			<!-- /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>
    			<span class="comments"><?php if (comments_open( get_the_ID() ) ) comments_popup_link( __( 'Leave your thoughts', 'html5blank' ), __( '1 Comment', 'html5blank' ), __( '% Comments', 'html5blank' )); ?></span>
    			<!-- /post details -->
    
    			<?php the_content(); // Dynamic Content ?>
    
    			<?php the_tags( __( 'Tags: ', 'html5blank' ), ', ', '<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.', 'html5blank' ); ?></h1>
    
    		</article>
    		<!-- /article -->
    
    	<?php endif; ?>
    		</div>
    	<div id="comments">
    		<?php comments_template(); ?>
    	</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">
    <div id="searchbox">
    	<form class="search" method="get" action="<?php echo home_url(); ?>" role="search">
    	<input class="search-input" type="search" name="s" placeholder="<?php _e( 'To search, type and hit enter.', 'html5blank' ); ?>">
    	<button class="search-submit" type="submit" role="button"><?php _e( 'Search', 'html5blank' ); ?></button>
    </form>
    
    		</div>
    <div id="blogcontainer">
    	<?php query_posts('post_type=post') ?>
    		<?php if (have_posts()): while (have_posts()) : the_post(); ?>
    	<div class="postcontainer" id="post-<?php the_ID(); ?>">
    <div class="thumb">
    				<?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
    			<a>" title="<?php the_title(); ?>">
    				<?php the_post_thumbnail(array(100,100)); // Declare pixel size you need inside the array ?>
    			</a>
    		<?php endif; ?>
    
    		
    		</div>
    <div class="topblock"><div class="titleblock">	<a>" title="<?php the_title(); ?>"><?php the_title(); ?></a></div>
    <div class="moreblock">MORE ></div>
    </div>
    <div class="block">
    <div class="date"><p><span class="date"><?php the_time('F j, Y'); ?></span></p></div>
    	<?php html5wp_excerpt('html5wp_index'); ?>
    </div>
    		
    		<?php endwhile; ?>
    
    		<?php else: ?>
    
    				<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
    
    		<?php endif; ?>
    </div>
    	
    
    			</div>
    </div>
    
    	
    
    <?php get_footer(); ?>
    
    • This topic was modified 7 years, 6 months ago by starwag.

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

Viewing 11 replies - 1 through 11 (of 11 total)
  • I went to your link and it is not there.
    I saw this:

    Your theme needs to set the body background color (that yellow is my browser default color), especially if you are going to use white text.

    Moderator bcworkz

    (@bcworkz)

    The only time a named page would normally display multiple posts is if your site has a static front page and you’ve designated the page as the blog listing page. Otherwise only showing the content of a single page is normal.

    In any case, if you are not getting what you expected displayed, whether you only get one post or no posts (as is the current state), the main query is not doing what you expect. It’s difficult to say how the query is getting corrupted. It is often due to errant code hooked into “pre_get_posts” if not code directly on the template. Editing CSS or divs on a template would not change how the main query works. Something else has changed as well if it was working before.

    Thread Starter starwag

    (@starwag)

    The link should work now. I had it set to private, unfortunately. Sorry about that.

    In spite of going through the code again, I still don’t have a clue how to fix this. I know that post pages only display one post by default, but I did start a new loop query. It starts a new loop but will only display the very last post typed, rather than the 5 I set it to display.

    On the back end, when I go to inspect the page, the code is showing as running every other post of the last 5. So, for example: 228,226, and 224 are running, not showing, but running on the back end. What happened to 229 and 225? And why aren’t any of them showing?

    Moderator bcworkz

    (@bcworkz)

    Ah, I stopped reading your code when I saw footer, apologies. It seems that posts per page is set to 1 for some reason. Verify what you have in reading settings. If that’s OK, there is some override code somewhere. You can try adding &posts_per_page=5 to the query arguments, but if there is override code somewhere it will not help.

    Thread Starter starwag

    (@starwag)

    No worries. Thanks for coming back to the question. Yeah, I’ve thought there must be something somewhere, but I simply cannot find it. I have no memory of setting anything to 1, and the reading settings are also on 5. I’ve been avoiding ripping the entire site apart and adding back code line by line, but if no one else has any suggestions, it sounds like that might be what I’ll have to do.

    Moderator bcworkz

    (@bcworkz)

    The usual action to alter queries is “pre_get_posts”. Add some code to a template to dump out global var $wp_filter inside of pre tags. Actions are listed here as well. Find the array key “pre_get_posts” and note what callback functions are assigned. Find the named functions in source code somewhere. The Linux grep command or similar text search utility is very useful for this.

    If the callback name is a long hexadecimal string, it’s probably a closure (or anonymous function). In this case, simply grep for “pre_get_posts” in source.

    Other potential filters that can be used to alter queries are “post_limits”, “posts_clause”, and “posts_request”. This is not a comprehensive list, but the most likely hooks that devs use. Good luck in your search!

    • This reply was modified 7 years, 6 months ago by bcworkz.
    Thread Starter starwag

    (@starwag)

    Okay, so I went back to my original theory that this was a style issue, stripped the style sheet to not display any backgrounds and to show/scroll everything, and it seems like I am getting the posts, but that they are nesting themselves inside of each other. However, I have no clue why they are nesting. My original files don’t do this across any browser, and this only began when I styled the loop. Any experience with this happening? I’ll keep playing with it to see if I can figure it out, but I’m thinking this shouldn’t happen simply because I styled it.

    Moderator bcworkz

    (@bcworkz)

    Ha! That’s a genius inspiration! I’ve seen that with small elements with a lot of CSS applied, like menu items, but never entire posts.

    Are we looking at the same page? The one linked in your OP? I searched for the “postcontainer” class in that page’s source code and only one occurrence was found, indicating there is only one post returned in the query. Where are you seeing 5 posts? If CSS rules are hiding posts, the element inspector tool of your browser will likely help you track down the responsible CSS. If you still have trouble, I could take a look as well, but I need a link to a page that has 5 posts returned.

    Thread Starter starwag

    (@starwag)

    Thanks! Yeah, in fact the whole site is showing the nested posts now (I’ll link it again). It’s on the part of the site right next to the scrollbar. It looks hidden because you have to scroll through that section’s scrollbar to see the other scrollable section inside of that, then that section has to be scrolled through to see the next scrollable section, and so on and so forth. Each scrollable section seems to display two posts, the first, and then the second which becomes its own scrollable section with two posts inside of it. Also, I upped the post limit to 10, just to see if I could get more posts than the 3 I was getting, which means there’s a lot more nested than there was before.

    the site

    Moderator bcworkz

    (@bcworkz)

    Ah, the linked page’s sidebar only has one post for some reason, but I see what you mean on other pages. One problem is each successive post is nested inside the previous because one of the closing div tags is after the endwhile statement while it should be before. Or it’s missing altogether. I’ll leave it to you to decide which. Unless you really want nested elements, it’s important to ensure all tags within a loop balance before ending the loop.

    Actually, ensuring all tags throughout balance is important. Browsers are forgiving with this, but the W3C validator is not. What I do if the matching tag is not obvious just from proper nesting of code lines is label the closing tag with a comment identifying the class or ID of its mate. I find it’s very helpful. There might be more things to deal with in CSS, but we cannot properly evaluate CSS until the HTML is straightened out.

    Thread Starter starwag

    (@starwag)

    Thanks! I think that is going to work. I just placed the one div over the php ending and it all started working beautifully. So simple, yet so complex. Thanks again!

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Loop Showing 1 Post Only’ is closed to new replies.