开发者

Exclude Link from a list if it matches the URL of current website

I have created a php file that has a list of SEO links on them which is hosted on my server. All of my clients web pages have a resource page which includes this page and displays my links. I did this to make adding links to all of my pages easier for me. Now what I'm trying to do is write a code that would search through my links and not display the ones that are for the current site being visited.

Ex: I am on the webpage (www.loonytoons.com) and I want my list to display all links except the one for this page. It would have to do it for all of my clients. This follow开发者_Go百科ing is an example of my list. Thanks

<ul id="resources">
    <li><a href="http://www.loonytoons.com/">Loony Toons</a> I want this link to show up on all sites execpt current site</li>
    <li><a href="http://www.theaustinbusinesslawyer.com/">Austin Business Lawyer</a> The Austin Business Lawyer Michael Pruneda can help you with any business related issues or concerns.</li>
</ul>


// isset required for win servers (This may not work on all win servers)
if (isset($_SERVER['HTTP_HOST'])){$domain = $_SERVER['HTTP_HOST'];}
if (strpos($link, $domain) === false){echo $link;}

$link is the string of your anchor info, so you would need to store all of the links most likely in an array and put the above into a foreach loop like this:

foreach ($linksarray as $link) {
    // Above code would go here
}

In response to the bottom comment: You could but that would be more work (you'd need strpos loops to create that array. It would be easier to just set up an array and have the array print your

  • 's.

    // [][0] = URL, [][1] = Title, [][2] = Description
    $linkarray = array(
        array('http://url1.com', 'URL1 Title', 'URL2 Description'),
        array('http://url2.com', 'URL2 Title', 'URL2 Description'),
    );
    

    The only thing you would need to change is in the first code box in my original answer change all $link to $link[0] (not in the foreach())

    Then your final line would look something like:

    if (strpos($link[0], $domain) === false){
        echo '<li class="liclass"><a href="'. $link[0] . '">' . $link[1] . '</a> - ' . $link[2];
    }
    


    On the client side, you could use jQuery to hide links for the current URL:

    $('a[href=' + document.URL + ']').hide();
    
  • 0

    上一篇:

    下一篇:

    精彩评论

    暂无评论...
    验证码 换一张
    取 消

    最新问答

    问答排行榜