اذهب إلى المحتوى
  • 0

كيف أظهر taxonomy terms باستعمال حلقة تكرار على ووردبريس؟

سعاد

السؤال

داخل موقع مبني بووردبريس، لدي صفحة Html بالشكل التالي:

<table>
    <tr>
        <td>Name 1</td>
        <td>Name 2</td>
        <td>Name 3</td>
        <td>Name 4</td>  
    </tr>
    <tr>
    .....
</table>

وأريد إدراج كود php يعمل على جلب taxonomy terms باستعمال حلقة تكرار، بالطريقة التالية:

<?php 
    // no default values. using these as examples
    $i          = 0;
    $taxonomies = array( 'urun-kategorileri' );
    $args       = array(
        'orderby'   => 'menu-order',
        'order'     => 'ASC',
    ); 
    $tax_terms  = get_terms( $taxonomies, $args );

    echo '<table class="table table-hover"><tr>';  

    foreach( $tax_terms as $tax_term ) { {
        $i++;
        if( $i <= 4 ) {
            echo '<td><a href="' . esc_attr( get_term_link( $tax_term, $taxonomy ) ) . '" title="' . sprintf( __( "Profilleri Görüntüle %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name . '</a></td>';
            echo ("\n"); 
        }
        else {       
            echo '</tr><tr>';
            $i = 0;
        }
    } }
?>

</table>

لكن عند وصول الحلقة إلى الرقم 4 لا تظُهر  أي محتوى، فما العمل؟

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 0

المشكل هو في المتغير i$ والذي يعتبر في حلقة التكرار هذه بمثابة index والرقم الترتيبي لـ tax_term$.

بعد غلق أداة الشرط else اكتب ++i$، وذلك لإضافة 1 لقيمة i$ عند كل حلقة، ليكون الكود بالشكل التالي:

foreach( $tax_terms as $tax_term ) {
    if( $i <= 4 ) {
        echo '<td><a href="' . esc_attr( get_term_link( $tax_term, $taxonomy ) ) . '" title="' . sprintf( __( "Profilleri Görüntüle %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name . '</a></td>';
        echo ("\n"); 
    } else {       
        echo '</tr><tr>';
        $i = 0;
    }
    $i++;
}

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...