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
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
mjauvin

There are two ways to do this:

  1. 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, and post.featured_images.last to get the other for the secondary language.
  2. 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
kutup

@Mjauvin,

Thank you for your answer and support. Shouldn't I make a condition to show the secondary picture?

mjauvin
mjauvin

On your blog post page, just show the right one depending on the activeLocale

kutup
kutup

You can think of me as a beginner :) Could you write an example if I ask? Thank you so much

1-5 of 5

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.