【问题标题】:WordPress mouse over text with background color?WordPress鼠标悬停在带有背景颜色的文本上?
【发布时间】:2015-09-23 05:08:55
【问题描述】:

我是 wordpress 新手,使用的是 4.2.2 版本。我需要在背景颜色上显示鼠标,并在图像上显示文字。给定的文本和图像是从管理面板动态生成的。我提供了以下图片供您参考,第一张图片现在我有我的网站,下一张图片我需要这样做。

提前致谢!

【问题讨论】:

  • Text on image mouseover?的可能重复
  • 这里已经有一个fiddle了。 jsfiddle.net/4LjeL/2
  • 谢谢 sagar,我会检查一下这个以及如何集成到 WordPress 中。
  • 我使用的是 enfold 主题,我不知道哪个文件可以显示输出。这是我的网站和我的页面,(ef.efvoice.com/ef/?page_id=132)我需要知道文件路径。请告诉我。我为此苦苦挣扎了几天。
  • 最后我用 css 编写并用文本显示鼠标。感谢大家的支持。

标签: php jquery css wordpress


【解决方案1】:

您可以将此功能用于wordpress

<?php wp_get_attachment_image( $attachment_id, $size, $icon, $attr ); ?>

<?php wp_get_attachment_metadata( $attachment_id, $unfiltered ); ?>

这是法典

https://codex.wordpress.org/Function_Reference/wp_get_attachment_image https://codex.wordpress.org/Function_Reference/wp_get_attachment_metadata

有了这个,你可以得到图像的名称,并像 Sagar 所说的那样显示

你将在你的页面中使用它,而不是在你的functions.php中

你在函数中不会是这个,你会在你的页面中使用这个,像这样

<?php 
     $my_query = new WP_Query('post_type=eventos&category_name=galeria_evento&posts_per_page=1');
                    while ($my_query->have_posts()) : $my_query->the_post(); 
                        ?>

                    <?php
                        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                        $args = array(
                                        'post_type' => 'attachment',
                                        'post_parent' => $post->ID,
                                        'numberposts' => -1,
                                        'paged' => get_query_var('paged'),
                                        'exclude' => get_post_thumbnail_id()
                                    );

                   // making the list of the attachments
                        $attachments = get_posts( $args );
                        if ( $attachments ) {
                            foreach ( $attachments as $attachment ) {
                            // getting the image and title of the attachment
                            echo "<div class='item-slide'><p class='title-slide'>".apply_filters( 'the_title', $attachment->post_title )."</p>".wp_get_attachment_image( $attachment->ID, 'full' )."</div>";                                
                            }
                        }
                    ?>


            <?php endwhile; ?>

【讨论】:

  • 图片来自wordpress页面,我如何才能包含这些功能。我想我需要编辑页面或模板文件才能正确放置这些功能?然后我需要找到适用于这些页面的 css 文件并包含 css 代码对吗?我很困惑在哪个文件中编写代码。
  • 不,你不需要更改太多代码,只需使用foreach获取附件,并使用wp_get_attachment_meta($id)获取foreach中关于附件的属性,有一次我会找到我在哪里使用它并将代码放在这里
  • 在侧主题中,我需要在哪个文件中添加这个功能
  • 我找到了文件的地方,这里已经有这个功能了。这是 post.php 文件中的函数。函数 wp_get_attachment_metadata( $post_id = 0, $unfiltered = false ) { $post_id = (int) $post_id;如果 ( !$post = get_post( $post_id ) ) 返回 false; $data = get_post_meta($post->ID, '_wp_attachment_metadata', true ); if ( $unfiltered ) 返回 $data;返回 apply_filters('wp_get_attachment_metadata', $data, $post->ID); }
  • 你正在获取标题,现在你只需在“媒体”选项卡中的 wordpress 内的图片中添加一个标题
猜你喜欢
  • 1970-01-01
  • 2015-07-26
  • 1970-01-01
  • 1970-01-01
  • 2012-03-29
  • 2013-01-23
  • 2020-02-14
  • 2011-04-04
  • 1970-01-01
相关资源
最近更新 更多