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 code in the search.php file does not work:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php if( get_post_type() == 'post' ) {?>

<div id="post">
<div id="postimagen"><a href="<?php the_permalink() ?>"><?php the_post_thumbnail( 'thumbnail', $attr ); ?></a></div>
<div id="postcontent">
<div id="categorias">
<?php foreach((get_the_category()) as $category) { 
echo '<li class="cat-' .$category->cat_name. '"><a href="'.get_category_link($category->term_id ).'">' . $category->cat_name . '</a></li>';}?>
</div>
<a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><h1><?php the_title(); ?></h1></a>
<div id="info">
<div id="informacion">Escrito por <?php the_author_posts_link(); ?> el <?php the_time('d/m/Y') ?> a las <?php the_time('G:i'); ?></div>
<div id="numcoment"><?php comments_number('0 Comentarios', '1 Comentario', '% Comentarios' );?></div>
</div>
<?php the_excerpt() ?>
<div id="readmore"><a href="<?php the_permalink() ?>">Continuar</a></div>
</div>

<div class="clear"></div>
</div>
<?php } if( get_post_type() == 'articulo' ) {?>

<div id="post">
<div class="clear"></div>
<div id="postcontent2"><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><h1><?php the_title(); ?></h1></a>
<div id="postmeta">
Escrito por <?php the_author_posts_link(); ?> el <?php the_time('d/m/Y') ?> a las <?php the_time('G:i'); ?>
<div id="numcoment"><?php comments_number('0 Comentarios', '1 Comentario', '% Comentarios' );?></div>
</div>
<?php the_content(false); ?>
<div id="readmore"><a href="<?php the_permalink() ?>">Continuar</a></div>
</div>
<div class="clear"></div>
</div>

<?php } else; endwhile;?>
<?php endif; ?>
share|improve this question
    
what is the result? please describe "does not work" in more detail. –  Michael Mar 29 '13 at 11:50
    
Sorry, when I search something the page is blank. –  seravifer Mar 29 '13 at 12:14
1  
What have you done to troubleshoot? What PHP errors or notices do you get? Where is the rest of the template file code (what's included in the question is just the loop). –  Chip Bennett Mar 29 '13 at 12:47

1 Answer 1

First of all, it works on my test install. I guess it depends on what you are searching for. I'm searching for 'hello' and the post 'Hello World' shows up fine.

Second, I get the following notice for this bit the_post_thumbnail( 'thumbnail', $attr );:

PHP Notice: Undefined variable: attr

Third, just to be a perfectionist, I would put elseif instead of if right here:

<?php } if( get_post_type() == 'articulo' ) {?>
share|improve this answer

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.