2017-01-10 30 views
0

我可以用CSS和HTML工作得很好,但對PHP一無所知。我正在開發一個wordpress客戶端項目,他希望在靜態主頁上顯示多個最新帖子/最新帖子。我正在試圖弄清楚這件事。從發佈的代碼中,有人可以告訴我要刪除什麼以及如何替換它,以使最新的帖子出現5個?我非常感謝大家的幫助。如何添加更多最新帖子到主頁

<?php 
/** 
* Template Name: Homepage 
*/ 
?> 
<?php $mts_options = get_option(MTS_THEME_NAME); ?> 
<?php get_header(); ?> 
<?php if ($mts_options['mts_banner_show'] == '1') { ?> 
<div class="b_first"> 
    <div class="main-container"> 
     <div class="container"> 
      <div class="blog_first"> 
       <!--first content--> 
       <div id="first_b"> 
        <div class="b_right" <?php if (isset($_GET['mailchimp_signup']) || !empty($_GET['aweber_signedup'])) echo 'style="display:none;"'; ?>> 
         <h2 class="front-view-title"> 
          <?php echo $mts_options['mts_banner_title']; ?> 
         </h2> 
         <div class="front-view-content"> 
          <?php echo $mts_options['mts_banner_texts']; ?> 
         </div> 
         <?php if(!empty($mts_options['mts_button_text'])) { ?> 
          <div class="readMore" style="background:<?php echo $mts_options['mts_banner_button_bg']; ?>"> 
           <a href="javascript:void(0);" onclick="hide_b();"><?php echo $mts_options['mts_button_text']; ?></a> 
           <?php if(!empty($mts_options['mts_arrow_image'])) { ?> 
            <div class="b_dollor"> 
             <img src="<?php echo $mts_options['mts_arrow_image']; ?>"> 
            </div> 
           <?php } ?> 
          </div> 
         <?php } ?> 
        </div> 
        <!--Rightside Content-Option-1--> 
       </div> 
       <div id="second_b" <?php if (!isset($_GET['mailchimp_signup']) && empty($_GET['aweber_signedup'])) echo 'style="display:none;"'; ?>> 
        <div class="blog_first_alternative"> 
         <h2 class="front-view-title"> 
         <?php echo $mts_options['mts_banner_title']; ?> 
         </h2> 
         <div class="form_wrap"> 
          <?php if(!empty($mts_options['mts_form_image'])) { ?> 
           <div class="form_wrap_left"> 
            <img src="<?php echo $mts_options['mts_form_image']; ?>"> 
           </div> 
          <?php } ?> 
          <div class="form_wrap_right"> 
           <?php dynamic_sidebar('Home Subscribe Widget'); ?> 
          </div> 
         </div> 
        </div> 
        <!--Rightside content alternative option--> 
        <script type="text/javascript"> 
         function hide_b() { 
          jQuery('#first_b').hide(); 
          jQuery('#second_b').show(); 
         } 
        </script> 
       </div> 
      </div> 
      <!--End of first content--> 
     </div> 
    </div> 
</div> 
<?php } ?> 
<div class="main-container"> 
    <div id="page"> 
     <div class="artcl article"> 
      <div id="content_box"> 
       <?php if ($mts_options['mts_banner2_show'] == '1') { ?> 
        <!--Second Content--> 
        <div class="blog_second"> 
         <div class="b_left"> 
          <h2 class="front-view-title"> 
           <?php echo $mts_options['mts_social_title']; ?> 
          </h2> 
          <?php if (!empty($mts_options['mts_banner_social']) && is_array($mts_options['mts_banner_social'])) { ?> 
           <div class="social-icons"> 
            <ul> 
             <?php foreach($mts_options['mts_banner_social'] as $header_icons) : ?> 
              <?php if(! empty($header_icons['mts_banner_icon']) && isset($header_icons['mts_banner_icon'])) : ?> 
               <li><a href="<?php print $header_icons['mts_banner_icon_link'] ?>" class="header-<?php print $header_icons['mts_banner_icon'] ?>"><span class="fa fa-<?php print $header_icons['mts_banner_icon'] ?>"></span></a></li> 
              <?php endif; ?> 
             <?php endforeach; ?> 
            </ul> 
           </div> 
          <?php } ?> 
         </div> 
         <div class="b_right"> 
          <h2 class="front-view-title"> 
          <?php echo $mts_options['mts_books_title']; ?> 
          </h2> 
          <div class="b_readings"> 
           <ul> 
            <?php if(!empty($mts_options['mts_books_image'])){ ?> 
             <?php foreach($mts_options['mts_books_image'] as $slide) : ?> 
              <li><a href="<?php echo $slide['mts_book_link']; ?>"> <?php echo wp_get_attachment_image($slide['mts_book_image'], false, array('title' =>'')); ?></a></li> 
             <?php endforeach; ?> 
             <li class="more-books"><a href="<?php echo $mts_options['mts_more_book_link']; ?>"><?php echo $mts_options['mts_more_book_text']; ?><i class="fa fa-angle-double-right"></i></a></li> 
            <?php } ?> 
           </ul> 
          </div> 
         </div> 
        </div> 
       <?php } ?> 
       <?php if(!empty($mts_options['mts_featured_posts']) && !empty($mts_options['mts_featured_post_cat'])) { ?> 
        <div class="home_article"> 
         <?php 
         $featured_cat = implode(",", $mts_options['mts_featured_post_cat']); 
         $featured_query = new WP_Query('cat='.$featured_cat.'&posts_per_page=5'); 
         if ($featured_query->have_posts()) : while ($featured_query->have_posts()) : $featured_query->the_post(); ?> 
         <article class="latestPost featuredpost excerpt"> 
          <!--Featured Post--> 
          <header> 
           <h3 class="title front-view-title"><?php echo get_the_category_by_ID($featured_cat); ?></h3> 
           <?php if(has_post_thumbnail()) { ?> 
            <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>" id="featured-thumbnail"> 
             <div class="featured-thumbnail"> 
              <?php the_post_thumbnail('steadyincome-featured',array('title' => '')); ?> <?php if (function_exists('wp_review_show_total')) wp_review_show_total(true, 'latestPost-review-wrapper'); ?> 
             </div> 
            </a> 
           <?php } ?> 
          </header> 
          <div class="latestpost_wrap"> 
           <h2 class="front-view-title"> 
            <a href="<?php the_permalink() ?>" title="<?php the_title(); ?> 
           "><?php the_title(); ?></a> 
           </h2> 
           <?php mts_the_postinfo('home'); ?> 
           <div class="front-view-content"> 
            <?php echo mts_excerpt(45); ?> 
           </div> 
           <?php mts_readmore(); ?> 
          </div> 
         </article> 
         <?php endwhile; wp_reset_query(); endif; ?> 

         <?php $j = 0; 
         if (get_query_var('page') > 1) { 
          $paged = get_query_var('page'); 
         } elseif (get_query_var('paged')) { 
          $paged = get_query_var('paged'); 
         } else { 
          $paged = 1; 
         } 
         $args= array('paged' => $paged, 'post_type' => 'post'); 


         query_posts($args); 
         if (have_posts()) : while (have_posts()) : the_post();?> 
          <?php if($j ==0){ ?> 
           <article class="latestPost latestpost excerpt"> 
            <!--Latest Post--> 
            <header> 
             <h3 class="title front-view-title"><?php _e('Latest Post','steadyincome'); ?></h3> 
             <a href="<?php the_permalink() ?>" title="Menu widget article" id="featured-thumbnail"> 
              <div class="featured-thumbnail"> 
               <?php the_post_thumbnail('steadyincome-featured',array('title' => '')); ?> 
               <?php if (function_exists('wp_review_show_total')) wp_review_show_total(true, 'latestPost-review-wrapper'); ?> 
              </div> 
             </a> 
            </header> 
            <div class="latestpost_wrap"> 
             <h2 class="front-view-title"> 
              <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> 
             </h2> 
             <?php mts_the_postinfo('home'); ?> 
             <div class="front-view-content"> 
              <?php echo mts_excerpt(40); ?> 
             </div> 
             <?php mts_readmore(); ?> 
            </div> 
           </article> 
          <?php } ?> 
         <?php $j++; endwhile; wp_reset_query(); endif; ?> 
        </div> 
       <?php } ?> 
      </div> 
     </div> 
    </div> 
</div> 
<?php get_footer(); ?> 
+3

歡迎來到SO。你可以看一些[遊覽]和[問]。這些應該給你一個好主意,如何提出一個好問題,並最大限度地利用這個網站 – happymacarts

回答

0

看起來你可能在你的主題設置中有一些設置。但是,如果你沒有在那裏設置。

你可以看到這條線被限制最新的帖子只是一個帖子:

​​

您可以嘗試將其更改爲編號,你想嘗試,看看它是否循環更多內容有:

     <?php if($j < 5){ ?> 

這應該允許循環現在運行五個帖子。嘗試一下,看看它是否有幫助。

+0

你真了不起!有效!我忽略了這樣一個簡單的調整。非常感謝! (希望我會來這裏幾個小時前) –

+0

很高興它爲你工作@CharlesRivera祝你好運! :) – Mohsin

相關問題