WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Keep Getting Member Function Error (5 posts)

  1. Jacob Martella
    Member
    Posted 2 years ago #

    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?

  2. Jacob Martella
    Member
    Posted 2 years ago #

    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.

  3. JarretC
    Member
    Posted 2 years ago #

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

  4. Jacob Martella
    Member
    Posted 2 years ago #

    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; ?>
  5. Jacob Martella
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic