Foros del Web » Creando para Internet » Sistemas de gestión de contenidos » WordPress »

Sidebars dinámicos

Estas en el tema de Sidebars dinámicos en el foro de WordPress en Foros del Web. Buenas, me gustaría mostrar un sidebar diferente para cada página o categoría de mi wordpress. Lo he escrito así: <?php if (is_frontpage) get_sidebar();?> <?php if ...
  #1 (permalink)  
Antiguo 10/09/2007, 05:35
 
Fecha de Ingreso: julio-2007
Mensajes: 11
Antigüedad: 16 años, 9 meses
Puntos: 0
Sidebars dinámicos

Buenas, me gustaría mostrar un sidebar diferente para cada página o categoría de mi wordpress. Lo he escrito así:
<?php if (is_frontpage) get_sidebar();?>
<?php if (is_page(6)) include (TEMPLATEPATH . '/web.php');?>
El problema es que de esta manera me carga los dos sidebars. Como puedo escribirlo para que sólo me cargue uno?
Gracias
  #2 (permalink)  
Antiguo 10/09/2007, 06:12
Avatar de _minimalnet_  
Fecha de Ingreso: diciembre-2006
Ubicación: Valencia
Mensajes: 302
Antigüedad: 17 años, 4 meses
Puntos: 6
Re: Sidebars dinámicos

Yo, como soy medio zoquete y lo hago todo en plan amateur xD, (no sé usar lo de "or", "and"), hago lo siguiente. En la plantilla sidebar.php pongo todo esto y me va de lujo. Si quieres echa un vistazo a mi blog y lo ves www.minimalnet.org:

para el sidebar de un post:
<?php if (is_single()) { ?>
todo lo que quiero que aparezca
<?php } ?>


para el sidebar de la portada:
<?php if (is_home()) { ?>
todo lo que quiero que aparezca
<?php } ?>


para el sidebar de una página:
<?php if (is_page()) { ?>
todo lo que quiero que aparezca
<?php } ?>


para el sidebar de los resultados de una búsqueda:
<?php if (is_search()) { ?>
todo lo que quiero que aparezca
<?php } ?>


para el sidebar de los archivos:
<?php if (is_archive()) { ?>
todo lo que quiero que aparezca
<?php } ?>


para el sidebar de la página de error
<?php if (is_404()) { ?>
todo lo que quiero que aparezca
<?php } ?>
__________________
mi blog --> www.minimalnet.org
  #3 (permalink)  
Antiguo 10/09/2007, 06:24
 
Fecha de Ingreso: julio-2007
Mensajes: 11
Antigüedad: 16 años, 9 meses
Puntos: 0
Re: Sidebars dinámicos

Hostia yo pensaba que había que ponerlo en el index.php.
Voy a probarlo como dices.
Muchas gracias.
Por cierto, está genial tu web.
Nosotros también publicamos música electrónica, llevamos 4 referencias, échales un vistazo, o mejor dicho, un oidazo:
http://www.influxmedia.es/?page_id=8.
Podríamos colaborar.
Hasta pronto.
  #4 (permalink)  
Antiguo 10/09/2007, 06:29
Avatar de _minimalnet_  
Fecha de Ingreso: diciembre-2006
Ubicación: Valencia
Mensajes: 302
Antigüedad: 17 años, 4 meses
Puntos: 6
Re: Sidebars dinámicos

Ahhh mira que bien, pues voy a mirar a ver, ¿que es un netlabel español?, no lo conocía aún.

De la manera en la que lo hacías lo que haces es llamar en el indice a varias sidebars, y con la que he comentado yo sólo a 1 que se muestra de manera diferente según la página que muestre.

Aquí aún hay más tags condicionales, aunque yo los uso ya casi todos. http://codex.wordpress.org/Conditional_Tags
__________________
mi blog --> www.minimalnet.org
  #5 (permalink)  
Antiguo 10/09/2007, 06:40
 
Fecha de Ingreso: julio-2007
Mensajes: 11
Antigüedad: 16 años, 9 meses
Puntos: 0
Re: Sidebars dinámicos

Sí, somos de Canarias.
Oye no me sale, serías tan amable de escribirme una sentencia completa?
Gracias
  #6 (permalink)  
Antiguo 10/09/2007, 06:52
 
Fecha de Ingreso: julio-2007
Mensajes: 11
Antigüedad: 16 años, 9 meses
Puntos: 0
Re: Sidebars dinámicos

De esta manera también me carga los dos
  #7 (permalink)  
Antiguo 10/09/2007, 07:06
Avatar de _minimalnet_  
Fecha de Ingreso: diciembre-2006
Ubicación: Valencia
Mensajes: 302
Antigüedad: 17 años, 4 meses
Puntos: 6
Re: Sidebars dinámicos

Como mi plantilla es enorme he simplificado lo que hay en la sidebar y he añadido espacios para que lo veas más claro.



/*================================= Esto que viene aquí es lo que venía por defecto en mi plantilla ================================= */

<hr />
<div id="sidebar-main" class="secondary">


<?php /* Menu for subpages of current page */
global $notfound;
if (is_page() and ($notfound != '1')) {
$current_page = $post->ID;
while($current_page) {
$page_query = $wpdb->get_row("SELECT ID, post_title, post_status, post_parent FROM $wpdb->posts WHERE ID = '$current_page'");
$current_page = $page_query->post_parent;
}
$parent_id = $page_query->ID;
$parent_title = $page_query->post_title;

$page_menu = wp_list_pages('echo=0&sort_column=menu_order&title _li=&child_of='. $parent_id);
if ($page_menu) {
?>

<div class="sb-pagemenu">
<h2><?php echo $parent_title; ?> <?php _e('Subpages','k2_domain'); ?></h2>

<ul>
<?php echo $page_menu; ?>
</ul>

<?php if ($parent_id != $post->ID) { ?>
<a href="<?php echo get_permalink($parent_id); ?>"><?php printf(__('Back to %s','k2_domain'), $parent_title ) ?></a>
<?php } ?>
</div>
<?php } } ?>


<?php if (is_attachment()) { ?>
<div class="sb-pagemenu">
<a href="<?php echo get_permalink($post->post_parent); ?>" rev="attachment"><?php printf(__('Back to \'%s\'','k2_domain'), get_the_title($post->post_parent) ) ?></a>
</div>
<?php } ?>

<?php /* If there is a custom about message, use it on the frontpage. */ $k2about = get_option('k2aboutblurp'); if ((is_home() and $k2about != '') or !is_home() and !is_page() and !is_single() or is_paged()) { ?>

<div class="sb-about">
<h2><?php _e('About','k2_domain'); ?></h2>

<?php /* Frontpage */ if (is_home() and !is_paged()) { ?>
<p><?php echo stripslashes($k2about); ?></p>

<?php /* Category Archive */ } elseif (is_category()) { ?>
<p><?php printf(__('You are currently browsing the %1$s weblog archives for the %2$s category.','k2_domain'), '<a href="' . get_settings('siteurl') .'">' . get_bloginfo('name') . '</a>', single_cat_title('', false) ) ?></p>

<?php /* Day Archive */ } elseif (is_day()) { ?>
<p><?php printf(__('You are currently browsing the %1$s weblog archives for the day %2$s.','k2_domain'), '<a href="' . get_settings('siteurl') .'">' . get_bloginfo('name') . '</a>', get_the_time(__('l, F jS, Y','k2_domain'))) ?></p>

<?php /* Monthly Archive */ } elseif (is_month()) { ?>
<p><?php printf(__('You are currently browsing the %1$s weblog archives for the month %2$s.','k2_domain'), '<a href="'.get_settings('siteurl').'">'.get_bloginfo( 'name').'</a>', get_the_time(__('F, Y','k2_domain'))) ?></p>

<?php /* Yearly Archive */ } elseif (is_year()) { ?>
<p><?php printf(__('You are currently browsing the %1$s weblog archives for the year %2$s.','k2_domain'), '<a href="'.get_settings('siteurl').'">'.get_bloginfo( 'name').'</a>', get_the_time('Y')) ?></p>

<?php /* Search */ } elseif (is_search()) { ?>
<p><?php printf(__('You have searched the %1$s weblog archives for \'<strong>%2$s</strong>\'.','k2_domain'),'<a href="'.get_settings('siteurl').'">'.get_bloginfo( 'name').'</a>', wp_specialchars($s)) ?></p>

<?php /* Author Archive */ } elseif (is_author()) { ?>
<p><?php printf(__('Archive for <strong>%s</strong>.','k2_domain'), get_the_author()) ?></p>
<p><?php the_author_description(); ?></p>

<?php } elseif (function_exists('is_tag') and is_tag()) { ?>
<p><?php printf(__('You are currently browsing the %1$s weblog archives for \'%2$s\' tag.','k2_domain'), '<a href="'.get_settings('siteurl').'">'.get_bloginfo( 'name').'</a>', get_query_var('tag') ) ?></p>

<?php /* Paged Archive */ } elseif (is_paged()) { ?>
<p><?php printf(__('You are currently browsing the %s weblog archives.','k2_domain'), '<a href="'.get_settings('siteurl').'">'.get_bloginfo( 'name').'</a>') ?></p>

<?php /* Permalink */ } elseif (is_single()) { ?>
<p><?php next_post('%', __('Next: ','k2_domain'),'yes') ?><br/>
<?php previous_post('%', __('Previous: ','k2_domain') ,'yes') ?></p>

<?php } ?>

<?php if (!is_home() and !is_paged() and !in_category($k2asidescategory) or is_day() or is_month() or is_year() or is_author() or is_search() or (function_exists('is_tag') and is_tag())) { ?>
<?php } ?>
</div>

<?php } ?>

/*================================= Hasta aquí es lo que venía por defecto, ahora añado lo de los condicionales ================================= */













<?php if (is_single()) { ?>


<h2>About this <span class="a">entry</span></h2>
This entry was posted <?php /* $entry_datetime = abs(strtotime($post->post_date) - (60*120)); echo time_since($entry_datetime); echo ' ago'; */ ?> on <?php the_time('l, F jS, Y') ?> at <?php the_time() ?> and is filed under <?php the_category(', ') ?> category.
<br><br>
You can follow any responses to this entry through the <a href="<?php echo get_permalink(); ?>feed/" target="_blank">RSS 2.0</a> feed.

<?php } ?>


































<?php if (is_home()) { ?>

<h2>About <span class="a">MinimalNet</span></h2>
A netlabel is a online label that distributes its music by Internet in digital format and in a <u>free way</u> and MinimalNet is a personal blog where I select the best netlabel dance releases.

<br>

<h2>Most Commented <span class="a">Posts</span></h2>
<ul><?php get_mostcommented(); ?></ul>

<br>
<h2>Blog <span class="a">Stats</span></h2>
<?php GeneralStatsComplete(); ?>

<?php } ?>














<?php if (is_page()) { ?>

<div id="height10pxall"></div>

<div id="search"><h2><?php _e('Search','k2_domain'); ?></h2><?php include (TEMPLATEPATH . '/searchform.php'); ?></div>

<br>

<h2>About <span class="a">MinimalNet</span></h2>
A netlabel is a online label that distributes its music by Internet in digital format and in a <u>free way</u> and MinimalNet is a personal blog where I select the best netlabel dance releases.

<br>

<div id="recent_comment"><h2>Recent <span class="a">Comments</span></h2> <ul><?php get_recent_comments(); ?></ul></div>

<?php } ?>


















<?php if (is_search()) { ?>

<div id="height10pxall"></div>

<div id="search"><h2><?php _e('Search','k2_domain'); ?></h2><?php include (TEMPLATEPATH . '/searchform.php'); ?></div>

<br>

<h2>About <span class="a">MinimalNet</span></h2>
A netlabel is a online label that distributes its music by Internet in digital format and in a <u>free way</u> and MinimalNet is a personal blog where I select the best netlabel dance releases.
<br><br>
You can add this <a href="http://feeds.feedburner.com/minimalnet" target="_blank">feed</a> to your rss reader or subscribe to the <a href="http://www.feedburner.com/fb/a/emailverifySubmit?feedId=1097042&loc=en_US" target="_blank">newsletter</a> and receive the news daily in your email.
<br><br>
For more info read the <a href="http://www.minimalnet.org/faq">FAQ</a> section.


<h2>Recent <span class="a">Post</span></h2>
<ul><?php recent_posts(); ?></ul>

<br>

<div id="recent_comment"><h2>Recent <span class="a">Comments</span></h2> <ul><?php get_recent_comments(); ?></ul></div>

<br>

<h2>Archives <span class="a">Last 8 months</span></h2>
<ul>
<?php wp_get_archives('type=monthly&limit=8'); ?>
</ul>

<?php } ?>



















<?php if (is_archive()) { ?>

<div id="height10pxall"></div>

<div id="search"><h2><?php _e('Search','k2_domain'); ?></h2><?php include (TEMPLATEPATH . '/searchform.php'); ?></div>

<br>

<h2>About <span class="a">MinimalNet</span></h2>
A netlabel is a online label that distributes its music by Internet in digital format and in a <u>free way</u> and MinimalNet is a personal blog where I select the best netlabel dance releases.
<br><br>
You can add this <a href="http://feeds.feedburner.com/minimalnet" target="_blank">feed</a> to your rss reader or subscribe to the <a href="http://www.feedburner.com/fb/a/emailverifySubmit?feedId=1097042&loc=en_US" target="_blank">newsletter</a> and receive the news daily in your email.
<br><br>
For more info read the <a href="http://www.minimalnet.org/faq">FAQ</a> section.

<br>

<h2>Recent <span class="a">Post</span></h2>
<ul><?php recent_posts(); ?></ul>

<br>

<div id="recent_comment"><h2>Recent <span class="a">Comments</span></h2> <ul><?php get_recent_comments(); ?></ul></div>

<br>

<h2>Archives <span class="a">Last 8 months</span></h2>
<ul>
<?php wp_get_archives('type=monthly&limit=8'); ?>
</ul>

<?php } ?>


















<?php if (is_404()) { ?>

<img src="http://www.minimalnet.org/wp-content/themes/jstheme/images/ICO_FEED2.gif" hspace="0" vspace="0" border="0" align="absmiddle" title="">&nbsp;&nbsp;MinimalNet has changed the feed url, update your rss to this new link <a href="http://feeds.feedburner.com/minimalnet" target="_blank">http://feeds.feedburner.com/minimalnet</a>

<div id="height10pxall"></div>

<div id="search"><h2><?php _e('Search','k2_domain'); ?></h2><?php include (TEMPLATEPATH . '/searchform.php'); ?></div>

<?php } ?>






/*================================= Esto que viene ahora como está fuera de los "if" sale en todas las sidebar ================================= */








<br>

<div id="meta_rss">
<span class="s1">RSS: </span>
<span class="s1">
<a href="http://feeds.feedburner.com/minimalnet" target="_blank">Entries</a>
<a href="http://feeds.feedburner.com/minimalnet-comments" target="_blank">Comments</a>
<a href="http://www.feedburner.com/fb/a/emailverifySubmit?feedId=1097042&loc=en_US" target="_blank">Newsletter</a>
</span>
</div>



</div> <!-- #sidebar-main -->

<div class="clear"></div>
__________________
mi blog --> www.minimalnet.org

Última edición por _minimalnet_; 10/09/2007 a las 07:15
  #8 (permalink)  
Antiguo 10/09/2007, 07:07
Avatar de _minimalnet_  
Fecha de Ingreso: diciembre-2006
Ubicación: Valencia
Mensajes: 302
Antigüedad: 17 años, 4 meses
Puntos: 6
Re: Sidebars dinámicos

A mi hay un trozo de código, el de los post recientes, que si lo muestro 2 veces, en single y en home, por ejemplo, hace que me salgan varias sidebar, por lo que finalmente tras darle muchas vueltas decidí mostrarlo sólo en el índice.
__________________
mi blog --> www.minimalnet.org
  #9 (permalink)  
Antiguo 10/09/2007, 07:24
Avatar de _minimalnet_  
Fecha de Ingreso: diciembre-2006
Ubicación: Valencia
Mensajes: 302
Antigüedad: 17 años, 4 meses
Puntos: 6
Re: Sidebars dinámicos

Quitando el tochazo de arriba, a ver si se ve más claro, si tu sidebar se llama de otra manera no tendrás q poner "sidebar-main" sino el nombre que sea.












<div id="sidebar-main" class="secondary"> /*================================= COMIENZO DEL SIDEBAR ================================= */



<?php if (is_single()) { ?>
Esto es un post, puedes comentar y tal y tal
<?php } ?>


<?php if (is_home()) { ?>
Esta es la parte del sidebar más grande porque pertenece a la portada
<?php } ?>




<?php if (is_page()) { ?>
Esto sale en la página de los links, por ejemplo.
<?php } ?>




/*================================= Esto que viene ahora como está fuera de los "if" sale en todas las sidebar ================================= */


<br>

<div id="meta_rss">
<span class="s1">RSS: </span>
<span class="s1">
<a href="http://feeds.feedburner.com/minimalnet" target="_blank">Entries</a>
<a href="http://feeds.feedburner.com/minimalnet-comments" target="_blank">Comments</a>
<a href="http://www.feedburner.com/fb/a/emailverifySubmit?feedId=1097042&loc=en_US" target="_blank">Newsletter</a>
</span>
</div>


</div> /*================================= FINAL DEL SIDEBAR ================================= */
__________________
mi blog --> www.minimalnet.org
  #10 (permalink)  
Antiguo 10/09/2007, 07:27
Avatar de _minimalnet_  
Fecha de Ingreso: diciembre-2006
Ubicación: Valencia
Mensajes: 302
Antigüedad: 17 años, 4 meses
Puntos: 6
Re: Sidebars dinámicos

Por otra parte en el "index.php" deberías de poner sólo

<?php get_sidebar(); ?>

Porque sinó sigues llamando a varias sidebars allí.
__________________
mi blog --> www.minimalnet.org
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:16.