عرض المنشورات مع علامة "مميزة" في الأعلى باستخدام PHP في WordPress
سؤال
لدي صفحة في WordPress تعرض المنشورات مع فئة من "الصحف" فقط. الآن ، يتم طلب المنشورات عن طريق الترتيب المتنازع عليه (على ما أعتقد ، إذا كان هذا هو الافتراضي) ، فإن الأحدث هو في الأعلى.
هذا هو الرمز الذي لدي:
<?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 »'); ?>
<div class="clear"></div>
</div>
<?php endwhile; endif;?>
كنت أتساءل عما إذا كان من الممكن عرض المنشورات مع علامة "مميزة" في الأعلى ، في حين أن جميع المنشورات الأخرى بدون علامة مميزة بعد ذلك.
شكرًا! أميت
المحلول
حسنًا ، هذا ما فعلته مؤقتًا. لم أعتمد على مميز بطاقة شعار, ، ولكن بدلاً من ذلك في فئة Newspaper. ليس بالضبط كيف أردت أن يكون ، ولكن هذا سوف يفعل الآن:
<?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 »'); ?>
<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 »'); ?>
<div class="clear"></div>
</div>
<?php endwhile; endif;?>
كما قلت ، إنها ليست أنظف طريقة للقيام بالأشياء ، لكنها تعمل. إذا كان لديك اقتراحات أخرى ، فأنا كل آذان :)
شكرًا! أميت
لا تنتمي إلى StackOverflow