Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This search.php shows all the results from a said search however, doesn't include the title, The Search Results For...... and search query amount; or even the no searches found and prints the searchform.

<?php get_header(); ?>
<?php if ( have_posts() ) : ?>

 <h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'nothing' ), '' . get_search_query() . '' ); ?></h1>


<!--custom area--> 

<ul id="post-list">

 <?php if (have_posts()) : while (have_posts()) : the_post(); ?>


<?php
 $featured = get_post_meta($post->ID,'_thumbnail_id',true);
 $attachments = get_children( 'post_type=attachment&orderby=menu_order&exclude='.$featured.'&post_mime_type=image&post_parent='.$post->ID );
 $vimeo = get_post_meta($post->ID, 'rw_post-vimeo',true);?>
<li class="post">

<span class="entry-published">
<time datetime="<?php the_time('Y-m-d')?>"><?php the_time('F jS, Y') ?></time>
    <!--Start Single Image-->
<?php  get_template_part( 'includes/inc-image' ); ?>
<?php endif; ?>
<!--End Single Image-->


<!--Start Rest Of Post Content-->
<?php  get_template_part( 'includes/inc-detail' ); ?>
<?php endwhile; endif; ?>


<section id="pagination">
<?php wp_pagenavi(); ?> 
</section>

<!--End Rest Of Post Content-->

</li>

</ul>


<!-- end of custom area -->



<?php else : ?>
<h2><?php _e( 'Nothing Found', 'nothing' ); ?></h2>
<p><?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'twentyten' ); ?></p>
<?php get_search_form(); ?>
<?php endif; ?>

<?php get_footer(); ?>

Interesting though the posts in their li tag appear witin the opening

<h1 class="page-title">

So i assume its a statement issue but cannot figure it out :(

Any ideas?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

I see at least two potential issues:

  1. You have if ( have_posts() ) : twice.

Here:

<?php if ( have_posts() ) : ?>
<h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'nothing' ), '' . get_search_query() . '' ); ?></h1>

And here:

<ul id="post-list">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  1. The get_template_part() template tag expects a filename slug, rather than a path. So you may want to use the locate_template() template tag instead for these:

Try:

<?php  locate_template( 'includes/inc-image.php' ); ?>
<?php  locate_template( 'includes/inc-detail.php' ); ?>

EDIT

The locate_template doesn't load any content when i apply that...

Do those files exist?

...and removing one of the if gives me an unexpected T_ELSEIF error... :(

Yeah, because you have an improperly opened/closed else/if construct. Get rid of the stray endif here:

<?php  get_template_part( 'includes/inc-image' ); ?>
<?php endif; ?>

EDIT 2

So, here's a rewrite, attempted to fix your syntax errors:

<?php get_header(); ?>

<h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'nothing' ), '' . get_search_query() . '' ); ?></h1>

<?php if ( have_posts() ) : ?>

    <ul id="post-list">

        <?php while (have_posts()) : the_post(); ?>

            <?php
            $featured = get_post_meta($post->ID,'_thumbnail_id',true);
            $attachments = get_children( 'post_type=attachment&orderby=menu_order&exclude='.$featured.'&post_mime_type=image&post_parent='.$post->ID );
            $vimeo = get_post_meta($post->ID, 'rw_post-vimeo',true);
            ?>
            <li class="post">

                <span class="entry-published">
                <time datetime="<?php the_time('Y-m-d')?>"><?php the_time('F jS, Y') ?></time>
                <!--Start Single Image-->
                <?php  get_template_part( 'includes/inc-image' ); ?>
                <!--End Single Image-->

                <!--Start Rest Of Post Content-->
                <?php  get_template_part( 'includes/inc-detail' ); ?>

                <!--End Rest Of Post Content-->

            </li>

        <?php endwhile; ?>

    </ul>

    <section id="pagination">
    <?php wp_pagenavi(); ?> 
    </section>

<?php else : ?>

    <h2><?php _e( 'Nothing Found', 'nothing' ); ?></h2>
    <p><?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'twentyten' ); ?></p>
    <?php get_search_form(); ?>

<?php endif; ?>

<?php get_footer(); ?>

Verify that works, and then we'll tackle the template-part output issues.

share|improve this answer
    
The locate_template doesn't load any content when i apply that and removing one of the if gives me an unexpected T_ELSEIF error... :( –  Jezthomp Oct 26 '11 at 13:20
    
See updated answer, addressing these two issues. –  Chip Bennett Oct 26 '11 at 13:26
    
Thanks chip. Yes the files exist because the page content is loading originally and does on the index.php also. Its the search.php elements title etc that is not. Still get another unexpected T_ELSE error... :( –  Jezthomp Oct 26 '11 at 13:36
    
"Still get another unexpected T_ELSE error... :(" - yes, because there are more such errors. I would suggest cleaning up your PHP syntax, and then attempting to figure out what's going on with your query output. –  Chip Bennett Oct 26 '11 at 13:41
    
The page works perfectly on index.php and in single.php, its only once it tries to display the search results in search.php does it play up... –  Jezthomp Oct 26 '11 at 13:44
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.