idに基づいて作成者プロファイルを表示するショートコードを作成しました。たとえば、[user-profile id = "1"]は、作成者1のuser-profile.phpで定義されたプロファイルブロックを表示します。これは機能しました(同じページに複数のインスタンスがある場合でも)。
function user_profile( $atts, $content = null ) {
extract(shortcode_atts(array('id' => ''), $atts));
include 'user-profile.php';
}
...コード内の場所に関係なく、ショートコード出力が他のエントリコンテンツの前に表示されていた場合を除きます。これを解決するために、私はこの修正を追加しました:
function user_profile( $atts, $content = null ) {
extract(shortcode_atts(array('id' => ''), $atts));
function get_user_profile() { include 'user-profile.php'; }
ob_start();
get_user_profile();
$output_string = ob_get_contents();
ob_end_clean();
return $output_string;
}
...これはポジショニングの問題を解決するために機能しましたが、ショートコードの複数のインスタンスを壊しました。[user-profile id = "1"]は機能しますが、[user-profile id = "1"] [user-profile id = "2"]は機能しません。その時点で、ページの読み込みが停止します。
複数のインスタンスを許可するようにこれを変更するにはどうすればよいですか?