Wordpress PHP条件
我的主页有一个垂直滑块,在主页顶部显示5篇文章的标题。显示的每个帖子都有一个背景图像显示在其后面。它目前运行良好,尽管我希望在每个帖子显示后面显示不同的背景图像。我不知道如何使用PHP代码实现这一点。我已经发布了下面的代码,显示了包含JCarousel功能的文件。我猜我需要设置某种类型的条件,允许新的背景图像与每个“列表”项一起显示 代码如下:Wordpress PHP条件,php,wordpress,Php,Wordpress,我的主页有一个垂直滑块,在主页顶部显示5篇文章的标题。显示的每个帖子都有一个背景图像显示在其后面。它目前运行良好,尽管我希望在每个帖子显示后面显示不同的背景图像。我不知道如何使用PHP代码实现这一点。我已经发布了下面的代码,显示了包含JCarousel功能的文件。我猜我需要设置某种类型的条件,允许新的背景图像与每个“列表”项一起显示 代码如下: <div id="home-gallery-wrapper"> <ul id="home-gallery" class="jcarou
<div id="home-gallery-wrapper">
<ul id="home-gallery" class="jcarousel-skin-home clearfix">
<?php
global $post;
if ( get_option('minimax_hl_show') == '1' ) {
$my_query = get_pages('include='.get_option('minimax_hl_ID').'');
} else {
$my_query = get_posts('include='.get_option('minimax_hl_ID').'');
}
foreach($my_query as $post) :
setup_postdata($post);
?>
<li style="width:910px"><div style="
background:url('<?php bloginfo('template_directory'); ?>/images/banner3.png')
center top no-repeat;">
<table align="center" style="width:910px;
height:200px">
<tr>
<td style="vertical-align:top">
<div style="width:90%; display:block; margin-left:auto; margin-right:auto">
<h2 style="text-align:center; border:none; text-decoration:none; font-family:calligraffiti;
margin-top:15px; font-size:1.8em; line-height:35px; color:#fff; position:relative; z-index:10">
<a style="color:#fff; border:none; text-decoration:none"
title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink(); ?>"
rel="bookmark"><?php the_title(); ?></a></h2>
</div>
</td></tr>
</table></div>
<?php
$key="show-video";
if ( get_post_meta($post->ID, $key, true) != '' ) {
?>
<div class="video"><?php echo get_post_meta($post->ID, $key, true); ?></div>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("embed").attr("wmode", "transparent");
});
</script>
<?php
} else if ( has_post_thumbnail() ) {
?>
<a title="Permanent Link to <?php the_title(); ?>"
href="<?php the_permalink() ?>"><?php the_post_thumbnail(); ?></a>
<?php } ?>
</li>
<?php
endforeach;
?>
</ul>
</div><!-- end home-gallery-wrapper -->
<script type="text/javascript">
function mycarousel_initCallback(carousel)
{
// Disable autoscrolling if the user clicks the prev or next button.
carousel.buttonNext.bind('click', function() {
carousel.startAuto(0);
});
carousel.buttonPrev.bind('click', function() {
carousel.startAuto(0);
});
// Pause autoscrolling if the user moves with the cursor over the clip.
carousel.clip.hover(function() {
carousel.stopAuto();
}, function() {
carousel.startAuto();
});
};
jQuery(document).ready(function() {
jQuery('#home-gallery').jcarousel({
vertical: true,
scroll: 1,
easing: 'easeInOutBack',
auto: 2,
wrap: 'last',
initCallback: mycarousel_initCallback,
animation: 800
});
});
</script>
- 用您选择的颜色创建5个不同的横幅,并将它们命名为banner1.png、banner2.png、banner3.png等
然后替换
foreach($my_query as $post) :
setup_postdata($post);
?>
<li style="width:910px"><div style="
background:url('<?php bloginfo('template_directory'); ?>/images/banner3.png')
center top no-repeat;">
foreach($my_query as$post):
设置_postdata($post);
?>
- 本网站也位于阿南德,我的朋友,你真是太棒了!所以我假设你在“列表”中设置了一个增量。对吗?你能解释一下你在这方面的想法吗。我喜欢学习这些东西,因为我还是新手。还有,为什么你要把增量放在代码中的“banner”和“.png”之间?啊,PHP和它的疯狂力量!是的,我在列表中设置了增量<代码>/images/banner.png
当PHP在发送到浏览器之前对其进行求值时,会变成/images/banner1.png
。$i
的值最初设置为0,然后在赋值时递增,因此在第一个循环中它将是1,然后是2,3等等。
$i = 0;
foreach($my_query as $post) :
setup_postdata($post);
?>
<li style="width:910px"><div style="
background:url('<?php bloginfo('template_directory'); ?>/images/banner<?php $i++; ?>.png')
center top no-repeat;">