簡體   English   中英

如何創建頁面特定鏈接

[英]How to create a page specific link

我創建了一個圖標並想知道如何使其特定於頁面。 我正在使用 WordPress,因此 html 是通過主頁上的 html 小部件實現的。 但是,當用戶導航到不同的頁面時,我希望該鏈接可以將該頁面共享到社交媒體,而不是像目前這樣的站點頁面。

HTML代碼

<div id="custom_html-21" class="widget_text widget widget_custom_html">
  <div class="textwidget custom- html-widget">
    <a href="https://www.facebook.com/sharer/sharer.php?u=https://4309.co.uk" target="_blank" rel="noopener noreferrer">
      <div class="containercross">
        <div class="cross1">
          <div class="cross2"></div>
        </div>
      </div>
    </a>
  </div>
</div>

CSS代碼

@media (min-width: 768px) . {
   #custom_html-21 {
      position: absolute;
      height: 0px;
      top: -8px !important;
      left: 90%;
      margin-left: -46px;
   }
}
#custom_html-21 {
   position: absolute;
   height: 0px;
   top: -5px;
   left: 90%;
   margin-left: -46px;
}
.containercross {
   left: 0px;
   top: 20px;
}
.cross1 {
   height: 20px;
   width: 5px;
   background-color: black;
   margin-left: 50px;
}
.cross2 {
   height: 20px;
   width: 5px;
   background-color: black;
   margin-left: 50px;
   transform: rotate(90deg);
   margin-left: 0px;
}

因此,如果用戶在主頁上並選擇共享主頁,那么他們按下主頁中的鏈接並將主頁共享到社交媒體。 但我想這樣做,如果用戶在另一個頁面上,他們按下相同的圖標並以相同的方式鏈接到社交媒體,但不是共享主頁,而是共享用戶所在的頁面。

這里最容易在手機上看到

使用 PHP,您可以這樣做:

$currentPageUrl = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$link = 'https://www.example.com?share=' . $currentPageUrl;

HTML:

<a href="<?=$link?>" target="_blank">Share this page</a>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM