2013-09-01 2 views
1

index.php 테마에서 부트 스트랩 탭을 사용하여 기본 페이지 테마에 다른 내용을 표시하려고합니다. 나는 index.php에서 탭을 구현하고 인기있는 탭에 링크 된 popular-post.php라는 새 페이지를 만듭니다.새 php page wordpress에 링크

내가 인기있는 콘텐츠를 표시하기 위해 링크를 클릭하면 그러나 나는 얻을

치명적인 오류 :

에 정의되지 않은 함수 get_header()에 호출이 내의 index.php의 코드

<?php get_header(); ?> 
    <div class="row" id="content"> 
     <div class="col-sm-8 col-md-8 col-lg-8" id="primary"> 
     <ul class="nav nav-tabs"> 
    <li class="active"><a href="#">Home</a></li> 
    <li><a href="<?php bloginfo('template_directory'); ?>/popular-post.php">Popular</a></li> 
    <li><a href="#">Recientes</a></li> 
</ul> 



     <?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
      <?php 
       /* Include the Post-Format-specific template for the content. 
       * If you want to overload this in a child theme then include a file 
       * called content-___.php (where ___ is the Post Format name) and that will be used instead. 
       */ 
       get_template_part('content', get_post_format()); 
      ?> 

     <?php endwhile;?> 
      <?php /* Pagnavi plugin support */ wp_pagenavi(); ?> 

     <?php else: ?> 

      <?php get_template_part('no-results', 'index'); ?> 

     <?php endif; ?> 
     </div> 
     <div class="col-sm-4 col-md-4 col-lg-4" id="secondary"> 
     <?php get_sidebar(); ?> 
     </div> 
    </div><!--/content--> 

     <?php get_footer(); ?> 

이 ADVAN에

<?php 
/* 
Template Name: Popular Posts 
*/ 
?> 
<?php get_header(); ?> 
    <div class="row" id="content"> 
     <div class="col-sm-8 col-md-8 col-lg-8" id="primary"> 
     <ul class="nav nav-tabs"> 
    <li><a href="<?php bloginfo('template_directory'); ?>">Home</a></li> 
    <li class="active"><a href="#">Popular</a></li> 
    <li><a href="#">Recientes</a></li> 
</ul> 

<ul class="popular_posts"> 
     <?php $pc = new WP_Query('orderby=comment_count&#038;posts_per_page=10'); 

     while ($pc->have_posts()) : $pc->the_post(); ?> 
      <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> 
      <p>Posted by <strong><?php the_author() ?></strong> with <?php comments_popup_link('No Comments;', '1 Comment', '% Comments'); ?></p></li> 
     <?php endwhile; ?> 
    </ul> 

     </div> 
     <div class="col-sm-4 col-md-4 col-lg-4" id="secondary"> 
     <?php get_sidebar(); ?> 
     </div> 
    </div><!--/content--> 

     <?php get_footer(); ?> 

덕분에 인기-post.php의 코드 ce

답변

2

<a href="<?php bloginfo('template_directory'); ?>/popular-post.php">Popular</a>과 같은 테마 파일에 직접 연결할 수 없습니다.
이것은 잘못된 URL입니다 : http://example.com/wp-content/themes/YOUR-THEME/any-theme-file.php입니다. .

) URL에 (페이지 ID를 기록해 둡니다 파일이 이미 Page Template 헤더가 (템플릿을 선택, "인기있는 게시물"새 페이지를 만들고 링크와 같은 :.

<a href="<?php echo get_permalink(THE-ID-OF-YOUR-PAGE); ?>">Popular</a> 

이 유효한 URL이 생성 http://example.com/popular-posts/, 콘텐츠 (페이지)의 조각, 즉 정의 된 페이지 템플릿 파일을 사용

을 제목 사용 get_page_by_title에 의해 페이지 ID를 얻으려면 :.

$the_page = get_page_by_title('popular-posts'); 
echo '<a href="' . get_permalink($the_page->ID) . '">Popular</a>'; 

Template Hierarchy에 대한 정보도 도움이 될 것입니다.

+0

좋아요! get_pemalink에 에코를 추가하는 것만으로도 완벽하게 작동합니다! 그렇게 쉬운 일이었고 나는 미쳐 버렸습니다. 다른 질문 : 지금은 지역에서 일하고 있는데, 내 서버에 테마를 업로드 할 때 WordPress의 관리자 패널에서 인기있는 게시물 페이지를 만들고 ID를 변경해야만합니까 ?? – Trenton

+0

해결 방법으로 답을 업데이트했습니다 (그리고'echo'가 누락되었습니다). – brasofilo

관련 문제