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

Categorias Wordpress

Estas en el tema de Categorias Wordpress en el foro de WordPress en Foros del Web. Hola Amigos!. Tengo este codigo para el archivo category.php: Código PHP: <?php get_header ();  ?> <div id="border-center-top"></div>   <div id="content">   <div id="center">   <div id="container">   <div id="center-title"> <h3>Noticias:  <?php  echo  single_cat_title ();  ?> ...
  #1 (permalink)  
Antiguo 08/09/2010, 12:32
 
Fecha de Ingreso: febrero-2009
Mensajes: 176
Antigüedad: 15 años, 2 meses
Puntos: 1
Categorias Wordpress

Hola Amigos!.
Tengo este codigo para el archivo category.php:

Código PHP:
<?php get_header(); ?>
<div id="border-center-top"></div>
  <div id="content">
  <div id="center">
  <div id="container">
  <div id="center-title">
<h3>Noticias: <?php echo single_cat_title(); ?></h3>
</div>
  <div id="center-left-1">        
        <?php if (have_posts()) : while(have_posts()) : $i++; if(($i 2) == 0) : $wp_query->next_post(); else : the_post(); ?>
  <div class="post" id="post-<?php the_ID(); ?>"> 
  <h1><a href="<?php the_permalink() ?>" rel="bookmark">
  <?php the_title(); ?>
  </a></h1>
  <div class="date">
  <?php the_category(', '?><?php the_time(' | j F Y'); ?>
  </div>
  <a href="<?php the_permalink() ?>" rel="bookmark">
  <?php the_post_thumbnail(array( 120,120 ), array('class' => 'imagen_post')) ?>
  </a>
  <?php the_excerpt(); ?>
  <div class="coments-home">
  <?php comments_popup_link('0 comentarios &raquo;''1 comentario &raquo;''% comentarios &raquo;'); ?>
  </div>
  </div>
<?php endif; endwhile; else: ?>
<div>Alternate content</div>
<?php endif; ?>
</div>
<div id="center-left-2">
<?php $i 0rewind_posts(); ?>
<?php 
if (have_posts()) : while(have_posts()) : $i++; if(($i 2) !== 0) : $wp_query->next_post(); else : the_post(); ?>
  <div class="post" id="post-<?php the_ID(); ?>">
  <h1><a href="<?php the_permalink() ?>" rel="bookmark">
  <?php the_title(); ?>
  </a></h1>
  <div class="date">
  <?php the_category(', '?><?php the_time(' | j F Y'); ?>
  </div>
  <a href="<?php the_permalink() ?>" rel="bookmark">
  <?php the_post_thumbnail(array( 120,120 ), array('class' => 'imagen_post')) ?>
  </a>
  <?php the_excerpt(); ?>
  <div class="coments-home">
  <?php comments_popup_link('0 comentarios &raquo;''1 comentario &raquo;''% comentarios &raquo;'); ?>
  </div>
  </div>
<?php endif; endwhile; else: ?>
<div>Alternate content</div>
<?php endif; ?>
</div>
  <div id="navigation">
   <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } 
            else { 
?>
            <div class="right"><?php next_posts_link('Next Page &raquo;'?></div>
            <div class="left"><?php previous_posts_link('&laquo; Previous Page'?></div>
            <?php ?>
  </div>
</div>
</div>
<?php include (TEMPLATEPATH '/sidebar1.php'); ?>
<?php 
include (TEMPLATEPATH '/sidebar2.php'); ?>
<?php 
include (TEMPLATEPATH '/sidebar3.php'); ?>
<?php 
include (TEMPLATEPATH '/forms.php'); ?>
</div>
<?php get_footer(); ?>
Y le quiero agregar este:

Código PHP:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <?php 
        $id 
get_cat_id('job');
        
$in_subcategory false;
        foreach( 
explode"/"get_category_children$id ) ) as $child_category ) {
        if(
in_category($child_category))$in_subcategory true;
        }        
        if (
$in_subcategory || in_category$id )) {?>
        <div class="the_job">
            <div class="span-6">
                <h3 class="jobtitle"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
                <span class="jobcompany">
                    Company: <strong><?php $jobcompany get_post_custom_values("company"); echo $jobcompany[0]; ?></strong>
                </span>
                <span class="jobaddress">
                    Where: <strong><?php $jobaddress get_post_custom_values("address"); echo $jobaddress[0]; ?></strong>
                </span>
                <p class="jobinfo">
                    Submitted the: <strong><?php the_time('jS F Y'?> <?php // comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></strong>
                </p>
            </div>
            <div class="span-6 last">
                <div class="jobentry entry">
                    <?php the_content('Read more &raquo;'); ?>
                    <?php trackback_rdf(); ?> 
                </div>
            </div>
        </div>
Quiero agregarlo para que cuando una entrada sea etiquetada en la categoria "Job" la muestre de la forma indicada en este ultimo codigo, y si no pertenece a esta categoria la muestre de forma normal, es decir, como el primer codigo.

Como puedo agrupar estos dos codigos?
Gracias!!!
  #2 (permalink)  
Antiguo 08/09/2010, 13:13
 
Fecha de Ingreso: abril-2003
Mensajes: 1.129
Antigüedad: 21 años
Puntos: 34
Respuesta: Categorias Wordpress

Imagino que sabes de código, así que te tiro la idea, y seguro te animás a armarlo, pero dentro del "bucle" deberías poner mas o menos algo asi.

Un if en donde levantes el nombre de la categoría y pones if ($cat_id =="job") { entonces tu codigo } else { el otro codigo }

Ojo que no se cuando levantas la categoría, si te devolverá el nombre de la misma, o un número.

Espero se entienda la idea.
__________________
elGastronomo
  #3 (permalink)  
Antiguo 08/09/2010, 13:27
 
Fecha de Ingreso: febrero-2009
Mensajes: 176
Antigüedad: 15 años, 2 meses
Puntos: 1
Respuesta: Categorias Wordpress

Hola American2010!
Gracias por responder.

No la tengo muy clara con el codigo a decir verdad jaja.
Como ya tengo un "else" en mi actual codigo, esto me confunde.

Donde deberia colocar tu "if"?
Abrazo!.
  #4 (permalink)  
Antiguo 08/09/2010, 14:45
 
Fecha de Ingreso: abril-2003
Mensajes: 1.129
Antigüedad: 21 años
Puntos: 34
Respuesta: Categorias Wordpress

Creo que por acá

Código PHP:
 <?php if (have_posts()) : while(have_posts()) : $i++; if(($i 2) == 0) : $wp_query->next_post(); else : the_post(); ?>


ACA buscar como levantar el nombre de la Cat. y poner el if.

Entonces si es la que buscas { tu codigo } sino

{ seguis con lo que ves en tu codigo  <div class="post" id="post-<?php the_ID(); ?>">  

.....}

al cerrar ese else entonces dejas la linea <?php endif; endwhile; else: ?>
__________________
elGastronomo
  #5 (permalink)  
Antiguo 08/09/2010, 15:00
 
Fecha de Ingreso: febrero-2009
Mensajes: 176
Antigüedad: 15 años, 2 meses
Puntos: 1
Respuesta: Categorias Wordpress

Me da errores de este tipo:
Parse error: syntax error, unexpected T_ENDIF in /home/libertad/public_html/wp-content/themes/theme_libertad_wp/category.php on line 75

Pruebo poner y sacar if, else... pero no me funciona...
:S
  #6 (permalink)  
Antiguo 08/09/2010, 15:10
 
Fecha de Ingreso: febrero-2009
Mensajes: 176
Antigüedad: 15 años, 2 meses
Puntos: 1
Respuesta: Categorias Wordpress

Asi me quedo el codigo:

Código PHP:
<?php get_header(); ?>
<div id="border-center-top"></div>
  <div id="content">
  <div id="center">
  <div id="container">
  <div id="center-title">
<h3>Noticias: <?php echo single_cat_title(); ?></h3>
</div>
  <div id="center-left-1">
                
        <?php if (have_posts()) : while(have_posts()) : $i++; if(($i 2) == 0) : $wp_query->next_post(); else : the_post(); ?>
        
<?php if (is_category('job')) { ?>
<?php 
        $id 
get_cat_id('job');
        
$in_subcategory false;
        foreach( 
explode"/"get_category_children$id ) ) as $child_category ) {
        if(
in_category($child_category))$in_subcategory true;
        }
        
        
        
        if (
$in_subcategory || in_category$id )) {?>
        
        <div class="the_job">
            <div class="span-6">
                <h3 class="jobtitle"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
            
                <span class="jobcompany">
                    Company: <strong><?php $jobcompany get_post_custom_values("company"); echo $jobcompany[0]; ?></strong>
                </span>
            
                <span class="jobaddress">
                    Where: <strong><?php $jobaddress get_post_custom_values("address"); echo $jobaddress[0]; ?></strong>
                </span>
            
                <p class="jobinfo">
                    Submitted the: <strong><?php the_time('jS F Y'?> <?php // comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></strong>
                </p>
            
            </div>
        
            <div class="span-6 last">
                <div class="jobentry entry">

                    <?php the_content('Read more &raquo;'); ?>
                    <?php trackback_rdf(); ?> 

                </div>
            </div>
        </div>
<?php ?>
<?php 
else: ?>
  
  <div class="post" id="post-<?php the_ID(); ?>"> 
  
  <h1><a href="<?php the_permalink() ?>" rel="bookmark">
  <?php the_title(); ?>
  </a></h1>
  <div class="date">
  <?php the_category(', '?><?php the_time(' | j F Y'); ?>
  </div>
  
  <a href="<?php the_permalink() ?>" rel="bookmark">
  <?php the_post_thumbnail(array( 120,120 ), array('class' => 'imagen_post')) ?>
  </a>

  <?php the_excerpt(); ?>
  <div class="coments-home">
  <?php comments_popup_link('0 comentarios &raquo;''1 comentario &raquo;''% comentarios &raquo;'); ?>
  </div>
  </div>
  <!-- TERMINA EL POST -->
  
<?php endif; endwhile; else: ?>
<div>Alternate content</div>
<?php endif; ?>
<?php 
endif; ?>
</div>
<div id="center-left-2">
<?php $i 0rewind_posts(); ?>

<?php if (have_posts()) : while(have_posts()) : $i++; if(($i 2) !== 0) : $wp_query->next_post(); else : the_post(); ?>

  <div class="post" id="post-<?php the_ID(); ?>">
  <h1><a href="<?php the_permalink() ?>" rel="bookmark">
  <?php the_title(); ?>
  </a></h1>
  <div class="date">
  <?php the_category(', '?><?php the_time(' | j F Y'); ?>
  </div>
  
  <a href="<?php the_permalink() ?>" rel="bookmark">
  <?php the_post_thumbnail(array( 120,120 ), array('class' => 'imagen_post')) ?>
  </a>
  
  <?php the_excerpt(); ?>
  <div class="coments-home">
  <?php comments_popup_link('0 comentarios &raquo;''1 comentario &raquo;''% comentarios &raquo;'); ?>
  </div>
  </div>
  
<?php endif; endwhile; else: ?>
<div>Alternate content</div>
<?php endif; ?>
</div>

  <div id="navigation">
   <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } 
            else { 
?>
            <div class="right"><?php next_posts_link('Next Page &raquo;'?></div>
            <div class="left"><?php previous_posts_link('&laquo; Previous Page'?></div>
            <?php ?>
  </div>
  
</div>
</div>

<?php include (TEMPLATEPATH '/sidebar1.php'); ?>
<?php 
include (TEMPLATEPATH '/sidebar2.php'); ?>
<?php 
include (TEMPLATEPATH '/sidebar3.php'); ?>
<?php 
include (TEMPLATEPATH '/forms.php'); ?>
</div>
<?php get_footer(); ?>
Y me da este error:
Parse error: syntax error, unexpected T_ELSE in /home/libertad/public_html/wp-content/themes/theme_libertad_wp/category.php on line 53
  #7 (permalink)  
Antiguo 08/09/2010, 15:38
 
Fecha de Ingreso: abril-2003
Mensajes: 1.129
Antigüedad: 21 años
Puntos: 34
Respuesta: Categorias Wordpress

Dejame el nombre del Theme que estás usando, mañana si puedo reviso.

Igual hay algo que no entiendo. Cuando entras a Category, no se va ya sabiendo que uno va a ver X categoría? Bueno, dejame el link al Theme que usas y mañana pruebo, que de paso hago un testeo que me interesa...

Saludos.
__________________
elGastronomo
  #8 (permalink)  
Antiguo 08/09/2010, 16:07
 
Fecha de Ingreso: febrero-2009
Mensajes: 176
Antigüedad: 15 años, 2 meses
Puntos: 1
Respuesta: Categorias Wordpress

El theme lo hice yo te mando un mensaje privado para que puedas descargarlo asi no lo expongo en publico.
Gracias!.
  #9 (permalink)  
Antiguo 09/09/2010, 10:43
 
Fecha de Ingreso: abril-2003
Mensajes: 1.129
Antigüedad: 21 años
Puntos: 34
Respuesta: Categorias Wordpress

La idea sería esta, pero a ver si te podes pasar por el Foro de PHP porque no termino de entender donde está el error, entre PHP y el codigo de WP algun if o while esta molestando y no se como resolverlo...

Código PHP:
<?php get_header(); ?>
<div id="border-center-top"></div>
  <div id="content">
  <div id="center">
  <div id="container">
  <div id="center-title">
<h3>Noticias: <?php $id get_cat_id('Job'); echo single_cat_title(); ?></h3>
</div>

<?php if ($id=="10") { //Cambiar ese 10 por el ID de la categoría Job en tu WP // ?>



<div id="center-left-1">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <?php 
        $id 
get_cat_id('job');
        
$in_subcategory false;
        foreach( 
explode"/"get_category_children$id ) ) as $child_category ) {
        if(
in_category($child_category))$in_subcategory true;
        }        
        if (
$in_subcategory || in_category$id )) {?>
        <div class="the_job">
            <div class="span-6">
                <h3 class="jobtitle"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
                <span class="jobcompany">
                    Company: <strong><?php $jobcompany get_post_custom_values("company"); echo $jobcompany[0]; ?></strong>
                </span>
                <span class="jobaddress">
                    Where: <strong><?php $jobaddress get_post_custom_values("address"); echo $jobaddress[0]; ?></strong>
                </span>
                <p class="jobinfo">
                    Submitted the: <strong><?php the_time('jS F Y'?> <?php // comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></strong>
                </p>
            </div>
            <div class="span-6 last">
                <div class="jobentry entry">
                    <?php the_content('Read more &raquo;'); ?>
                    <?php trackback_rdf(); ?> 
                </div>
            </div>
        </div>
<?php ?>

</div>

<?php } else { ?>

  <div id="center-left-1">
  <?php if (have_posts()) : while(have_posts()) : $i++; if(($i 2) == 0) : $wp_query->next_post(); else : the_post(); ?>
  <div class="post" id="post-<?php the_ID(); ?>"> 
  <h1><a href="<?php the_permalink() ?>" rel="bookmark">
  <?php the_title(); ?>
  </a></h1>
  <div class="date">
  <?php the_category(', '?><?php the_time(' | j F Y'); ?>
  </div>
  <a href="<?php the_permalink() ?>" rel="bookmark">
  <?php the_post_thumbnail(array( 120,120 ), array('class' => 'imagen_post')) ?>
  </a>
  <?php the_excerpt(); ?>
  <div class="coments-home">
  <?php comments_popup_link('0 comentarios &raquo;''1 comentario &raquo;''% comentarios &raquo;'); ?>
  </div>
  </div>
<?php endif; endwhile; else: ?>
<div>Alternate content</div>
<?php endif; ?>
</div>
<div id="center-left-2">
<?php $i 0rewind_posts(); ?>
<?php 
if (have_posts()) : while(have_posts()) : $i++; if(($i 2) !== 0) : $wp_query->next_post(); else : the_post(); ?>
  <div class="post" id="post-<?php the_ID(); ?>">
  <h1><a href="<?php the_permalink() ?>" rel="bookmark">
  <?php the_title(); ?>
  </a></h1>
  <div class="date">
  <?php the_category(', '?><?php the_time(' | j F Y'); ?>
  </div>
  <a href="<?php the_permalink() ?>" rel="bookmark">
  <?php the_post_thumbnail(array( 120,120 ), array('class' => 'imagen_post')) ?>
  </a>
  <?php the_excerpt(); ?>
  <div class="coments-home">
  <?php comments_popup_link('0 comentarios &raquo;''1 comentario &raquo;''% comentarios &raquo;'); ?>
  </div>
  </div>
<?php endif; endwhile; else: ?>
<div>Alternate content</div>
<?php endif; ?>
</div>

<?php ?>

  <div id="navigation">
   <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } 
            else { 
?>
            <div class="right"><?php next_posts_link('Next Page &raquo;'?></div>
            <div class="left"><?php previous_posts_link('&laquo; Previous Page'?></div>
            <?php ?>
  </div>
</div>
</div>
<?php include (TEMPLATEPATH '/sidebar1.php'); ?>
<?php 
include (TEMPLATEPATH '/sidebar2.php'); ?>
<?php 
include (TEMPLATEPATH '/sidebar3.php'); ?>
<?php 
include (TEMPLATEPATH '/forms.php'); ?>
</div>
<?php get_footer(); ?>
Los errores ya están en tu segundo código, que no tiene cerrados los if. No se como se cierran, ese formato de if, while y demás con los : nunca los entendí.
__________________
elGastronomo
  #10 (permalink)  
Antiguo 15/09/2010, 13:50
 
Fecha de Ingreso: febrero-2009
Mensajes: 176
Antigüedad: 15 años, 2 meses
Puntos: 1
Respuesta: Categorias Wordpress

Ya lo solucione agregando un archivo exclusivo para esa categoria.
Lo nombre category-14.php.
Y problema resuelto.
Gracias!.
  #11 (permalink)  
Antiguo 15/09/2010, 14:54
 
Fecha de Ingreso: abril-2003
Mensajes: 1.129
Antigüedad: 21 años
Puntos: 34
Respuesta: Categorias Wordpress

Ese truco no lo conocía, voy a experimentar con esas cosas, suenan interesantes para resolver varios problemas que uno puede tener.

Gracias por comentar como lo soucionaste.
__________________
elGastronomo

Etiquetas: categorias
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 04:40.