2012-11-02 17 views
8

Kendi temam var ve ana sayfamdaki yayınları belirli bir kategoriden görüntülemek istiyorum.Sülük kullanarak kategoriden nasıl yayın alırım?

Şimdiye kadar bunu böyle elde ettik:

<?php 
    global $post; 
    $args = array('numberposts' => 10, 'category' => 6); 
    $posts = get_posts($args); 
    foreach($posts as $post): setup_postdata($post); 
?> 

    <divs with the_title() the_excerpt() etc ></div> 

<?php 
    endforeach; 
?> 

Ama benim bir onun kurşunla kategoriyi almak istiyorsanız? Yoksa yönetici panelinden bir kategori seçim kutusu açmak mümkün mü?

cevap

24

sonra, bizim kodunu

+0

@IoQ Bu kod ile sayfalandırma nasıl kullanılabilir? – Amin

+0

Çok teşekkürler, zaman kurtardın – Bellash

2

http://codex.wordpress.org/Class_Reference/WP_Query#Parameters Eğer 'buz kek' olarak kategorisi adı 'buz kek' ve kategori sümüklüböcek olduğunu varsayalım bu bağlantıyı kontrol daha fazla bilgi için category_name

global $post; 
$args = array('numberposts' => 10, 'category_name' => 'cat-slug'); 
$posts = get_posts($args); 
foreach($posts as $post): setup_postdata($post); 

?> 

<divs with the_title() the_excerpt() etc ></div> 

<?php 

endforeach; 

ile kategori parametresinin yerini 'ice cakes' kategorisi altındaki gönderiyi almak için:

<?php 
       $args = array('posts_per_page' => 3, 
       'category_name' => 'ice-cakes'); 

       $icecakes = get_posts($args); 
       foreach ($icecakes as $post) : setup_postdata($post); ?> 
        <li> 
         <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> 
        </li> 
       <?php endforeach; 
       wp_reset_postdata(); ?> 
İlgili konular