• Resolved starwag

    (@starwag)


    I am nearly finished building the site I am working on. The design requires individual pages to be designed differently, with a custom loop that will display page specific content along with the normal running loop on the side that will continue to display the last 10 to 20 posts. For example: The page marked Garden will have all posts relating to garden in the center portion of the site, while the most recent posts continue to run on the right side of the page. The same will be true of each of the pages.

    What I am having trouble with is that every time I try to make a custom loop I get a parse error returned to me.

    I have followed to the letter, not one, but 5 different videos, tutorials, and articles describing how to do this.

    I have tried putting wp_query markup in both the page.php and the functions.php folder, both simultaneously and individually, and I keep getting messages like “unnecessary ‘}’ or “unnecessary ‘,'”. However, when these offending symbols are removed, the next letter, word, or symbol just takes its place as the “unnecessary” feature until I end up having to delete everything I have just done.

    I know I must tweak what tutorials show me for my own needs (aka rename queries etc. after my own content) but even when I retool the entire site to have files and names exactly like those in the tutorials, I still can’t keep the error messages from popping up!

    I am trying to edit the templates themselves, and yes, I know, child themes are better, but this, I believe, was an unavoidable challenge I had to tackle.

    I do also realize that simply using page.php will not be sufficient in the long run for what I need, but there’s no sense in creating specific pages when I can’t even get one to do what I want it to.

    Furthermore, I am working out of the html5blank theme and wondered if there was something amiss in the theme that could be preventing me from doing this, but I’ve checked each page, and especially the functions.php page many times to see if there was a preexisting query that might be overriding this, but I see none.

    I’m at my wits end. I’m so close to being done and yet I’ve been stumped on this problem for nearly a month. I have not included code here, because I have tried so many different ways of doing this, but if someone has an idea, I will be happy to cough up any code he/she would need to help me with this problem!

    Thanks ahead of time!

Viewing 4 replies - 1 through 4 (of 4 total)
  • please post the full code of at least one of the templates, so somebody can double-check if there is anything wrong.

    Thread Starter starwag

    (@starwag)

    Below is one of my most recent attempts from my page.php file. The only place I have placed the proposed loop is inside the div marked ‘contents2’. I think this is one of the messier versions I’ve used, and I’ve tried it without the extra php code in the middle, and it still didn’t work. I’ve got more if you don’t like this one. I can probably still link the tutorial I got this from if you need that.

    <?php get_header(); ?>
    <div id="menu">
    <div id="topleftcorner">
    <div id="pinterest"><a href="https://pinterest.com/peggyslittlecor/"><img src="pin.png" alt="follow me" /></a></div>
    </div>
    <div id="homepic"><img src="https://peggyslittlecorner.com/wp-content/uploads/2016/07/sheepside.jpg"></div>
    <div id="logo"><a href="fluidpage.html"><img src="https://peggyslittlecorner.com/wp-content/uploads/2016/07/logobox.jpg"></a></div>
    </div>
    <div id="article">
    <div id="section1">
    <div id="topi"><img src="sheep.jpg"></div>
    <div id="contents1">
    	<li>Meet the Flock</li>
    	<li>Understanding Sheep</li>
    	<li>Then and Now</li>
    	<li>Breeds</li>
    	<li>Housing</li>
    	<li>Feed</li>
    	<li>Bottle Feeding</li>
    	<li>Sheering</li>
    	<li>Horns and Hoof Trimming</li>
    	<li>Tail Bobbing</li>
    </div>
    <div id="title1">
    <h2>| Introduction</h2>
    <h3>An introduction to my flock and some practical beginner knowledge on rearing sheep</h3>
    </div>
    </div>
    <div id="section2">
    <div id="middlei"><img src="elsie-health.jpg"></div>
    <div id="title2">
    <h2>| Health</h2>
    <h3>Sheep can be rather delicate, and if you plan on owning one, this section will be your primary concern</h3>
    </div>
    <div id="contents2">
    
    <?php $args = array('category_name' => 'sheep'); ?>
    <?php $sheepPosts = new WP_Query($args); ?>
    <?php if ($sheepPosts->have_posts()): ?>
    <?php ?>
    <?php while ($sheepPosts->have_posts()) : $sheepPosts->the post (); ?>
    <h2><?php the_title(); ?></h2>
    <?php endwhile; ?>
    <?php else: ?>
    </php get_template_part( 'content', 'none' ); ?>
    <?php endif;?>
    
    </div>
    </div>
    <div id="section3">
    <div id="bottomi"><img src="lily-apple-blossoms.jpg"></div>
    <div id="contents3">
    	<li>My collection</li>
    	<li>Musings on sheep at Easter</li>
    </div>
    <div id="title3">
    <h2>| Other</h2>
    <h3>Musings on my sheep, the antics they get themselves into, and the new things I learn everyday</h3>
    </div>
    </div>
    </div>
    
    <div id="left">
    		<?php query_posts('post_type=post') ?>
    <?php if (have_posts()): while (have_posts()) : the_post(); ?>
    
    			<!-- article -->
    			<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    	<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
    			<!-- post title -->
    			<h1>
    				<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    			</h1>
    			<!-- /post title -->
    
    			<!-- post details -->
    			<span class="date"><?php the_time('F j, Y'); ?></span>
    	<p>
    
    		<?php echo get_the_excerpt(); ?>
    </p>
    
    				<br class="clear">
    			</article>
    			<!-- /article -->
    
    <hr>
    		<?php endwhile; ?>
    
    		<?php else: ?>
    
    			<!-- article -->
    			<article>
    
    				<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
    
    		<?php endif; ?>
    </div>
    <div id="right"></div>
    
    <?php get_footer(); ?>

    there are some typing mistakes in the code –

    correct this line (corrected version shown):

    <?php while($sheepPosts->have_posts()) : $sheepPosts->the_post(); ?>

    and this line:

    <?php get_template_part( 'content', 'none' ); ?>

    if you have errors with any of the other trials, please post the full code and the exact full error message.

    Thread Starter starwag

    (@starwag)

    Oh good grief. I thought I fixed the mistakes by just changing them on my page and didn’t work. I got the error below, but then I just copy pasted from your post and it worked like a dream! Thank you so very much! I’ve got happy tears this is such a relief! Can’t believe it was something so simple and I kept missing it.

    Parse error: syntax error, unexpected ‘post’ (T_STRING) in /home/content/p3pnexwpnas07_data01/48/2730848/html/wp-content/themes/html5blank-stable/html5blank-stable/page.php on line 40

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘adding custom loop and getting errors’ is closed to new replies.