【问题标题】:Hover on specific post should show the title of only that post悬停在特定帖子上应仅显示该帖子的标题
【发布时间】:2011-04-06 00:02:54
【问题描述】:

我正在为我的网站使用 Wordpress。我想要实现的是,如果我将鼠标悬停在特定帖子上,它应该显示该帖子的标题。但它现在所做的是,如果我将鼠标悬停在一篇文章上,它会显示所有文章的标题。

代码:

<?php if (have_posts()) : ?>

        <?php while (have_posts()) : the_post(); ?>

        <div class="post">
            <div>

                <div class="post-header"><a href="<?php the_permalink() ?>">
                <?php if ( p75HasThumbnail($post->ID) ) { ?>
                    <img src="<?php echo p75GetThumbnail($post->ID, 200, 108); ?>" alt="<?php the_title(); ?>" width="200" height="108" />
                <?php  } ?>
                </a></div>

       <div class="post-content" style="display:none;">
                    <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>    
                </div>

                <div class="post-footer">
                    <small>
                    In: <?php the_category(' | ') ?>
                    </small>
                </div>
            </div>

        </div>
        <!--    -->


    <?php endwhile; ?>


    <?php next_posts_link('<div class="post archiveTitle "><div>&larr; Older</div></div>') ?>
    <?php previous_posts_link('<div class="post archiveTitle "><div>Newer &rarr;</div></div>') ?>


    <?php else : ?>

    <div class="post">
        <div>
            <h1>Not Found</h1>
            <p>Sorry, but you are looking for something that isn't here.</p>
        </div>
     </div>

    <?php endif; ?>

JS:

<script type="text/javascript" charset="utf-8">
    $(document).ready(function() {
        $('.post-header').hover(function(){
            $('.post-content').show();
        }, function(){
            $('.post-content').hide();    
        });
    });
    </script>

【问题讨论】:

    标签: php jquery wordpress hover


    【解决方案1】:

    我不确定,如果是这样,你想达到什么:

    $('.post-header').hover(function(){
        $('.post-content', $(this).parent()).show();
    }, function(){
        $('.post-content').hide();    
    });
    

    现在只显示当前悬停的帖子的帖子内容。

    【讨论】:

      猜你喜欢
      • 2015-04-24
      • 2021-03-27
      • 2021-04-01
      • 2013-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多