Ver Mensaje Individual
  #9 (permalink)  
Antiguo 08/12/2011, 12:41
Avatar de metacortex
metacortex
Viejo demente
 
Fecha de Ingreso: junio-2004
Ubicación: Caracas - Venezuela
Mensajes: 9.027
Antigüedad: 19 años, 11 meses
Puntos: 832
Respuesta: home.php o index.php... Esa es la cuestión

Cita:
Iniciado por rogertm Ver Mensaje
Ahora bien, si hago un theme donde cree un archivo llamado home.php (Twenty Ten no lo trae) donde cargue el front de mi sitio, puedo, en teoría, hacer de index.php un archivo donde muestre un mensaje para quien llegue luego de hacer una búsqueda vacía, o poner un formulario de búsqueda avanzada o algo así.
La jerarquía de archivos es un recurso para el desarrollador y no está relacionada con este problema, el cual es simple: is_search() sólo se activa cuando "s=" no es nulo. Por tal motivo fallarán todos los intentos de aplicar alguna condicional si te basas en éste.

Si trabajas con $_GET puedes condicionar el contenido antes del envío y fuera del loop, en el mismo index.php. Reemplaza el código completo de tu index.php por éste y luego efectúa una búsqueda vacía (Ojo: en Twenty Eleven):

Código PHP:
Ver original
  1. <?php
  2. /**
  3.  * The main template file.
  4.  *
  5.  * This is the most generic template file in a WordPress theme
  6.  * and one of the two required files for a theme (the other being style.css).
  7.  * It is used to display a page when nothing more specific matches a query.
  8.  * E.g., it puts together the home page when no home.php file exists.
  9.  * Learn more: http://codex.wordpress.org/Template_Hierarchy
  10.  *
  11.  * @package WordPress
  12.  * @subpackage Twenty_Eleven
  13.  */
  14.  
  15. get_header(); ?>
  16.  
  17.         <div id="primary">
  18.             <div id="content" role="main">
  19.  
  20.             <?php if(isset($_GET['s']) and $_GET['s'] == null) : ?>
  21.  
  22.                 <p>Resultado vacío</p>
  23.  
  24.             <?php else : ?>
  25.  
  26.                 <?php if ( have_posts() ) : ?>
  27.  
  28.                     <?php twentyeleven_content_nav( 'nav-above' ); ?>
  29.  
  30.                     <?php /* Start the Loop */ ?>
  31.                     <?php while ( have_posts() ) : the_post(); ?>
  32.  
  33.                         <?php get_template_part( 'content', get_post_format() ); ?>
  34.  
  35.                     <?php endwhile; ?>
  36.  
  37.                     <?php twentyeleven_content_nav( 'nav-below' ); ?>
  38.  
  39.                 <?php else : ?>
  40.  
  41.                     <article id="post-0" class="post no-results not-found">
  42.                         <header class="entry-header">
  43.                             <h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
  44.                         </header><!-- .entry-header -->
  45.  
  46.                         <div class="entry-content">
  47.                             <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
  48.                             <?php get_search_form(); ?>
  49.                         </div><!-- .entry-content -->
  50.                     </article><!-- #post-0 -->
  51.  
  52.                 <?php endif; ?>
  53.  
  54.             <?php endif; ?>
  55.  
  56.             </div><!-- #content -->
  57.         </div><!-- #primary -->
  58.  
  59. <?php get_sidebar(); ?>
  60. <?php get_footer(); ?>