Home 게시판 커뮤니티 Q&A is_page 값을 넘기려면..?

8개 답변, 1 voice Last updated by 익명 18 years, 1 month 전
  • 익명
    손님
    @
    #935

    생각해보니 위에 제가 답변드린 내용으로는 원하시는 결과를 보실 수 없네요. 죄송합니다.

    적용하시려는 조건들이 고정적이지 않고 유동적이기때문에 그렇습니다.
    이미 정해진 옵션값이나 설정값을 불러오는건 가능하지만, 이 경우는 css가 페이지에 로딩되기 이전에 이미 ‘test’라는 값이 입력된 상태로 넘어오게 되는거죠.

    원하는 결과를 얻으려면 header.php파일에 직접 입력하는 방법밖에 없겠네요.

    <?php if (is_page('contact')) $current = 'contact';
    else $current = 'test'; ?>
    <style type="text/css">

    스타일값들...
    }
    </style>

    익명
    손님
    @
    #936

    <?php
    if ( is_page('contact') ) { $current = 'contact'; }
    elseif ( is_page('works') ) { $current = 'works'; }
    elseif ( is_page('home') ) { $current = 'home'; }
    else { $current = 'test'; }
    ?>

    background-position: 0 -32px;
    }

    이런식으로 header.php 나 single.php 페이지에는 삽입하면 브라우저 소스보기에서 $current값이 출력 됨을 확인할 수 있습니다.

    하지만 이값들을 php에 넣어, 값을 전달받고자 합니다. (header는 css로 입력)

    http://1.com/wp/wp-content/theme/1/1.css.php 라고 저장후 불러올 경우

    결과는

    Fatal error: Call to undefined function: is_page() in 절대경로/1.css.php

    즉 다른 페이지에 <?php get_header(); ?> 를 입력하여 출력시키면
    Fatal error: Call to undefined function: get_header() 라고 에러가 납니다.

    이 부분을 해결하려면 어떻게 해야 할까요;;

    익명
    손님
    @
    #940

    <?php
    if ( is_page('contact') ) { $current = 'contact'; }
    elseif ( is_page('works') ) { $current = 'works'; }
    elseif ( is_page('home') ) { $current = 'home'; }
    else { $current = 'test'; }
    ?>

    background-position: 0 -32px;
    }

    이런식으로 header.php 나 single.php 페이지에는 삽입하면 브라우저 소스보기에서 $current값이 출력 됨을 확인할 수 있습니다.

    하지만 이값들을 php에 넣어, 값을 전달받고자 합니다. (header는 css로 입력)

    http://1.com/wp/wp-content/theme/1/1.css.php 라고 저장후 불러올 경우

    결과는

    Fatal error: Call to undefined function: is_page() in 절대경로/1.css.php

    즉 다른 페이지에 <?php get_header(); ?> 를 입력하여 출력시키면
    Fatal error: Call to undefined function: get_header() 라고 에러가 납니다.

    이 부분을 해결하려면 어떻게 해야 할까요;;

    Avatar of 082net082net
    Keymaster
    @082net
    #937

    우선 질문 하신 내용에 대한 답변입니다.

    css파일에서 워드프레스의 인식자를 쓰려면 wp-config.php파일을 include하셔야 합니다.
    (css파일이 ‘/wp-content/themes/1/1.css.php’에 위치한다고 가정하겠습니다.)

    파일의 맨 위에 아래 코드를 넣어 주세요.

    <?php
    /*
    The headers below tell the browser to cache the file and also tell the browser it is css.
    */
    header("Cache-Control: must-revalidate");
    $offset = 60*60*24*60;
    $ExpStr = "Expires: ".gmdate("D, d M Y H:i:s",time() + $offset)." GMT";
    header($ExpStr);
    header('Content-Type: text/css');
    include("../../../wp-config.php");
    ?>

    주석처리된 설명을 보시면 왜 위의 코드가 필요한지를 아실 수 있습니다.

    추가
    질문하신 내용으로 미루어보아.. 페이지마다 메뉴의 css스타일을 다르게 하려고 하시는듯 한데.. 맞나요?

    그렇다면 위 과정을 거치는것 보다는 페이지 리스트를 wp_list_pages() 를 이용해서 나열하는 방법이 더 효과적일듯 합니다.
    (참고페이지: http://codex.wordpress.org/Template_Tags/wp_list_pages)
    이 방법을 이용하면 현재의 페이지의 class가 ‘current_page_item’이 되고 나머지 페이지 메뉴들의 class는 ‘page_item’이 됩니다.
    .current_page_item { } 의 스타일만 다르게 지정해 주시면 되네요. 아래는 k2테마에서 상단부분에 페이지메뉴를 나열한 방법입니다. 한번 살펴보세요.

    <ul class="menu">
    <li class="<?php if (((is_home()) && !(is_paged())) or (is_archive()) or (is_single()) or (is_paged()) or (is_search())) { ?>current_page_item<?php } else { ?>page_item<?php } ?>"><a href="<?php echo get_settings('home'); ?>" title="Blog Home">Blog</a></li>
    <?php wp_list_pages('sort_column=menu_order&depth=1&title_li='); ?>
    </ul>

    질문하신 내용에 있는 css스타일은 아래처럼 됩니다.

    ul.menu li.page_item {
    /* 기본적인 메뉴 스타일 */
    }

    ul.menu li.current_page_item {
    background-position: 0 -32px; /* 헌재 페이지의 스타일 */
    }

    Avatar of 082net
    Facebook 사용자 모임 그룹 도 함께 운영되고 있으며, 격 주로 미트업과 스터디를 진행하고 있으니 관심 있으신 분들의 많은 참여 바랍니다 🙂
    Avatar of 082net082net
    Keymaster
    @082net
    #941

    우선 질문 하신 내용에 대한 답변입니다.

    css파일에서 워드프레스의 인식자를 쓰려면 wp-config.php파일을 include하셔야 합니다.
    (css파일이 ‘/wp-content/themes/1/1.css.php’에 위치한다고 가정하겠습니다.)

    파일의 맨 위에 아래 코드를 넣어 주세요.

    <?php
    /*
    The headers below tell the browser to cache the file and also tell the browser it is css.
    */
    header("Cache-Control: must-revalidate");
    $offset = 60*60*24*60;
    $ExpStr = "Expires: ".gmdate("D, d M Y H:i:s",time() + $offset)." GMT";
    header($ExpStr);
    header('Content-Type: text/css');
    include("../../../wp-config.php");
    ?>

    주석처리된 설명을 보시면 왜 위의 코드가 필요한지를 아실 수 있습니다.

    추가
    질문하신 내용으로 미루어보아.. 페이지마다 메뉴의 css스타일을 다르게 하려고 하시는듯 한데.. 맞나요?

    그렇다면 위 과정을 거치는것 보다는 페이지 리스트를 wp_list_pages() 를 이용해서 나열하는 방법이 더 효과적일듯 합니다.
    (참고페이지: http://codex.wordpress.org/Template_Tags/wp_list_pages)
    이 방법을 이용하면 현재의 페이지의 class가 ‘current_page_item’이 되고 나머지 페이지 메뉴들의 class는 ‘page_item’이 됩니다.
    .current_page_item { } 의 스타일만 다르게 지정해 주시면 되네요. 아래는 k2테마에서 상단부분에 페이지메뉴를 나열한 방법입니다. 한번 살펴보세요.

    <ul class="menu">
    <li class="<?php if (((is_home()) && !(is_paged())) or (is_archive()) or (is_single()) or (is_paged()) or (is_search())) { ?>current_page_item<?php } else { ?>page_item<?php } ?>"><a href="<?php echo get_settings('home'); ?>" title="Blog Home">Blog</a></li>
    <?php wp_list_pages('sort_column=menu_order&depth=1&title_li='); ?>
    </ul>

    질문하신 내용에 있는 css스타일은 아래처럼 됩니다.

    ul.menu li.page_item {
    /* 기본적인 메뉴 스타일 */
    }

    ul.menu li.current_page_item {
    background-position: 0 -32px; /* 헌재 페이지의 스타일 */
    }

    Avatar of 082net
    Facebook 사용자 모임 그룹 도 함께 운영되고 있으며, 격 주로 미트업과 스터디를 진행하고 있으니 관심 있으신 분들의 많은 참여 바랍니다 🙂
    익명
    손님
    @
    #938

    <?php
    if ( is_page('contact') ) { $current = 'contact'; }
    elseif ( is_page('works') ) { $current = 'works'; }
    elseif ( is_page('home') ) { $current = 'home'; }
    else { $current = 'test'; }
    ?>

    background-position: 0 -32px;
    }

    우선, 답변감사합니다. 많은 도움됐습니다 (__

    <?php
    /*
    The headers below tell the browser to cache the file and also tell the browser it is css.
    */
    header("Cache-Control: must-revalidate");
    $offset = 60*60*24*60;
    $ExpStr = "Expires: ".gmdate("D, d M Y H:i:s",time() + $offset)." GMT";
    header($ExpStr);
    header('Content-Type: text/css');
    include("../../../wp-config.php");
    ?>

    이부분을 입력하니 값을 제대로 받아오는 것 같습니다.
    다마, 작성한 페이지의 경우에는 예를들어 contact라는 페이지의 경우

    if ( is_page('contact') ) { $current = 'contact'; }

    이렇게 기재되어 있음에도 불구하고..
    else { $current = ‘test’; } 이 항목의 값만 출력이 됩니다.

    다른소스코드로는 index.php나 single.php는 다르게 적용이 됩니다.

    작성한 페이지의 값을 전달받을 방법은 없을까요..?

    익명
    손님
    @
    #942

    <?php
    if ( is_page('contact') ) { $current = 'contact'; }
    elseif ( is_page('works') ) { $current = 'works'; }
    elseif ( is_page('home') ) { $current = 'home'; }
    else { $current = 'test'; }
    ?>

    background-position: 0 -32px;
    }

    우선, 답변감사합니다. 많은 도움됐습니다 (__

    <?php
    /*
    The headers below tell the browser to cache the file and also tell the browser it is css.
    */
    header("Cache-Control: must-revalidate");
    $offset = 60*60*24*60;
    $ExpStr = "Expires: ".gmdate("D, d M Y H:i:s",time() + $offset)." GMT";
    header($ExpStr);
    header('Content-Type: text/css');
    include("../../../wp-config.php");
    ?>

    이부분을 입력하니 값을 제대로 받아오는 것 같습니다.
    다마, 작성한 페이지의 경우에는 예를들어 contact라는 페이지의 경우

    if ( is_page('contact') ) { $current = 'contact'; }

    이렇게 기재되어 있음에도 불구하고..
    else { $current = ‘test’; } 이 항목의 값만 출력이 됩니다.

    다른소스코드로는 index.php나 single.php는 다르게 적용이 됩니다.

    작성한 페이지의 값을 전달받을 방법은 없을까요..?

    익명
    손님
    @
    #939

    <?php
    if ( is_page('contact') ) {
       $current1 = 'contact';
    } else {
       $current1 = 'conspiracy';
    }
    ?>

    이 경우 contact 페이지로 넘어갔을 경우 3개 값을 출력해야 하는데
    single나 index, archive는 else값이 출력이 되나 contact페이지에서는 값이 출력되지 않습니다.

    익명
    손님
    @
    #943

    <?php
    if ( is_page('contact') ) {
       $current1 = 'contact';
    } else {
       $current1 = 'conspiracy';
    }
    ?>

    이 경우 contact 페이지로 넘어갔을 경우 3개 값을 출력해야 하는데
    single나 index, archive는 else값이 출력이 되나 contact페이지에서는 값이 출력되지 않습니다.

9 글 보임 - 1에서 9 까지 (총 9 중에서)
  • 답변은 로그인 후 가능합니다.