Skip to content

Commit

Permalink
Fixed Related Articles not appearing on article page
Browse files Browse the repository at this point in the history
For bug #1048

- Related Articles now appear if the article has meta keywords
- Now searches for the last 50 articles that have a matching keyword and is ordered by date
- lower case all keywords
- Mentioned Related Articles Feature in Meta Tags Config description
  • Loading branch information
eSilverStrike committed Mar 25, 2020
1 parent 7a90737 commit 2dc3484
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
5 changes: 2 additions & 3 deletions public_html/docs/english/config.html
Expand Up @@ -113,9 +113,8 @@ <h3><a name="site_site">Site: Site</a></h3>
<tr>
<td valign="top"><a name="desc_meta_tags">meta_tags</a></td>
<td valign="top">Disabled</td>
<td valign="top">Enabled - The meta tags for articles and topics will be displayed. If none are found, then the default will be used. The default will also be used for any page that doesn't have meta tags.<br />
Enabled (Default for Homepage only) - The same as Enabled except, the defaults are used only for the Homepage.<br />
Disabled - Meta tags are not used.</td></tr>
<td valign="top">If "Enabled" (1) the meta tags for articles and topics will be displayed. If none are found, then the default will be used. The default will also be used for any page that doesn't have meta tags. If
"Enabled (Default for Homepage only)" (2) then it behaves the same as "Enabled" except, the defaults are used only for the Homepage. If "Disabled" (0) then Meta tags are not used.<br /><br /> Please note, if enabled and the article has it's own meta keywords then the article page will also display a list of up to 5 related articles (displayed under the title "You might also like"). This relation is based on how many keywords the article shares with others and how new the other articles are.</td></tr>
<tr>
<td valign="top"><a name="desc_meta_description">meta_description</a></td>
<td valign="top">'Geeklog, the open source content management system designed with security in mind.'</td>
Expand Down
1 change: 1 addition & 0 deletions public_html/docs/history
Expand Up @@ -20,6 +20,7 @@ For more in-depth explanation of the issues below see: https://github.com/Geeklo
- [Bug] [#1044] Fixed searching just articles [Tom]
- [Bug] [#1046] Fixed Users can only be set to certain statuses by Admins [Tom]
- [Bug] [#1047] Fixed Admin login form for those who try to access the Geeklog Admin area. Regular Logged in Users get just a message now instead of showing a login form [Tom]
- [Bug] [#1048] Fixed related Articles are Missing From the Article Page [Tom]

The following items are all current Geeklog API, functions, and/or global variables that are planned to be either required or depreciated by a current Geeklog version. Plugin and Theme developers please take note of these changes in case they affect you.

Expand Down
5 changes: 2 additions & 3 deletions public_html/docs/japanese/config.html
Expand Up @@ -101,9 +101,8 @@ <h3><a name="site_site">サイト: サイト</a></h3>
<tr>
<td valign="top"><a name="desc_meta_tags">メタタグ(meta_tags)</a></td>
<td valign="top">無効にする</td>
<td valign="top"><ul><li>「有効にする」 - 記事と話題用のメタタグが出力されます。メタタグが見つからない場合、既定値が使用されます。メタタグがない他のすべてのページで既定値が使用されます。</li>
<li>「有効にする(トップページにのみ既定値を使用する)」 - トップページに対してだけ既定値を使用するという点を除いて、「はい」と同じです。</li>
<li>「無効にする」 - メタタグを出力しません。</li></ul></td></tr>
<td valign="top">If "Enabled" (1) the meta tags for articles and topics will be displayed. If none are found, then the default will be used. The default will also be used for any page that doesn't have meta tags. If
"Enabled (Default for Homepage only)" (2) then it behaves the same as "Enabled" except, the defaults are used only for the Homepage. If "Disabled" (0) then Meta tags are not used.<br /><br /> Please note, if enabled and the article has it's own meta keywords then the article page will also display a list of up to 5 related articles (displayed under the title "You might also like"). This relation is based on how many keywords the article shares with others and how new the other articles are.</td></tr>
<tr>
<td valign="top">サイトの<a name="desc_meta_description">説明文のメタタグ(meta_description)</a></td>
<td valign="top">'Geeklog, the open source content management system designed with security in mind.'</td>
Expand Down
1 change: 1 addition & 0 deletions public_html/docs/japanese/history.html
Expand Up @@ -46,6 +46,7 @@ <h2>March ? 2020 (2.2.1sr1)</h2>
<li>[Bug] [#1044] Fixed searching just articles [Tom]</li>
<li>[Bug] [#1046] Fixed Users can only be set to certain statuses by Admins [Tom]</li>
<li>[Bug] [#1047] Fixed Admin login form for those who try to access the Geeklog Admin area. Regular Logged in Users get just a message now instead of showing a login form [Tom]</li>
<li>[Bug] [#1048] Fixed related Articles are Missing From the Article Page [Tom]</li>
</ul>

<p>The following items are all current Geeklog API, functions, and/or global variables that are planned to be either required or depreciated by a current Geeklog version. Plugin and Theme developers please take note of these changes in case they affect you.<br>
Expand Down
13 changes: 9 additions & 4 deletions system/classes/article.class.php
Expand Up @@ -2021,7 +2021,7 @@ private static function getRelatedArticlesSort(array $a, array $b)
*
* @param string $articleId
* @param string $keywordList a comma-separated list of keywords
* @param int $limit max number od related articles
* @param int $limit max number of related articles returned
* @return array
* @link http://www.enkeladress.com/article/20110315104621317
*/
Expand All @@ -2031,6 +2031,10 @@ public static function getRelatedArticlesByKeywords($articleId, $keywordList, $l

$work = array();

// Lets search the 50 latest articles that match the keyword
// This will return the most related
$searchlimit = 50;

$articleId = trim($articleId);
$keywords = explode(',', $keywordList);

Expand All @@ -2053,9 +2057,10 @@ public static function getRelatedArticlesByKeywords($articleId, $keywordList, $l
$sql = "SELECT sid, title FROM {$_TABLES['stories']} "
. "WHERE (sid <> '{$escapedArticleId}') "
. "AND (draft_flag = 0) AND (date <= NOW()) "
. "AND meta_keywords LIKE '%{$escapedKeyword}%' "
. "AND LOWER(meta_keywords) LIKE LOWER('%{$escapedKeyword}%') "
. "GROUP BY sid, title "
. "LIMIT 5 ";
. "ORDER BY date DESC "
. "LIMIT $searchlimit ";
$resultSet = DB_query($sql);

while (($A = DB_fetchArray($resultSet, false)) !== false) {
Expand Down Expand Up @@ -2083,7 +2088,7 @@ public static function getRelatedArticlesByKeywords($articleId, $keywordList, $l
}

$retval = '';
if ($found) {
if (count($work) > 0) {
if (count($work) > 1) {
usort($work, array(__CLASS__, 'getRelatedArticlesSort'));
}
Expand Down
2 changes: 1 addition & 1 deletion system/lib-article.php
Expand Up @@ -655,7 +655,7 @@ function STORY_renderArticle($story, $index = '', $storyTpl = 'articletext.thtml
}

// Add related articles
if ($index === 'n') {
if ($index === 'n' && $_CONF['meta_tags'] > 0) {
$article->set_var(
'related_articles_by_keyword',
Article::getRelatedArticlesByKeywords(
Expand Down

0 comments on commit 2dc3484

Please sign in to comment.