私はWordPress(duh)を使いこなしています。サブページからの添付ファイルの呼び出しと表示 - WordPress
私はいくつかのサブページを持っています。それぞれのサブページには画像が添付されています。私はこれらの画像を表示したいだけです。クライアントは定期的にさらに多くのサブページを追加するので、コードは自己のイメージだけを表示することを知っている必要があります。実行中の問題はです。それぞれサブページが表示されます。すべて添付ファイルすべてサブページです。私はすべての私の通常のページのIfステートメントを、持っている私のpage.php
で
//find out if it is a suppage to use in page.php as function 'is_subpage'
function is_subpage() {
global $post; // load details about this page
if (is_page() && $post->post_parent) { // test to see if the page has a parent
return $post->post_parent; // return the ID of the parent post
} else { // there is no parent so ...
return false; // ... the answer to the question is false
}
}
:私のFunctions.php
で
は、私は、ページがInfactはサブページであるかどうかを判断するには、このコードを持っています。それは、この中で絶頂に達する:exhibition-template.php
で
elseif (is_subpage()) {
get_template_part('exhibition-template');
get_template_part('normalfooter');
}
、私は私のイメージは、私がこれを持って表示したい場所:
<?php
if (is_subpage($post->ID)) { //I think I screwed up here, innermost brackets
$args = array(
'order' => 'ASC',
'post_type' => 'attachment',
'post_parent' => $post->ID, //or is my issue here...?
'post_mime_type' => 'image',
'post_status' => null,
'numberposts' => -1,
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
echo wp_get_attachment_link($attachment->ID, 'large', false, false);
}
}
}
?>
しかし、何が起こるかはそれぞれ、すべてのサブページは、単純にすべてのサブページ間ですべての画像を表示していますそして、率直に言って、私は進歩する方法や、何をどこで始めるべきかを知ることができない。 アイデア
を私はあなたの新しい友人、のvar_dump()http://php.net/manual/en/function.var-dump.phpをご紹介しましょう。これはあなたの
exhibition-template.php
が見ることができる方法です。最初に、あなたの関数内でどの条件が満たされているかを調べるために、条件式の中にvar_dumpedを出すために何かを含めることにします。それから私はあなたの展示用テンプレートに$ post-> IDが何であるか、つまりvar_dump($ post-> ID)が分かっていることを確認します。 –ありがとう - 私は、デバッグ/エラー/アウトプットが実際にどこに出現するのでしょうか? –