رفتن به مطلب

نمایش نوشته هایی که تصویر شاخص دارند


پست های پیشنهاد شده

با سلام!

برای نمایش 5 نوشته آخریی که برای آن ها تصاویر شاخص انتخاب شده باید از چه کدی استفاده کرد؟

(برای بعضی از نوشته ها تصویر شاخص استفاده نمی شود حالا می خواهیم در یک مکان در صفحه نخست فقط 5 نوشته ایی که تصویر شاخص دارند نمایش داده شوند)

لینک به ارسال

از wp_query استفاده کنید با پارامتر:


$args = array (
'numberposts' => 4,
'post_type' => 'post',
'meta_key' => '_thumbnail_id',
'orderby' => 'date',
'order' => 'DESC'
);

  • امتیاز 2
لینک به ارسال

از wp_query استفاده کنید با پارامتر:


$args = array (
'numberposts' => 4,
'post_type' => 'post',
'meta_key' => '_thumbnail_id',
'orderby' => 'date',
'order' => 'DESC'
);

کد کاملشو نمیشه بذارید :mellow:

لینک به ارسال

از کدهای زیر استفاده کردم ولی 10 نوشته آخر رو در مکان مورد نظر نشون داد :mellow:


<?php $recent = new WP_Query($args);
$args = array (
'numberposts' => 5,
'post_type' => 'post',
'meta_key' => '_thumbnail_id',
'orderby' => 'date',
'order' => 'DESC'
);
while($recent->have_posts())
: $recent->the_post();?>
<?php the_post_thumbnail(); ?><br />
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a><br />
<p><?php the_excerpt_rss( 1000, 1 ); ?></p>
<?php endwhile; ?>

همچنین نوشته هایی که تصویر شاخص هم نداشتند به نمایش در آمدند

ویرایش شده توسط saeedagha
لینک به ارسال

$args = array (
'numberposts' => 5,
'post_type' => 'post',
'meta_key' => '_thumbnail_id',
'orderby' => 'date',
'order' => 'DESC'
);

$recent = new WP_Query($args);

  • امتیاز 2
لینک به ارسال


$args = array (
'numberposts' => 5,
'post_type' => 'post',
'meta_key' => '_thumbnail_id',
'orderby' => 'date',
'order' => 'DESC'
);

$recent = new WP_Query($args);

با افزودن کد های زیر باز هم 10 نوشته آخر به نمایش در آمدند و همچنین نوشته هایی که تصویر شاخص نداشتند نشان داده شدند :(


<?php $args = array (
'numberposts' => '5',
'post_type' => 'post',
'meta_key' => '_thumbnail_id',
'orderby' => 'date',
'order' => 'DESC'
);
$recent = new WP_Query($args);
while($recent->have_posts())
: $recent->the_post();?>
<?php the_post_thumbnail(); ?><br />
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a><br />
<p><?php the_excerpt_rss( 1000, 1 ); ?></p>
<?php endwhile; ?>

ویرایش شده توسط saeedagha
لینک به ارسال

تست کنید:

<?php
query_posts('showposts=5');
while($recent->have_posts()): $recent->the_post();
if (has_post_thumbnail()) {
<?php the_post_thumbnail(); ?><br />
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a><br />
<p><?php the_excerpt_rss( 1000, 1 ); ?></p>
<?php
}
endwhile;wp_reset_query(); ?>

  • امتیاز 1
لینک به ارسال

لطفا برای ارسال دیدگاه وارد شوید

شما بعد از اینکه وارد حساب کاربری خود شدید می توانید دیدگاهی ارسال کنید



ورود به حساب کاربری
×
×
  • اضافه کردن...