2011-08-23 10 views
0

내 샘플 Wordpress 테마 index.php 코드를 검토해 주셨으면합니다.Wordpress 테마

<?php 
/* 
Template name: Homepage 
*/ 
get_header(); 
?> 
<?php 

    if(isset($_GET['action'])): 
     $action = $_GET['action']; 
     switch($action){ 
      case "sendmail": include("sendmail.php"); break; 
      case "mailsent" : include("thanks.php"); break; 
     } 
    else: 
?> 
    <!-------// Begin Content ----------> 
    <?php if (have_posts()): ?> 
    <?php while(have_posts()): the_post(); ?> 
     <tr> 
      <td class="contentarea"> 
       <h1><?php the_title(); ?></h1> 
       <p> <?php the_content(); ?></p> 
      </td> 
     </tr> 
    <?php endwhile; ?> 
    <?php else: ?> 
     <tr> 
      <td class="contentarea"> 
       <h1>Page not Found!</h1> 
       <p>Sorry, you are looking a page that is not here! </p> 
       <?php get_search_form(); ?> 
      </td> 
     </tr> 
    <?php endif; ?> 
     <!-------// End Content ----------> 
     <tr> 
     <!--begin contact form --> 
      <td class="contactarea" height="200"> 
       <?php include("contact_area.php"); ?> 
      </td> 
     <!--end contact form -->  
     </tr> 
<?php endif;?> 
<?php get_footer(); ? 

나는 켜려고 내 경우에는 내가 방법을 모르는 같은 기능 무언가로하지만, 위의 진술 :

 if(action_is_set()){ 
      then_do_the_action(); 
     }else { 
      //begin content..etc. 
     } 

내가 아직이야? 위의 내 코드의 더 나은 구조가 있는가 PHP와 Wordpress 모두를 배우기. 제발, 도와주세요. 감사!!.

+0

mythemeshop..visit에서 구입 한 모든 테마에서 60 % 할인 받으십시오. http://tech-papers.org/mythemeshop-coupon-code/ –

답변

1

나는 action_is_set() 함수를 만들려고 노력하지 않을 것입니다.

당신은 끝낼 것이다 :

function action_is_set() { 
    return isset($_GET['action']); 
} 

하지만 도움이 될 수 functions.php 내부 함수에 스위치를 이동합니다. 유사 보일 것

는 :

<?php 
get_header(); 

switch($_GET['action']) { 
    case 'sendmail': 
     include('sendmail.php'); 
     break; 
    case 'mailsent': 
     include('thanks.php'); 
     break; 
    default: 
     include('content.php'); 
} 

get_footer(); 
?> 

나도 몰라 :

function do_action() { 
    switch($_GET['action']) { 
     case 'sendmail': 
      include('sendmail.php'); 
      break; 
    } 
} 

또는 새에 콘텐츠 섹션을 이동하여 현재 페이지가 완전히 모듈화 할 수는 파일을 포함 이것이 WordPress의 모범 사례와 어떤 관계가 있는지를 보여주는 좋은 예입니다. 예를 들어 yourdomain.com/?action=blah에 갔다면 아무 일도 일어나지 않는 시나리오에서 특히 스위치에서 기본 사례를 사용하는 것이 좋습니다.

규칙 : 예상대로 사용하지 않을 것으로 기대하지 마십시오. 항상 누군가가 코드를 해독하려고한다고 가정합니다.

1

테마 아래 functions.php에 함수를 작성할 수 있습니다.

+0

thanks 덕분에 functions.php에서 코드 기능을 가르쳐 주시겠습니까 ?? ? :--( – Dan

+0

@Dan 이것은 코드 일반 함수와 아무런 차이가 없습니다 function.php에서 일부 함수를 정의하고 템플릿 PHP 파일에서 사용할 수 있습니다. 또한 add_action/add_filter를 사용하여 wordpress의 동작을 변경할 수 있습니다 the_content와 같은 기능. – xdazz

관련 문제