MyBB Community Forums

Full Version: get_thread_link
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi what seems to be the problem here! I am showing 50 results in the page but from like half of the page and down URL are showing as default ones not SEO Friendly:

What seem to be the issue? What half shows OK and the rest not?

Why this is not working with all links???
$threadlink = get_thread_link($whiletag['tid']);


50 results UP OK down not.


$querysearch = $db->query("
        SELECT *, u.uid as byuid, u.username as byusername, a.lastpost as threadlastpost
        FROM ".TABLE_PREFIX."tags t
		LEFT JOIN ".TABLE_PREFIX."threads a ON (a.tid=t.tid)
		LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=a.uid)
		LEFT JOIN ".TABLE_PREFIX."users l ON (l.uid=a.lastposteruid)
        LEFT JOIN ".TABLE_PREFIX."forums f ON (a.fid=f.fid)
        WHERE t.tags LIKE '%".$db->escape_string_like($search)."%' AND a.visible='1' AND a.closed NOT LIKE 'moved|%' {$where}
		order by t.tid ".$mybb->settings['systemtag_ascdesclist']."
		LIMIT {$start}, {$perpage}
    ");

	while($whiletag = $db->fetch_array($querysearch))
	{
		$forumpermissions[$whiletag['fid']] = forum_permissions($whiletag['fid']);

		// Make sure we can view this thread
		if($forumpermissions[$whiletag['fid']]['canview'] == 0 || $forumpermissions[$whiletag['fid']]['canviewthreads'] == 0 || $forumpermissions[$whiletag['fid']]['canonlyviewownthreads'] == 1 && $whiletag['uid'] != $mybb->user['uid'])
		{
			continue;
		}


		$threadlink = get_thread_link($whiletag['tid']);


		$forumlink = "<a target=\"_blank\" href=\"".$mybb->settings['bburl']."/".get_forum_link($whiletag['fid'])."\">".$whiletag['name']."</a>";

		$username = build_profile_link(format_name($whiletag['byusername'], $whiletag['usergroup'], $whiletag['displaygroup']), $whiletag['byuid']);

		$lastuser = build_profile_link(format_name($whiletag['lastposter'], $whiletag['lusergroup'], $whiletag['ldisplaygroup']), $whiletag['lastposteruid']);

		$time = my_date($mybb->settings['timeformat'], $whiletag['threadlastpost']);
		$date = my_date($mybb->settings['dateformat'], $whiletag['threadlastpost']);

          

		eval("\$listhreads .= \"".$templates->get("tags_listthread")."\";");
	}
Anyone?
I cannot explain why this behaviour occurs. It would mean that the global variable THREAD_URL is reset during execution of the loop. I myself would do some debugging.

But what I can see is that the query is rather strange. You left join users to the lastposter in the thread but the result is nowhere used. The same for the forum which is also not used. Still you use $whiletag['fid'] as if 'fid' is a result, what is only possible when it is a column of table "tags".

This will be part of a plugin, as the table "tags" is no standard MyBB table.
If it's about Google SEO - the plugin can't predict that these links are going to show on a page, so it has to query each individually, and then at some point the max. query limit kicks in and it stops doing that.

You can avoid the issue by switching Google SEO to lazy mode [which does string replacement on the final HTML instead, which is not always possible], or by creating additional links in a way Google SEO can predict or populate $google_seo_url_optimize directly (like google_seo/sitemap.php does).
Thanks guys! Could you help me here please! I would like to join google_seo table and from there get the URL for thread and forum as well as for user that sounds OK but I can't make it work.

$querysearch = $db->query("
        SELECT *, u.uid as byuid, u.username as byusername, a.lastpost as threadlastpost
        FROM ".TABLE_PREFIX."tags t
        LEFT JOIN ".TABLE_PREFIX."threads a ON (a.tid=t.tid)
        LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=a.uid)
        LEFT JOIN ".TABLE_PREFIX."users l ON (l.uid=a.lastposteruid)
        LEFT JOIN ".TABLE_PREFIX."forums f ON (a.fid=f.fid)



LEFT JOIN ".TABLE_PREFIX."google_seo g  ON (a.tid=g.id)
LEFT JOIN ".TABLE_PREFIX."google_seo o ON (a.fid=o.id)

        WHERE t.tags LIKE '%".$db->escape_string_like($search)."%' AND a.visible='1' AND a.closed NOT LIKE 'moved|%' {$where}
        order by t.tid ".$mybb->settings['systemtag_ascdesclist']."
        LIMIT {$start}, {$perpage}
    ");

The thread join appears to work but not the forum???
That won't work. Stick to get_thread_link().
OK juts gonna decrease the amount of results per page or use default URL that will be redirected to SEO one and since the header contains canonical URL I will be OK thanks a lot..