2017-07-04 8 views
0

私はWordpressのカスタムテーマをゼロから開発しています。私はindex.phpで動作するカスタムグリッド表示を取得することができました。各投稿には、投稿のタイトルとカテゴリがサブタイトルの画像が表示されます。Wordpress permalink content.phpにリンクしていません

<?php get_header(); ?> 
 

 
<div class="container-fluid bg-3 text-center Site-content" style="padding:60px; padding-top:100px;"> 
 
    <?php 
 
    $counter = 1; //start counter 
 

 
    $grids = 2; //Grids per row 
 

 
    query_posts($query_string . '&caller_get_posts=1&posts_per_page=12'); 
 

 

 
    if (have_posts()) : while (have_posts()) : the_post(); 
 
      ?> 
 
      <?php 
 
//Show the left hand side column 
 
      if ($counter == 1) : 
 
       ?> 
 
       <div class="col-sm-4"> 
 
        <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"> 
 
         <img src="<?php the_post_thumbnail_url(); ?>" class="img-responsive" style="width:100%;" alt=""></a> 
 
        <strong><?php the_title(); ?></strong> 
 
        <?php 
 
        foreach ((get_the_category()) as $category) { 
 
         echo "<h6>".$category->category_nicename. "</h6>"; 
 
        } 
 
        ?> 
 
       </div>  
 
       <?php 
 
//Show the right hand side column 
 
      elseif ($counter == $grids) : 
 
       ?> 
 
       <div class="col-sm-4"> 
 
        <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"> 
 
         <img src="<?php the_post_thumbnail_url(); ?>" class="img-responsive" style="width:100%;" alt=""></a> 
 
        <strong><?php the_title(); ?></strong> 
 
        <?php 
 
        // heres just the name and permalink: 
 
        foreach ((get_the_category()) as $category) { 
 
         echo "<h6>".$category->category_nicename. "</h6>"; 
 
        } 
 
        ?> 
 
       </div> 
 
       <?php 
 
       $counter = 0; 
 
      endif; 
 
      ?> 
 
      <?php 
 
      $counter++; 
 
     endwhile; 
 
    endif; 
 
    ?> 
 
</div> 
 
<?php get_footer(); ?>

投稿のサムネイルがcontent.phpにリンクしなければならない投稿のパーマリンクへのリンクが含まれています。ここindex.phpのコードです。ここcontent.phpです:

<div class="container" style="padding:100px;"> 
 
\t <strong><?php the_title(); ?></strong> 
 
     <?php 
 
     foreach ((get_the_category()) as $category) { 
 
      echo "<h5>" . $category->category_nicename . "</h5>"; 
 
     } 
 
     ?> 
 
     <h5>/<?php the_date(); ?> </h5> 
 
     <h5> <?php the_content(); ?> </h5> 
 
    </div>

問題は、私はindex.phpのサムネイルをクリックすると、それは代わりにcontent.phpページの、自身の小型版にリンクしていることです。私の推測では、パーマリンクにどこに行かなければならないかを伝える必要があるが、実際にこの設定をどこに置くべきかはわからない。

ありがとうございます!

答えて

1

WordPressでは、the_permalink()またはget_permalink()は、投稿またはページの単一ページURLを返します。単一の投稿ページにsingle.phpファイルが読み込まれるのはWordPress template hierarchyです。

あなたはここでは二つのオプション、

1)をしましたがcontent.phpからsingle.phpにあなたのコードをコピーして、あなたが行ってもいいでしょう。もちろん、ページが正しく読み込まれるように、get_header()get_footer()を含める必要があります。

2)ループ内のsingle.phpには、content.phpをテンプレート部分として含めることができます。 single.phpに次のように入り、ループを置き換えます。

while (have_posts()) : 
    the_post(); 
    get_template_part('content'); 
endwhile; 

また、上記のコードでは、私はあなたのcontent.phpがテーマディレクトリのルートに置かれていると仮定しています。

+0

完全に機能しました。ありがとうございました!さて、私は生成されたコンテンツに私の外部のCSSシートを適用するのに苦労しているだけですが、それは別の話だと思います。 – rschpdr

関連する問題