Visualizzazione post con un tag “In primo piano” nella parte superiore utilizzando PHP in Wordpress

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

  •  28-09-2019
  •  | 
  •  

Domanda

Ho una pagina in Wordpress che visualizza i messaggi con una categoria di "giornale" solo. Ora, i posti sono ordinate per ordine decrescente (penso, se questo è il default), in modo tale che il più recente è in cima.

Questo è il codice che ho:

<?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;?>

mi chiedevo se è possibile mostrare i messaggi con un tag "In primo piano" nella parte superiore, mentre tutti gli altri messaggi, senza un tag funzionalità dopo.

Grazie! Amit

È stato utile?

Soluzione

Va bene questo è quello che ho fatto temporaneo. Non ho contare su un tag caratterizzato , ma piuttosto su una categoria-giornale optional. Non è esattamente come avrei voluto che fosse, ma questo farà per ora:

<?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;?>

Come ho detto, non è il modo più pulito di fare le cose, ma funziona. Se avete altri suggerimenti, io sono tutte le orecchie:)

Grazie! Amit

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top