简体   繁体   English

将鼠标悬停在图像上的图像描述

[英]Hover image description on image

I am no expert in PHP, javascript and js; 我不是PHP,javascript和js方面的专家; so I am hoping someone can help me in easy language terms. 所以我希望有人可以用简单的语言帮助我。 I have just developed my first wordpress site and changed the code immensely, using this forum - thanks heaps so far! 我刚刚使用此论坛开发了我的第一个wordpress网站并极大地更改了代码-到目前为止,谢谢!

The site: http://www.heritageglass.com.au 该网站: http//www.heritageglass.com.au

My request: text (description of image in media library) hovering over image. 我的要求:将文本(媒体库中图像的描述)悬停在图像上。

Just like this website or this plugin , I have found several questions on this site that refer to my issue but they haven't seemed to help or I don't exactly know where to place this as it's grabbing the_title and I want the_description . 就像这个网站或这个插件一样 ,我在这个网站上发现了几个有关我的问题的问题,但是它们似乎并没有帮助,或者我不知道将其放置在哪里,因为它抓住了the_title ,我想要the_description Is there such a term? 有这样的名词吗?

PHP code in portfolio.php template: Portfolio.php模板中的PHP代码:

<div data-id="post-<?php the_ID(); ?>" data-type="<?php
  $categories = get_the_category();
  $count = count($categories);
  $i=1;
  foreach($categories as $category) {
      echo str_replace('-', '', $category->slug);
      if ($i<$count) echo ' '; $i++;} ?>" class="post-<?php the_ID(); ?>
      <?php
        $categories = get_the_category();
        foreach($categories as $category) {
            echo str_replace('-', '', $category->slug).' '; } ?> project portfolio-item-wrap">
    <div class="portfolio-item">
        <?php if ( has_post_thumbnail() ) { ?>
        <a class="portfolio-item-img" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail( 'portfolio-image' ); ?></a>
        <?php } ?>


        <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
        <p>
            <?php
            $categories = get_the_category(); 
            $temp = array();
            foreach($categories as $category) {
                if ($category->category_parent == 0) continue;
                $temp[] = str_replace('-', '', $category->name); 
            } 
            echo implode(", ", $temp);
            ?>
        </p>
    </div>
</div>

I found this: Text over image using jquery and css and added the script in the header.php. 我发现了这一点: 使用jquery和css在图像上输入文本 ,并将脚本添加到header.php中。 And used my .portfolio-item and .portfolio-item-img instead of .wrapper and .description - but that didn't do anything. 并使用了我的.portfolio-item和.portfolio-item-img而不是.wrapper和.description-但这没有任何作用。

Hoping someone can lead me in the right direction? 希望有人可以将我引向正确的方向?

Thanks! 谢谢!

在四年前我在WordPress论坛上进行搜索时,不确定是否是您需要的,但这可能会为您指明正确的方向。

$img_desc = $image->post_excerpt;

When editing a post, add two custome field, one for title, one for descritption. 编辑帖子时,添加两个定制字段,一个用于标题,一个用于描述。 Our code goes like this: 我们的代码如下所示:

$dataType = '';
$divClass = '';

$categories = get_the_category();
$count = count($categories); 
$i=1; 
foreach($categories as $category) {
    $dataType .= str_replace('-', '', $category->slug); 
    $divClass .= str_replace('-', '', $category->slug).' ';
    if ($i<$count) $dataType.= ' ';
    $i++;
}

$metaList = get_post_meta(get_the_ID());
$title = isset($metaList['title']) ? $metaList['title'] : '';
$description = isset($metaList['description']) ? $metaList['description'] : '';

// now we have title and description for the thumb!
?>
<div data-id="post-<?php the_ID(); ?>" data-type="<?php echo $dataType;?>"
    class="post-<?php the_ID(); echo $divClass;?>  project portfolio-item-wrap">
    <div class="portfolio-item">
        <?php if ( has_post_thumbnail() ) { ?>
            <a class="portfolio-item-img" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                <?php the_post_thumbnail( 'portfolio-image' ); ?>
            </a>
        <?php } ?>


        <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
        <p>
            <?php
                $temp = array();
                foreach($categories as $category) {
                    if ($category->category_parent == 0) continue;
                    $temp[] = str_replace('-', '', $category->name); 
                } 
                echo implode(", ", $temp);
            ?>
        </p>
    </div>
</div>

I have found the answer after sooooo much research. 经过大量研究,我找到了答案。

This is the answer: How do I get the featured image description from my wordpress page? 答案是: 如何从我的wordpress页面上获得特色图像描述?

enter the the_post_thumbnail_caption(); 输入the_post_thumbnail_caption(); within the span tags and set your span tags class in css. 在span标签中,并在CSS中设置您的span标签类。

done. 完成。

Thanks to all of you for your help! 感谢大家的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM