0

ショートコードが機能しない理由を突き止めようとしています - 誰でもその理由を理解できますか?

何らかの理由でコードがショートコードの上で実行されています。ショートコード内の変数で返すには、関数の先頭で get_ のようなものを使用する必要があると思われるため、ショートコードでテンプレートタグ/WP関数を使用する方法を完全に理解しているかどうかはわかりません。誰でも助けることができますか?

ありがとう

大須

/* 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;
}
4

1 に答える 1

0

私があなたを正しく理解していれば、直接エコーするのではなく、戻り値を取得するためにオプションの引数を指定して関数を呼び出す必要があります。たとえば、the_title() には 3 つのオプション引数があり、3 番目は出力を設定します (デフォルトは true)。 タイトル()。

他の値については、呼び出す関数を変更する必要があります。the_author() は常に値を表示 (エコー) します。代わりに get_the_author() を呼び出す必要があります。

于 2011-01-07T18:53:18.393 に答える