【问题标题】:Adding a div box / with Button under Featured Image in posts在帖子的特色图片下添加一个 div 框/带有按钮
【发布时间】:2012-03-16 17:33:01
【问题描述】:

我已经设法添加了一个“特色图片”,它会在我的 Wordpress 网站主页上填充每个帖子摘录的左侧。类似于它出现在这个网站上的方式:http://tinyurl.com/y8tk6oq BUT!我正在尝试添加一个 div / 按钮以显示在它的下方,占用我的图像的宽度,只需一点点填充。我很想在这个工作代码中添加,以便它在我的所有帖子中显示相同,并且我会单独使用每个代码来添加相应的单独链接。

我已经多次尝试复制下面的工作,但使用 DIV,在下面重新定位,但仍然没有这样的运气。

 <?php if($image= get_post_meta($post->ID, "image", true)) { ?>
                        <div class="postImage">
                        <img class="postImg" src="<?php echo $image; ?>" /> 
                        </div>                    
                    <?php } else if($isbn= get_post_meta($post->ID, "isbn", true)) { ?>
                        <div class="postImage">


                        <img class="postImg" src="http://www.randomhouse.com/images/dyn/cover/?source=<?php echo $isbn; ?>&height=225&maxwidth=150" />

                        </div>

                <?php } else { print"<div>";}?>    

【问题讨论】:

  • 按钮会链接到帖子,还是您希望每个按钮链接到不同的自定义 URL?
  • 是的。不幸的是,另一个自定义 URL。但我想稍后再考虑一下,我正在考虑只是浮动一个文本链接。但是,此时我只想让 div 在每个下方填充。

标签: php html css wordpress


【解决方案1】:

如果你只想添加一个按钮,你可以在循环中添加一个锚点。我添加了一个类为 readmore 的按钮,然后您可以将 CSS 规则应用到该按钮。

 <?php if($image= get_post_meta($post->ID, "image", true)) { ?>
                    <div class="postImage">
                    <img class="postImg" src="<?php echo $image; ?>" /> 
                    </div>                    
                <?php } else if($isbn= get_post_meta($post->ID, "isbn", true)) { ?>
                    <div class="postImage">


                    <img class="postImg" src="http://www.randomhouse.com/images/dyn/cover/?source=<?php echo $isbn; ?>&height=225&maxwidth=150" />
                    <a href="<?php the_permalink(); ?>" class="readmore">Read More</a>
                    </div>

            <?php } else { print"<div>";}?>    

编辑:如果您不想链接到帖子的永久链接,而是想逐个帖子链接到您选择的外部 URL,您可以通过使用自定义字段来实现。查看this article 了解操作方法。

【讨论】:

  • 我刚刚试过你的代码,这也是我最初的想法。对接!它没有用,只是尝试将样式设置为: .readmore { background-color: #333;宽度:225px;高度; 50像素; }
  • 下面什么也没有显示。
  • 链接是否出现在呈现的 HTML 源代码中?
  • 注意,我编辑了我的原始答案并添加了有关链接到自定义 URL 而不是永久链接的信息。
  • 我尝试使用上面评论的样式再次设置样式,但仍然没有 div 出现您建议的代码作为答案。我和我的尝试一样碰壁......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-28
  • 2013-10-04
  • 2015-04-03
  • 2015-04-08
  • 2018-04-28
相关资源
最近更新 更多