我不是PHP,javascript和js的专家;所以我希望有人可以用简单的语言来帮助我。我刚刚开发了我的第一个wordpress网站并且使用这个论坛极大地改变了代码 - 到目前为止感谢堆!
网站:http://www.heritageglass.com.au
我的请求:文字(媒体库中的图片说明)悬停在图片上。
就像这个website或此plugin一样,我在这个网站上发现了一些问题,但是他们似乎没有帮助,或者我不知道在哪里放置这是因为它抓住了the_title
而我想要the_description
。有这样一个词吗?
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>
我发现了这个:Text over image using jquery and css 并在header.php中添加了脚本。并使用我的.portfolio-item和.portfolio-item-img而不是.wrapper和.description - 但这没有做任何事情。
希望有人能带领我朝着正确的方向前进?
谢谢!
答案 0 :(得分:0)
在WordPress forums上搜索我从四年前发现这一点,不确定这是否是您需要的,但它可能会指向正确的方向。
$img_desc = $image->post_excerpt;
答案 1 :(得分:0)
我认为它会对你有帮助....
答案 2 :(得分:0)
编辑帖子时,添加两个自定义字段,一个用于标题,一个用于描述。 你的代码是这样的:
$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>
答案 3 :(得分:0)
经过大量的研究,我找到了答案。
这就是答案:How do I get the featured image description from my wordpress page?
输入the_post_thumbnail_caption();在span标记内,并在css中设置span标记类。
进行。
感谢各位的帮助!