Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Вывод последних статей - только определенной категории


Recommended Posts

Комрады, помогите разобраться, не хватает знаний и опыта. А надо как то сделать.

Суть:

Есть Блог на OpenCart 3, выводит на главную последние статьи из всех категорий. А нужно ограничить только одной.

Теорию я понимаю, ему нужно дать поиск статей только из определенной категории с ID. Но вот куда это прописать и как.... туповат я в этом. Но уверен дело пару строк всего.

У меня есть такой вот файлик - blog_latest.php

<?php
class ControllerExtensionModuleBlogLatest extends Controller {
    public function index($setting) {
        
        if (file_exists('catalog/view/theme/' . $this->config->get('config_template') . '/stylesheet/blog.css')) {
        $this->document->addStyle('catalog/view/theme/' . $this->config->get('config_template') . '/stylesheet/blog.css');
        } else {
        $this->document->addStyle('catalog/view/theme/default/stylesheet/blog.css');
        }
        
        static $module = 0;
        
        $this->load->language('blog/blog');
        $this->load->model('blog/blog');
        $this->load->model('tool/image');
        
        $data = array(
            'start' => 0,
            'limit' => $setting['limit']
        );
        
        $data['characters'] = $setting['characters'];
        $data['carousel'] = $setting['carousel'];
        $data['columns'] = $setting['columns'];
        $data['thumb'] = $setting['thumb'];
        
        if ($data['carousel']) {
        $this->document->addStyle('catalog/view/javascript/jquery/owl-carousel/owl.carousel.css');
        $this->document->addScript('catalog/view/javascript/jquery/owl-carousel/owl.carousel.min.js');
        }
        

        foreach ($this->model_blog_blog->getLatestBlogs($data) as $result){
              $data['posts'][] = array(
                'title' => $result['title'],
                'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
                
                'author' => $result['author'],
                'comment_total' => $this->model_blog_blog->getTotalCommentsByBlogId($result['blog_id']),
                'date_added_full' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
                'description' => utf8_substr(strip_tags(html_entity_decode($result['short_description'], ENT_QUOTES, 'UTF-8')), 0, $setting['characters']) . '..',
                'count_read' => $result['count_read'],
                'image'           => $this->model_tool_image->resize($result['image'], $setting['width'], $setting['height']),
                'href'  => $this->url->link('blog/blog', 'blog_id=' . $result['blog_id'])
              );
        }
        
        $data['blog_show_all'] = $this->url->link('blog/home');
        
        $data['text_show_all'] = $this->language->get('text_show_all');
        $data['text_posted_on'] = $this->language->get('text_posted_on');
        $data['text_posted_by'] = $this->language->get('text_posted_by');
        $data['text_read'] = $this->language->get('text_read');
        $data['text_comments'] = $this->language->get('text_comments');
        $data['text_not_found'] = $this->language->get('text_not_found');
        $data['heading_title_latest'] = $this->language->get('heading_title_latest');
        $data['text_read_more'] = $this->language->get('text_read_more');
        
        $data['date_added_status'] = $this->config->get('blogsetting_date_added');
        $data['comments_count_status'] = $this->config->get('blogsetting_comments_count');
        $data['page_view_status'] = $this->config->get('blogsetting_page_view');
        $data['author_status'] = $this->config->get('blogsetting_author');
        

        $data['module'] = $module++;

        return $this->load->view('extension/module/blog_latest', $data);

    }
}

 

------------------------------------------------------------------------------------

 

А есть вот такой файлик - blog.php ( и как я понял, обращение в БД, даю часть кода)

 

public function getLatestBlogs($data = array()) {
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "blog i LEFT JOIN " . DB_PREFIX . "blog_description id ON (i.blog_id = id.blog_id) LEFT JOIN " . DB_PREFIX . "blog_to_store i2s ON (i.blog_id = i2s.blog_id) WHERE id.language_id = '" . (int)$this->config->get('config_language_id') . "' AND i2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND i.status = '1' AND i.sort_order <> '-1' ORDER BY i.sort_order, i.blog_id DESC LIMIT " . (int)$data['start'] . "," . (int)$data['limit'] . "");
        
        return $query->rows;
    }

 

------------------------------------------------------------------------------------

 

Подскажите ПЛЫЗ! Куда прописать чтоб статьи брал только с одной категории category_id=49

Link to comment
Share on other sites


В 06.05.2021 в 09:19, kwakin сказал:

Купить нормальный блог

Так его и купили. И он даже работает нормально)))) Вот только при выборе его, я не до конца продумал все тонкости его применения. Так что по вашему, получается за этот просчет (мой косяк) нужно платить монетой? Может все же кто подскажет как быть?

Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.