【问题标题】:PHP + HTML - Please help me put this things together [closed]PHP + HTML - 请帮我把这些东西放在一起[关闭]
【发布时间】:2015-06-26 07:32:02
【问题描述】:

我有这段代码来显示帖子(代码效果很好)。

...if( $posts ): 

<ul>

<?php foreach( $posts as $post ): 

    setup_postdata( $post )

    ?>
    <li>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><p>
    </li>

<?php endforeach; ?>

</ul>
<?php endif; ?>
<?php wp_reset_postdata(); ?>

我打算使用此代码使帖子链接显示为“幻灯片” http://fiddle.jshell.net/vac9x/1/ 但我不知道如何将它们放在一起。

基本问题是“幻灯片”一次会显示3个帖子链接,当我点击下一步时,它会显示另外3个等等,我该如何解决?

【问题讨论】:

    标签: php html wordpress


    【解决方案1】:

    所以您只希望一次显示 1 个帖子链接?下面的代码基于小提琴示例中的滑块布局。您可以根据您的设计要求以多种不同的方式编写 html 标记。

    <a href="#" id="prev2">Prev</a>
    <div class="pics" id="s2" style="position: relative;">
       <?php foreach( $posts as $post ): 
    setup_postdata( $post ) ?>
    <div><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
    <?php endforeach; ?>
    <?php endif; ?>
    <?php wp_reset_postdata(); ?> 
           </div>           
           <a href="#" id="next2">Next</a>
    

    【讨论】:

    • 一次没有 2 个帖子的 id
    【解决方案2】:

    已解决 - 方法如下:

    ...if( $posts ): ?>
    
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
    <script type="text/javascript" src="http://malsup.github.com/chili-1.7.pack.js"></script>
    <script type="text/javascript" src="http://malsup.github.com/jquery.cycle.all.js"></script>
    <script type="text/javascript" src="http://sitewiththescript.com/theextrascript.js"></script>
    
    <a href="#" id="prev2">Prev</a>
    <div class="pics" id="s2" style="position: relative;">
    
    <?php $i = 0; foreach( $posts as $post ): setup_postdata( $post )?>
    <?php if ($i == '0') {echo '<div>';} else {};?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php if ($i == '1') {echo '</div>';} else {$i++;};?>
    <?php if ($i == '2') {$i == '0';} else {};?>
    
    <?php endforeach; ?>
    <?php endif; ?>
    </div>           
    <a href="#" id="next2">Next</a>
    <?php wp_reset_postdata(); ...
    

    【讨论】:

      猜你喜欢
      • 2013-12-23
      • 1970-01-01
      • 1970-01-01
      • 2013-02-03
      • 1970-01-01
      • 2011-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多