Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleArticleList.php returning the article title as link #694

Closed
agoat opened this issue Jan 31, 2017 · 6 comments
Closed

ModuleArticleList.php returning the article title as link #694

agoat opened this issue Jan 31, 2017 · 6 comments
Assignees
Labels
Milestone

Comments

@agoat
Copy link
Contributor

agoat commented Jan 31, 2017

In the class ModuleArticleList.php the link parameter in the returning array should give the alias instead of the title.

$articles[] = array
(
	'link' => $objArticles->alias,
	'title' => \StringUtil::specialchars($objArticles->title),
	'id' => $cssID[0] ?: 'article-' . $objArticles->id,
	'articleId' => $objArticles->id
);
@agoat
Copy link
Contributor Author

agoat commented Jan 31, 2017

Ahh, I forgot I changed my template file..

Then I have to extend this:
Let's say I want the article list to be a menu to open the articles directly. I need the alias or better the correct article link. The current template is only for anchor links. But if there would be also the real article link in the array, there would be a broader application.

I recommend to extend this:
Actually the parameter link should be a 'link', but to avoid BC we should not touch it. So I added a url parameter.

while ($objArticles->next())
{
	// Skip first article
	if (++$intCount <= intval($this->skipFirst))
	{
		continue;
	}
 
	$strAlias = $objArticles->alias ?: $objArticles->id;
	$cssID = \StringUtil::deserialize($objArticles->cssID, true);

	$articles[] = array
	(
		'link' => $objArticles->title,
		'title' => \StringUtil::specialchars($objArticles->title),
		'id' => $cssID[0] ?: 'article-' . $objArticles->id,
		'articleId' => $objArticles->id,
		'url' => ($objTarget ?: $objPage)->getFrontendUrl('/articles/' . $strAlias)
	);
}

Now I can do something like this:

<li><a href="<?= $article['url'] ?>" title="<?= $article['title'] ?>"><?= $article['link'] ?></a></li>

@asaage
Copy link

asaage commented Jan 31, 2017

I think a correct article link is what you get if you display article as teaser - the usecase for ModuleArticleList is onpage-navigation as far as i understand.

@agoat
Copy link
Contributor Author

agoat commented Jan 31, 2017

I also think it's mainly for onpage-navigation. But what is the sense to be able to select a reference page then? The links directing to the page and the anchor position.

At least there should be also returned the alias to be able to generate a correct article link.

while ($objArticles->next())
{
	// Skip first article
	if (++$intCount <= intval($this->skipFirst))
	{
		continue;
	}
 
	$cssID = \StringUtil::deserialize($objArticles->cssID, true);

	$articles[] = array
	(
		'link' => $objArticles->title,
		'title' => \StringUtil::specialchars($objArticles->title),
		'id' => $cssID[0] ?: 'article-' . $objArticles->id,
		'articleId' => $objArticles->id,
		'alias' => $objArticles->alias 
	);
}

So I can create a full article link in my template:

<li><a href="<?= $this->request ?>/articles/<?= $article['alias'] ?>" title="<?= $article['title'] ?>"><?= $article['link'] ?></a></li>

@asaage
Copy link

asaage commented Jan 31, 2017

i see...
ModArticleNavigation works kind of that way but without the ability to select a reference page.
I only use both modules rarely because i get allways confused.
Navigation works only if it's included in the layout - List will probably fail if you only display teasers.
I have no idea... 😄

@leofeyer leofeyer self-assigned this May 18, 2017
@leofeyer leofeyer added this to the 4.4.0 milestone May 18, 2017
@leofeyer
Copy link
Member

I have added the href parameter in 15ed60e.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants