2013-10-03 244 views
0

我有下面的代碼工作正常顯示帖子是標籤與頁的'slu'。WordPress的自定義頁面的帖子

php文件被稱爲pagesofposts.php在wordpress codex文檔中建議。

<?php 
/* 
Template Name: Page Of Posts 
*/ 

/* This example is for a child theme of Twenty Thirteen: 
* You'll need to adapt it the HTML structure of your own theme. 
*/ 

get_header(); ?> 

    <div id="primary" class="content-area"> 
     <div id="content" class="site-content" role="main"> 
     <?php 
     /* The loop: the_post retrieves the content 
     * of the new Page you created to list the posts, 
     * e.g., an intro describing the posts shown listed on this Page.. 
     */ 
     global $post; 
     $slug = get_post($post)->post_name; 

     if (have_posts()) : 
      while (have_posts()) : the_post(); 

       // Display content of page 
       get_template_part('content', get_post_format()); 
       wp_reset_postdata(); 

      endwhile; 
     endif; 

     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 

     $args = array(
      // Change these category SLUGS to suit your use. category_name is comma separated. 
      'tag' => $slug, 
      'paged' => $paged 
     ); 

     $list_of_posts = new WP_Query($args); 
     ?> 
     <?php if ($list_of_posts->have_posts()) : ?> 
      <?php /* The loop */ ?> 
      <?php while ($list_of_posts->have_posts()) : $list_of_posts->the_post(); ?> 
       <?php // Display content of posts ?> 
       <?php get_template_part('content', get_post_format()); ?> 
      <?php endwhile; ?> 

      <?php twentythirteen_paging_nav(); ?> 

     <?php else : ?> 
      <?php get_template_part('content', 'none'); ?> 
     <?php endif; ?> 

     </div><!-- #content --> 
    </div><!-- #primary --> 

<?php get_footer(); ?> 

我的問題是,頁面標題看起來好像它是一個職位,因爲它失去了格式。

我在下面列出了默認的page.php文件,據我瞭解,這個文件是Pages使用的默認模板。

<?php 
/** 
* The template for displaying all pages. 
* 
* This is the template that displays all pages by default. 
* Please note that this is the WordPress construct of pages and that other 
* 'pages' on your WordPress site will use a different template. 
* 
* @package WordPress 
* @subpackage Twenty_Thirteen 
* @since Twenty Thirteen 1.0 
*/ 

get_header(); ?> 

    <div id="primary" class="content-area"> 
     <div id="content" class="site-content" role="main"> 

      <?php /* The loop */ ?> 
      <?php while (have_posts()) : the_post(); ?> 

       <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 
        <header class="entry-header"> 
         <?php if (has_post_thumbnail() && ! post_password_required()) : ?> 
         <div class="entry-thumbnail"> 
          <?php the_post_thumbnail(); ?> 
         </div> 
         <?php endif; ?> 

         <h1 class="entry-title"><?php the_title(); ?></h1> 
        </header><!-- .entry-header --> 

        <div class="entry-content"> 
         <?php the_content(); ?> 
         <?php wp_link_pages(array('before' => '<div class="page-links"><span class="page-links-title">' . __('Pages:', 'twentythirteen') . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>')); ?> 
        </div><!-- .entry-content --> 

        <footer class="entry-meta"> 
         <?php edit_post_link(__('Edit', 'twentythirteen'), '<span class="edit-link">', '</span>'); ?> 
        </footer><!-- .entry-meta --> 
       </article><!-- #post --> 

       <?php comments_template(); ?> 
      <?php endwhile; ?> 

     </div><!-- #content --> 
    </div><!-- #primary --> 

<?php get_sidebar(); ?> 
<?php get_footer(); ?> 

可能有人請幫我將二者結合起來,所以它作爲一個標準的頁面,但相關聯的帖子在底部也顯示。

+0

你有問題的頁面標題?這兩個模板共享標題相同的代碼即header.php – codepixlabs

+0

它實際上在格式化標題,它看起來好像它是一個職位。我其實自己就解決了它。我將在一秒內將代碼發佈給其他人。 – Mike

回答

0

我實際上已經設法將它自己排序,上面兩個文件中的代碼合併爲一個可用的代碼。

該php文件被稱爲pagesofposts.php。

<?php 
/* 
Template Name: Page Of Posts 
*/ 

/* This example is for a child theme of Twenty Thirteen: 
* You'll need to adapt it the HTML structure of your own theme. 
*/ 

get_header(); ?> 

    <div id="primary" class="content-area"> 
     <div id="content" class="site-content" role="main"> 

     <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 
        <header class="entry-header"> 
         <?php if (has_post_thumbnail() && ! post_password_required()) : ?> 
         <div class="entry-thumbnail"> 
          <?php the_post_thumbnail(); ?> 
         </div> 
         <?php endif; ?> 

         <h1 class="entry-title"><?php the_title(); ?></h1> 
        </header><!-- .entry-header --> 

        <div class="entry-content"> 
         <?php the_content(); ?> 
         <?php wp_link_pages(array('before' => '<div class="page-links"><span class="page-links-title">' . __('Pages:', 'twentythirteen') . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>')); ?> 
        </div><!-- .entry-content --> 

        <footer class="entry-meta"> 
         <?php edit_post_link(__('Edit', 'twentythirteen'), '<span class="edit-link">', '</span>'); ?> 
        </footer><!-- .entry-meta --> 
       </article><!-- #post --> 

<?php 

    global $post; 
     $slug = get_post($post)->post_name; 

     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 

     $args = array(
      // Change these category SLUGS to suit your use. category_name is comma separated. 
      'tag' => $slug, 
      'paged' => $paged 
     ); 

     $list_of_posts = new WP_Query($args); 
     ?> 
     <?php if ($list_of_posts->have_posts()) : ?> 
      <?php /* The loop */ ?> 
      <?php while ($list_of_posts->have_posts()) : $list_of_posts->the_post(); ?> 
       <?php // Display content of posts ?> 
       <?php get_template_part('content', get_post_format()); ?> 
      <?php endwhile; ?> 

      <?php twentythirteen_paging_nav(); ?> 

     <?php else : ?> 
      <?php get_template_part('content', 'none'); ?> 
     <?php endif; ?> 

     </div><!-- #content --> 
    </div><!-- #primary --> 

<?php get_footer(); ?> 
相關問題