WordPress Theme How to cancel the links within the page

Source: Internet
Author: User
Tags php file

For example: the other side of the site down the right, it will affect our website. In addition, WordPress site links to the pages of the link will also accidentally the weight of our site to the other side. Therefore, we should not only pay attention to the quality of friendship links, at the same time, but also to cancel the inner page links. So, WordPress theme How to cancel the inner page of the friendship link?

First of all, worddpress3.5 after the default no friendship links, so we want to add links to the function, the code is as follows:

The code is as follows Copy Code

Add_filter (' pre_option_link_manager_enabled ', ' __return_true ');

Then, add the link output List code:

The code is as follows Copy Code

Call Friendship Link
function ssmay_links ($link _type= "txt", $get _total=0) {
Global $wpdb;
$link _select = ($link _type = = "txt")? " = ''" : " != ''";
$get _total = ($get _total!= 0)? "LIMIT $get _total": "";
$request = "Select link_id, Link_url, Link_name, Link_image, Link_target, Link_description, link_visible, link_rating FRO M $wpdb->links ";
$request. = "WHERE $wpdb->links.link_visible = ' Y ' and $wpdb->links.link_image $link _select";
$request. = "ORDER by link_rating DESC, link_id ASC $get _total";
$links = $wpdb->get_results ($request);
foreach ($links as $link) {//Call menu
$output = ';
if ($link _type = = "txt") $output. = '

<a target= "'. $link->link_target. ' title= '. $link->link_description. ' href= '. $link->link_url. '" > '. $link->link_name. ' </a> ';
else $output. = ' <a target= '. $link->link_target. ' title= '. $link->link_description. "href=". $link-> Link_url. ' " >

link_image. ' alt= '. $link->link_name. '" ></a> ';
$output. = '. ' \ n ";
Echo $output;
}
};

Remember, put the above 2 pieces of code into the WordPress theme functions.php file.

Then, the link list function is called in the foreground page. In order not to let friendship link does not appear inside the page, but only in the first page, we want to call this function to make a judgment, to determine whether the current page is the homepage, if it is home on the display, not the home page is not displayed, the code is as follows:

The code is as follows Copy Code

<?php if (Is_home ()) {?>
<strong> Friendship Link:</strong>
<?php ssmay_links ("TXT",)?>
<?php}?>

The first sentence in the above code is to judge the statement, whether it is the first page, if it is the first to execute after the statement. Well, through the above operation, the link will only be in the WordPress site homepage display, but not in the inner page (such as category page, article page) displayed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.