ایجاد شرط برای هک مطالب مرتبط ؟

jafar1374

کاربر عضو
سلام دوستان عزیز

تو این هک مطالب مرتبط اگه بخوام یه شرط بذارم تا مثلا اگه مطلب مرتبطی نبود یه پیام پیام بذاره (مطلب مرتبطی وجو ندارد) باید چکار کنم ؟

ممنون


کد:
<?php
//for use in the loop, list 5 post titles related to first tag on current post
$tags = wp_get_post_tags($post->ID);
if ($tags) {
  echo 'Related Posts';
  $first_tag = $tags[0]->term_id;
  $args=array(
    'tag__in' => array($first_tag),
    'post__not_in' => array($post->ID),
    'showposts'=>5,
    'caller_get_posts'=>1
   );
  $my_query = new WP_Query($args);
  if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
      <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a><br/>
      <?php
    endwhile;
  }
}
?>
 

erfan

طراح وب
پرسنل مدیریت
این کد رو به اخرش اضافه کن:


کد:
 <?php else : ?>
<h4 style="
font:13px 'Roya';border:solid 1px #FF0000; width:300px; text-align:center;margin:15px auto 0; background:#ff9094;border-radius:3px;
line-height:25px;
">مطلبی موجو نیست!</h4>
  <?php endif; ?>
 

jafar1374

کاربر عضو
این کد رو به اخرش اضافه کن:

کد:
 <?php else : ?>
<h4 style="
font:13px 'Roya';border:solid 1px #FF0000; width:300px; text-align:center;margin:15px auto 0; background:#ff9094;border-radius:3px;
line-height:25px;
">مطلبی موجو نیست!</h4>
  <?php endif; ?>
این کد رو آخر هک گذاشتم ارور داد

میشه لطف کنی قاطی اون هک اصلی بذاری چون من زیاد به پی اچ پی وارد نیستم

ممنون

 

Mohammad

مدیر انجمن
پرسنل مدیریت
کد:
<?php
//for use in the loop, list 5 post titles related to first tag on current post
$tags = wp_get_post_tags($post->ID);
if ($tags) {
  echo 'Related Posts';
  $first_tag = $tags[0]->term_id;
  $args=array(
    'tag__in' => array($first_tag),
    'post__not_in' => array($post->ID),
    'showposts'=>5,
    'caller_get_posts'=>1
   );
  $my_query = new WP_Query($args);
  if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
      <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a><br/>
      <?php
    endwhile;
  }

  else { echo"<p>هيچ مطلب مشابهي وجود ندارد</p>"; }
}
?>
 

MahdiY

راهبر انجمن
ممنون از کد محمد جان

میشه یه استایل زیبا برای این کد قرار بدی

 

jafar1374

کاربر عضو
محمد آقا دستت درد نکنه عالیه ، درست شد ولی اون تیکد کد شما باید قبل از بسته شدن کد پی اچ پی قرار بگیره وگرنه ارور میده


کد:
 <?php
//for use in the loop, list 5 post titles related to first tag on current post
$tags = wp_get_post_tags($post->ID);
if ($tags) {
  echo '';
  $first_tag = $tags[0]->term_id;
  $args=array(
    'tag__in' => array($first_tag),
    'post__not_in' => array($post->ID),
    'showposts'=>5,
    'caller_get_posts'=>1
   );
  $my_query = new WP_Query($args);
  if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
        <?php the_title(); ?>
        </a><br/>
        <?php
    endwhile;

  }

}
else { echo"<p>هيچ مطلب مشابهي وجود ندارد</p>"; }
?>
 
بالا