2011-01-07 2 views
0

내 짧은 코드가 작동하지 않는 이유를 알아 내려고 노력하고 있습니다. 누구나 왜 엉뚱한 서식에 사과하니 적절하게 표시 할 수 없습니까?Wordpress : 단축키에 템플릿 태그 및 기능 사용

어떤 이유로 코드가 내 짧은 코드 위에 있습니다. 잘 모르겠지만 템플릿 태그/WP 함수를 shortcodes로 사용하는 방법을 완전히 이해했다면 shortcodes 내의 변수에 반환하기 위해 함수의 처음에 get_과 같은 것을 사용해야한다고 생각합니다. 누구든지 도와 줄 수 있습니까? 내가 제대로 이해하면

감사

OSU

/* News from Blog category only - category 3 */ 

add_shortcode('latestblogposts', 'osu_latestblogposts'); 

function osu_latestblogposts() { 
    $start = '<div class="widget widget_osu_blog">'; 
    $start .= '<a title="Subscribe to our RSS feed" href="/feed?cat=3" class="rss"><img alt="RSS" src="' . get_bloginfo('template_directory') . '/images/ico-rss-big.png"></a>'; 
    $start .= '<div>'; 

    $my_query = new WP_Query('category=3&showposts=3'); 
    while ($my_query->have_posts()) : $my_query->the_post(); 
     $inner = '<div class="item"><a href="' . get_permalink() . '" title="'; 
     $inner .= printf(esc_attr__('Permalink to %s', 'inspire'), the_title_attribute('echo=0')); 
     $inner .= '" rel="bookmark" class="title">' . the_title() . '</a>'; 
     $inner .= '<p class="post-meta">'; 
     $inner .= '<span class="small">by</span> <span class="post-author"><a title="Posts by '; 
     $inner .= the_author(); 
     $inner .= '" href="' . the_author_posts_link() . '">' . the_author() . '</a></span>'; 
     $inner .= '<span class="small">on</span> <span class="post-date">'; 
     $inner .= get_the_date('d/m/Y') . '</span></p>'; 
     $inner .= the_excerpt() . '</div> <!-- End div.item -->'; 
    endwhile; 

    $end = '</div>'; 
    $end .= '</div> <!-- End div.widget_osu_blog -->'; 

    $latestblogposts = $start . $inner . $end; 
    return $latestblogposts; 
} 

답변

0

, 당신은 직접 에코 대신 반환 값을 얻기 위해 선택적 인수로 함수를 호출 할 필요가있다. 예를 들어 the_title()을 사용하면 3 개의 선택적 인수가 있고 세 번째 인수는 출력을 설정합니다 (기본값은 true). the_title().

다른 값의 경우 사용자가 호출하는 기능을 변경해야합니다. the_author()는 항상 값을 표시하고 (echo), 대신 get_the_author()를 호출해야합니다.

+0

또한 get_the_excerpt()에 대해 "the_excerpt()"를 변경해야합니다. – AJJ

+0

안녕하세요 AJweb, 저에게 다시와 주셔서 감사합니다 - 당신은 머리에 못을 박았. 이러한 것들의 대부분 전에 get_를 사용하는 간단한 경우입니까? 사용 가능한지 확인하기 위해 이러한 각 기능의 코덱을 검사해야한다고 가정합니다. 짧은 코드에도 루프를 넣는 깔끔한 방법이 있다고 확신합니다! – Osu

+0

맞아, 나는 코덱스에서 함수를 검사 할 필요가 있을까 두렵다. 함수 이름에 get_을 추가하는 경우가 항상있는 것은 아니다 (the_title()이 그 예이다). – AJJ