How can I make the filterBy code for the isTranslated applied to textarea on the page, named text
?
I use a if statement inside the foreach loop now. But I need to filter this to make my tags etc. play nice.
How can I make the filterBy code for the isTranslated applied to textarea on the page, named text
?
I use a if statement inside the foreach loop now. But I need to filter this to make my tags etc. play nice.
Or use the custom filter I have added⦠onlyTranslated is it called.
https://getkirby.com/docs/cookbook/multilanguage-secrets
It does not seem to work in the tags, the ->onlyTranslated()
The onlyTranslated is not checking the field that I want it to. But the isTranslated is.
Hey Jonathan, I donβt quite understand what you are asking, could you please provide your code. example?
Yes, of course. I have show you here two set of code. What works as expected and what is not.
I get the tags shown even if the content do not show in the list (the code ex. under). And I also get the wrong count. I have added I have added /site/plugins/filters.php
with the following code:
<?php
// To just show relevant content for each language
pages::$methods['onlyTranslated'] = function($pages) {
return $pages->filter(function($page) {
return $page->content(site()->language()->code())->exists();
});
};
Do not work as expected
This is used in a snippet.
<?php
// fetch all tags
$tags = $pages->find('articles')->children()->visible()->onlyTranslated()->filterBy('text', '!=', '')->sortBy('tags', 'aesc')->filterBy('date', '<=', strtotime(date_default_timezone_get(date('Y-m-d'))))->pluck('tags', ',', true);
$p = kirby()->request()->params()->tag();
?>
<?php foreach($tags as $tag): ?>
<?php
// find how many that uses this tag
$count = page('articles')->children()->visible()->onlyTranslated()->filterBy('text', '!=', '')->filterBy('tags', '*=', $tag)->filterBy('date', '<=', strtotime(date_default_timezone_get(date('Y-m-d'))))->count();
// echo $tag . ': ' . $count; -- to show both tag and how many
?>
<li>
<a href="<?php echo url($site->language()->code() . '/articles/tag:' . urlencode($tag))?>" <?php ecco($tag == $p, ' class="active"') ?>>#<?php echo html($tag) ?><span class="count-items opa"style="opacity: 0.4;" > (<?php echo html($count) ?>)</span>
</a>
</li>
<?php endforeach ?>
Works as expected
To list the βblogβ I use this code, and it work as expected after adding the if statement inside the foreach loop. So is there a way to make it in to a filter instead to make the tag work with the isTranslated()
function?
<?php
date_default_timezone_set('America/Sao_Paulo');
$articles = $pages->find('articles')
->children()
->visible()
->onlyTranslated()
->filterBy('text', '!=', '')
->filterBy('date', '<=', strtotime(date_default_timezone_get(date('Y-m-d'))))
->flip()
->paginate(14);
?>
<?php foreach($articles as $article): ?>
<?php if ($article->text()->isTranslated()): ?>
// show the content
<?php endif ?>
<?php endforeach ?>
Thank you @texnixe for being active here on a sunday.