2013-08-16 39 views
1

我想學習這個東西,但有多種方法去皮膚貓。我在WP中有幾個帖子,用作主頁上的內容塊。對於每個塊,我使用WordPress的簡單方法,然後分別拉每個帖子ID?

<?php 
$post_id = 34; 
$queried_post = get_post($post_id); 
$title = $queried_post->post_title; 
echo $queried_post->post_content; 
?> 

然後在不同的區域,我使用

<?php 
$post_id = 35; 
$queried_post = get_post($post_id); 
$title = $queried_post->post_title; 
echo $queried_post->post_content; 
?> 

這是構建一個自定義主頁的正確方法?

回答

0

使用此:

<?php 
$post_ID_Array = array(1, 10, 3, 4);//All the Post IDs you need 
    foreach ($post_ID_Array as $postID)://Iterate through all the IDs 
     $the_article = new WP_Query('p='.$postID);/*Retrieve the post*/ 
     while ($the_article->have_posts()) : $the_article->the_post(); ?> 
       <div class="post-details post-<?php echo $postID?>"> 
        <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2> 
        <p><?php the_content(); ?></p> 
       </div><!--.post-details--> 
    <?php 
    endwhile; 
    endforeach;?>  

然後可以樣式各部分單獨使用.post- {}帖子ID e.g 。員額-34 {}。您還可以使用設置所有帖子的風格.post-details

相關問題