Article View: pl.comp.lang.php
Article #231289newbie: moje rozwiązanie dla wymiany linków - proszę o opinie
From: jivanmukta
Date: Thu, 17 Mar 2016 09:21
Date: Thu, 17 Mar 2016 09:21
68 lines
3480 bytes
3480 bytes
Napisałem witrynę w PHP5/MySQL (CodeIgniter). Przymierzam się do SEO, po raz pierszy. Chciałbym się wymieniać linkami z innymi witrynami.
Zrobiłem dwie tabele:
CREATE TABLE `links` (
`url` varchar(70) NOT NULL,
`text` varchar(70) DEFAULT NULL,
`anchor` varchar(200) DEFAULT NULL, -- HTML niestandardowego linku
`subject` varchar(45) CHARACTER SET utf8 COLLATE utf8_polish_ci NOT NULL,
PRIMARY KEY (`url`),
KEY `fk_subject_idx` (`subject`),
KEY `ix_subject` (`subject`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Linki do stron polecanych';
CREATE TABLE `link_subjects` (
`subject` varchar(45) CHARACTER SET utf8 COLLATE utf8_polish_ci NOT NULL,
`sequence_number` tinyint(3) unsigned DEFAULT NULL, -- kolejność
PRIMARY KEY (`subject`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Wyświetlam je na podstronie mojego serwisu. Link ("Polecamy strony") do podstrony jest na mojej stronie głównej.
Akcja:
public function links() {
$params['robots'] = 'noindex,nofollow'; // żeby Google nie wykryło wymiany linków
$this->load->view('announcement/header3', $params);
$params['links'] = $this->common->getLinks();
$this->load->view('announcement/links', $params);
}
Biblioteka common zawiera:
// pobierz linki do polecanych stron:
public function getLinks() {
$sql = 'SELECT subject, url, text, anchor ' .
'FROM links INNER JOIN link_subjects USING(subject) ' .
'ORDER BY sequence_number ASC, text ASC';
$result = $this->ci->db->query($sql);
$links = array(); // tablica rekordów: subject => array(...link...)
foreach ($result->result_array() as $r) {
$subject = $r['subject'];
if (!isset($links[$subject])) {
$links[$subject] = array();
}
if (!is_empty($r['anchor'])) {
$links[$subject][] = $r['anchor'];
} else {
if (substr($r['url'], 0, 5) != 'http:' && substr($r['url'], 0, 6) != 'https:') {
$r['url'] = 'http://' . trim($r['url'], ' /');
}
$links[$subject][] = "<a href='$r[url]'>$r[text]</a>";
}
}
$result->free_result();
return $links;
}
Widok wyświetla linki rozdzielone znakiem | i pogrupowane wg tematu (subject):
<h6>Polecamy strony</h6>
<?php
foreach ($links as $subject => $la) {
echo '<p>', ucfirst($subject), ':<br>';
echo implode(' | ', $la);
echo "</p>\n";
}
Czy to ma sens?
Technical Details
Message-ID:
<621f5e9e-c468-4949-8f3f-1a80991445b9@googlegroups.com>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!goblin3!goblin.stu.neva.ru!news.ripco.com!news.glorb.com!nt3no2371379igb.0!news-out.google.com!k1ni1050igd.0!nntp.google.com!nt3no2371372igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mailShow Full Headers
Complete Article Headers
X-Received: by 10.98.42.67 with SMTP id q64mr6356741pfq.9.1458206514231; Thu, 17 Mar 2016 02:21:54 -0700 (PDT) X-Received: by 10.50.136.167 with SMTP id qb7mr183859igb.7.1458206514133; Thu, 17 Mar 2016 02:21:54 -0700 (PDT) Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!goblin3!goblin.stu.neva.ru!news.ripco.com!news.glorb.com!nt3no2371379igb.0!news-out.google.com!k1ni1050igd.0!nntp.google.com!nt3no2371372igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: pl.comp.lang.php Date: Thu, 17 Mar 2016 02:21:53 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=89.72.94.100; posting-account=Y8V58QoAAACtLuF8lEt8MaiUjYUTCWP6 NNTP-Posting-Host: 89.72.94.100 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <621f5e9e-c468-4949-8f3f-1a80991445b9@googlegroups.com> Subject: newbie: moje rozwiązanie dla wymiany linków - proszę o opinie From: jivanmukta@poczta.onet.pl Injection-Date: Thu, 17 Mar 2016 09:21:54 +0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit