2016-11-17 69 views
0

您好同事wordpress expirienced的用戶。 我在做Wordpress TwentySixteen主題中的最新3篇文章摘錄和我的主頁中的縮略圖時正在進行鬥爭。 我試過各種可能性,但我不能讓它運行。循環中的循環獲取摘錄 - 二十六個主題WordPress的

的目標是看帖子是這樣的: http://caenthemes.cekuj.net/?s=p%C5%99%C3%ADsp%C4%9Bvek

我的想法是使用一個已經取得模板的頁面SEACH。 但是,它的摘錄的文本是無處的: http://caenthemes.cekuj.net/ 請不要把它的樣式留下的事實。

主要頁面的代碼:

<?php 
/** 
* The template for displaying main-page without title. 
* @package WordPress 
* @subpackage Twenty_Sixteen 
* @since Twenty Sixteen 1.0 
*/ 
?> 

<section id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 
    <!--<header class="entry-header"> 
    <?php the_title('<h1 class="entry-title">', '</h1>'); ?> 
    </header><!-- .entry-header --> 
    <div class="wp-page-content"> 
     <?php 
     the_content(); 
     wp_link_pages(array(
      'before' => '<div class="page-links"><span class="page-links-title">' . __('Pages:', 'twentysixteen') . '</span>', 
      'after' => '</div>', 
      'link_before' => '<span>', 
      'link_after' => '</span>', 
      'pagelink' => '<span class="screen-reader-text">' . __('Page', 'twentysixteen') . ' </span>%', 
      'separator' => '<span class="screen-reader-text">, </span>', 
     )); 
     ?> 
    </div><!-- .entry-content --> 
</section> 
<section> 
    <header class="entry-header"> 
     <h2> 
      <?php 
      if (get_locale() == 'cs_CZ') { 
       echo "Nejnovější příspěvky"; 
      } else { 
       echo "Latest posts"; 
      } 
      ?> 
     </h2> 
    </header><!-- .entry-header --> 

    <?php 
    $args = array(
     'posts_per_page' => 3, 
     'offset' => 0, 
     'category' => '', 
     'category_name' => '', 
     'orderby' => 'date', 
     'order' => 'DESC', 
     'include' => '', 
     'exclude' => '', 
     'meta_key' => '', 
     'meta_value' => '', 
     'post_type' => 'post', 
     'post_mime_type' => '', 
     'post_parent' => '', 
     'author' => '', 
     'author_name' => '', 
     'post_status' => 'publish', 
     'suppress_filters' => true 
    ); 
    $myposts = get_posts($args); 
    foreach ($myposts as $post) : setup_postdata($post); 
     get_template_part('template-parts/content', 'search'); 
    endforeach; 
    wp_reset_postdata(); 
    ?> 
</section><!-- #wp-page-content-## --> 

我80%肯定,我不是正確的處理二十十六主循環內的內部循環。只是爲了涵蓋所有的可能性,我也試圖做到這一點,而不是通過獲取模板,但我仍然只獲得帖子類別標題和縮略圖,而不是摘錄。 你能幫我嗎? 整個頁面基於二十六個主題與我的修改。 非常感謝你, 卡昂Ragestorm

回答

0

感謝SJP我做到了。所以,爲我工作的完整代碼在這裏,希望其他人會發現它有用:

<section id="latest-posts"> 
    <header class="entry-header"> 
     <h2> 
      <?php 
      if (get_locale() == 'cs_CZ') { 
       echo "Nejnovější příspěvky"; 
      } else { 
       echo "Latest posts"; 
      } 
      ?> 
     </h2> 
    </header><!-- .entry-header --> 
    <div class="entry-content"> 
     <?php 
     $args = array(
      'posts_per_page' => 3, 
      'orderby' => 'date', 
      'order' => 'DESC', 
      'post_type' => 'post', 
      'post_status' => 'publish', 
      'suppress_filters' => true 
     ); 
     $latestPost = new WP_Query($args); 
     while ($latestPost->have_posts()) : $latestPost->the_post(); 
      ?> 
      <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 
       <header class="entry-header"> 
        <?php the_title(sprintf('<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url(get_permalink())), '</a></h2>'); ?> 
       </header><!-- .entry-header --> 
       <div class="post-summary"> 
        <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true"> 
         <?php the_post_thumbnail('post-thumbnail', array('alt' => the_title_attribute('echo=0'))); ?> 
        </a> 
        <div class="entry-summary"> 
         <?php the_excerpt(); ?> 
        </div> 
       </div> 
       <?php if ('post' === get_post_type()) : ?> 

        <footer class="entry-footer"> 
         <?php twentysixteen_entry_meta(); ?> 
         <?php 
         edit_post_link(
           sprintf(
             /* translators: %s: Name of current post */ 
             __('Edit<span class="screen-reader-text"> "%s"</span>', 'twentysixteen'), get_the_title() 
           ), '<span class="edit-link">', '</span>' 
         ); 
         ?> 
        </footer><!-- .entry-footer --> 

        <?php else : ?> 

        <?php 
        edit_post_link(
          sprintf(
            /* translators: %s: Name of current post */ 
            __('Edit<span class="screen-reader-text"> "%s"</span>', 'twentysixteen'), get_the_title() 
          ), '<footer class="entry-footer"><span class="edit-link">', '</span></footer><!-- .entry-footer -->' 
        ); 
        ?> 

       <?php endif; ?> 
      </article> 
       <?php 
      endwhile; 
      wp_reset_postdata(); 
      ?> 
    </div> 
</section> 

美好的一天,給大家。 卡昂Ragestorm

www.CaenRagestorm.cz

+0

謝謝@caen – Chinou

0

爲了得到交的詳細信息,如標題,內容和特色的圖像,你可以使用此代碼:根據您的要求

$latestPost = new WP_Query(array('post_type' => 'posts', 'posts_per_page' =>-1,'order' => 'ASC')); 
while ($latestPost->have_posts()) : $latestPost->the_post(); 
     $sTitle    = the_title(); 
     $sContent    = the_content(); 
     $feat_image_latestPost = wp_get_attachment_url(get_post_thumbnail_id($post->ID)); 
endwhile; 

重新寫CSS。

+0

感謝您的代碼,但我不知道它會與摘錄工作?因爲那是什麼不能正常工作。可能可能會得到the_excerpt()而不是內容? – Caen