Mostrando entradas con una etiqueta de “funciones” en la parte superior usando PHP en Wordpress

StackOverflow https://stackoverflow.com/questions/3486831

  •  28-09-2019
  •  | 
  •  

Pregunta

Tengo una página en Wordpress que muestra los mensajes con una categoría de "diario" solamente. Ahora, los mensajes están clasificadas por orden descendente (creo que, si ese es el valor predeterminado), de tal manera que la más reciente es en la parte superior.

Este es el código que tengo:

<?php $my_query = new WP_Query('category_name=newspaper&posts_per_page=-1'); ?>

<?php if (have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div class="post">
<!--<h3><?php the_title(); ?></h3>-->
<?php the_content('Read the rest of this entry &raquo;'); ?>
<div class="clear"></div>
</div>
<?php endwhile; endif;?>

Me preguntaba si es posible mostrar mensajes con una etiqueta de "funciones" en la parte superior, mientras que todos los demás puestos sin una etiqueta ofrecida después.

Gracias! Amit

¿Fue útil?

Solución

Está bien esto es lo que hice temporalmente. No me baso en una etiqueta funciones , sino más bien en una categoría de periódico ofrecido. No es exactamente como yo quería que fuera, pero esto va a hacer por ahora:

<?php $my_query = new WP_Query('category_name=newspaper&posts_per_page=-1'); ?>
<?php $my_featured = new WP_Query('category_name=featured-newspaper&posts_per_page=-1'); ?>

<!-- featured posts -->
<?php if (have_posts()) : while ($my_featured->have_posts()) : $my_featured->the_post(); ?>
<div class="post">
    <!--<h3><?php the_title(); ?></h3>-->
    <?php the_content('Read the rest of this entry &raquo;'); ?>
    <div class="clear"></div>
</div>
<?php endwhile; endif;?>
<!-- /end featured -->


<?php if (have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div class="post">
    <!--<h3><?php the_title(); ?></h3>-->
    <?php the_content('Read the rest of this entry &raquo;'); ?>
    <div class="clear"></div>
</div>
<?php endwhile; endif;?>

Como dije, no es la manera más limpia de hacer las cosas, pero funciona. Si usted tiene otras sugerencias, soy todo oídos:)

Gracias! Amit

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top