我正在使用“flexise”幻灯片脚本自动滚动图像列表。该列表与wordpress模板页中的脚本一起硬编码。
虽然这样做很好,但您如何使幻灯片能够将任何图像添加到特殊(私有)wordpress页面,而不必手动添加每个img src??
<ul id="flexiselDemo3">
<li><img src="http://mysite.com/wp-content/uploads/2014/02/logo.png" /></li>
<li><img src="http://mysite.com/wp-content/uploads/2014/02/logo2.png" /></li>
<li><img src="http://mysite.com/wp-content/uploads/2014/02/logo3.png" /></li>
</ul>
非常感谢
现在尝试您的建议,我已将上述内容替换为:
$attachments = get_posts(array(
\'post_type\' => \'attachment\',
\'numberposts\' => -1,
\'post_status\' =>\'any\',
// This is where you specify the ID of your private image page
\'post_parent\' => 6909,
));
if (count($attachments)) {
// We have attachments
?>
<ul id="flexiselDemo3">
<?php
// Now we loop through them
foreach ($attachments as $attachment) {
?>
<li>
<?php echo wp_get_attachment_image($attachment->ID, \'full\'); ?>
</li>
<?php
}
?>
</ul>
<?php
}
但这是一个错误。可能很简单,但我没有足够的调试经验?
Parse error: syntax error, unexpected \'<\' in /home4/speedyp/public_html /speedypancake.com/tmc/wp-content/themes/sirens/page_f.php
最合适的回答,由SO网友:tfrommen 整理而成
其中大部分是Codex:
<?php
$attachments = get_posts(array(
\'post_type\' => \'attachment\',
\'numberposts\' => -1,
\'post_status\' =>\'any\',
// This is where you specify the ID of your private image page
\'post_parent\' => $private_page_id,
));
if (count($attachments)) {
// We have attachments
?>
<ul id="flexiselDemo3">
<?php
// Now we loop through them
foreach ($attachments as $attachment) {
?>
<li>
<?php echo wp_get_attachment_image($attachment->ID, \'full\'); ?>
</li>
<?php
}
?>
</ul>
<?php
}
?>