• Resolved Jacob Martella

    (@arenapigskin)


    I’m creating my first theme with all of the files needed completed. My home.php features a featured post slideshow that I got here. I copied the code word-for-word (see below), but I keep getting the following error: Fatal error: Call to a member function have_posts() on a non-object in C:\xampp\htdocs\wordpress\wp-content\themes\sports\home.php on line 21.

    <?php
    		$featuredposts = new WP_Query();
    		$featuredposts->query("showposts=4&cat=5");
    		while ($featuredposts->have_posts()) : $featuredposts->the_post();
    	?>

    I can’t find any solution for my problem. Any help?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Jacob Martella

    (@arenapigskin)

    Hold on, never mind. I realized I made an error later on down where I tried to call the variable and I had an incorrect capitalized letter. That being said, I now get the following error: Fatal error: Call to undefined method WP_Query::the_posts() in C:\xampp\htdocs\wordpress\wp-content\themes\sports\home.php on line 21.

    Any help on that.

    What does line 21 on home.php look like along with the code for a few lines above it?

    Thread Starter Jacob Martella

    (@arenapigskin)

    Yeah, sorry about that. Thought of it after I shut down last night.

    Here is line 21:
    ($featuredposts->have_posts()) : $featuredposts->the_posts();

    Here is the entire code for slideshow:

    <?php
    		$featuredposts = new WP_Query();
    		$featuredposts->query("showposts=4&cat=5");
    		while ($featuredposts->have_posts()) : $featuredposts->the_post();
    	?>
    
    	<div id="slide-<?php echo $slide_id; $slide_id++;?>">
    		<a href="<?php the_permalink() ?>">
    		<?php the_post_thumbnail( 'slideshow-photo' ); ?>
    		</a>
    	</div>
    
    	<?php endwhile; ?>
    
    	<ul id="slide-nav">
    		<?php $nav_id=1; while
    		($featuredposts->have_posts()) : $featuredposts->the_posts(); ?>
    			<li>
    				<a href="#slide-<?php echo $nav_id; ?>">
    					<span>
    						<?php the_post_thumbnail( 'nav-image' ); ?>
    					</span>
    					<?php the_title(); $nav_id++;?>
    				</a>
    			</li>
    		<?php endwhile; ?>

    Thread Starter Jacob Martella

    (@arenapigskin)

    Okay, so kept looking at the code and I figured out the problem. The second the_post() statement had an ‘s’ at the end of it (result: the_posts() ). So I’m not getting the error anymore; however, the slideshow isn’t working (see this link). The tutorial says to use wp_enqueue_scripts() to get the ‘jquery’, ‘jquery-ui-core’ and ‘jquery-ui-tabs’ files. Not sure why it’s not working.

    And finally, my CSS skills are a bit on the bad side, obviously. If anyone wishes to help me, message me and I’ll see if I can get you the files as soon as possible. Thanks in advance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Keep Getting Member Function Error’ is closed to new replies.