This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
kutup
Hello friends, I want to change the prominent picture we add in blog posts according to the second language. So I need to add a featured image for each language. Can you help me? How can I do that?
mjauvin
There are two ways to do this:
- add two featured images to the post, the first for the default language, and the second for the secondary language. You can do
post.featured_images.first
to get the first (default language) image, andpost.featured_images.last
to get the other for the secondary language. - extend the Post model and add a secondary image:
\RainLab\Blog\Models\Post::extend(function ($model) {
$model->attachMany = array_merge($model->attachMany, [
'secondaryImages' => \System\Models\File::class,
]);
\Event::listen('backend.form.extendFields', function ($widget) {
if (!($widget->getController() instanceof \RainLab\Blog\Controllers\Posts && $widget->model instanceof \RainLab\Blog\Models\Post)) {
return;
}
$widget->addFields([
'secondaryImages' => [
'tab' => 'rainlab.blog::lang.post.tab_manage',
'label' => 'Secondary Images',
'type' => 'fileupload',
'mode' => 'image',
'imageWidth' => 200,
'imageHeight' => 200,
],
], \Backend\Classes\FormTabs::SECTION_SECONDARY);
});
});
Last updated
kutup
@Mjauvin,
Thank you for your answer and support. Shouldn't I make a condition to show the secondary picture?
1-5 of 5