0

我正在尝试做自己的滑块。我快完成了,但我需要将我的链接网址显示为标题或其他内容。

我应该添加什么来获取链接和显示?这是我的代码

<?php
  // The Loop
      while ( $the_query->have_posts() ) : $the_query->the_post(); ?><li>

          <?php 
           // Check if there's a Slide URL given and if so let's a link to it
              if ( get_post_meta( get_the_id(), 'wptuts_slideurl', true) != '' ) { ?>
                <a href="<?php echo esc_url( get_post_meta( get_the_id(),'wptuts_slideurl', true) ); ?>">

          <?php }
            // The Slide's Image
              echo the_post_thumbnail();

            // Close off the Slide's Link if there is one
              if ( get_post_meta( get_the_id(), 'wptuts_slideurl', true) != '' ) { ?>
              </a> <?php } ?> </li>

<?php endwhile; ?>
4

1 回答 1

0

您将数据库中的 URL 作为字符串回显,该字符串放置在<a>标记中。这意味着您可以在任何地方回显它。尝试这样的事情:

// Close off the Slide's Link if there is one
if ( get_post_meta( get_the_id(), 'wptuts_slideurl', true) != '' ) { ?>
  </a>
  // Add a <span> element which includes the exact same url as your link
  <span class="your-slide-url">
    <?php echo get_post_meta( get_the_id(), 'wptuts_slideurl', true); ?>
  </span>
<?php } ?>

现在,您可以随意设置样式<span class="your-slide-url">

于 2013-01-25T14:18:27.560 回答