2016-12-31 96 views
0

我有一個小問題,在模板最近的職位是什麼,我開發最近的帖子凌亂的wordpress

Screenshot

這是原始的HTML代碼

<div class="main-news"> <!-- general post container --> 

     <div class="new"> 
      <div class="new-content"> 
       <div class="new-image"> 
        <img class="noselect" src="<?php bloginfo('template_directory');?>/images/new-03.jpg" alt="News" title="Llamado Al templo"> 
       </div> 
       <div class="new-content-excerpt"> 
        <h1>Llamado al Templo</h1> 
        <p>La Academia Jedi Chile llama a todos sus miembros a reunirse en el templo jedi para iniciar un periodo de entrenamiento y... </p> 
        <p class="entrada">Entrada por: Midtaurus | 15/03/2016 | <span class="mark">Comentarios(8)</span></p> 
       </div> 
      </div> 
     </div> 

    </div> 

這是WordPress的改編

<?php 
    $recent_posts_query = new WP_Query(array('post_type' => 'post', 'posts_per_page' => 3)); 

    while ($recent_posts_query->have_posts()) 
    { 
    $recent_posts_query->the_post(); 
    ?> 
<div class="main-news"> 
    <div class="new"> 
     <div class="new-content"> 
     <div class="new-image"> 
     <?php the_post_thumbnail();?> 
    </div> 
    <div class="new-content-excerpt"> 
    <h1><?php echo the_title(); ?></h1> 
<?php the_excerpt();?> 
    <p class="entrada">Entrada por: <?php the_author(); ?> | <?php echo the_date('d/m/y'); ?> | <span class="mark">Comentario/s</span></p> 
</div> 

    <?php 
    } 
    ?> 
</div> 
</div> 
</div> 

我有點失落,我找不到什麼是問題,嘗試了不同的代碼,但所有你的時間做同樣的

感謝,並有一個很好的新的一年:)

PS:在HTML版本,當我重複的職位,他們不要弄亂

+0

你必須關閉三個閉合div後的while循環的大括號,檢查出HTML結構在你的代碼中是不匹配的。 –

回答

0

問題是HTML結構和大括號問題。

<?php 
$recent_posts_query = new WP_Query(array('post_type' => 'post', 'posts_per_page' => 3)); 

while ($recent_posts_query->have_posts()){ 
    $recent_posts_query->the_post(); ?> 
    <div class="main-news"> 
     <div class="new"> 
      <div class="new-content"> 
       <div class="new-image"><?php the_post_thumbnail();?></div> 
       <div class="new-content-excerpt"> 
        <h1><?php echo the_title(); ?></h1> 
        <?php the_excerpt();?> 
        <p class="entrada">Entrada por: <?php the_author(); ?> | <?php echo the_date('d/m/y'); ?> | <span class="mark">Comentario/s</span></p> 
       </div>  
      </div> 
     </div> 
    </div> 
<?php } ?> 

請您替換上面的代碼嗎?我希望這對你有所幫助。

+0

工作像魅力非常感謝! 新年快樂:)! –

相關問題