0

on my home page I have 4 posts selected by tag in slider as featured posts. Below that I have some widgets which displays posts from selected category.

How can I make category widget not to show posts which is still displayed in featured slider? I can find solution to exclude posts with certain tag but I still want those posts to show when they go away from featured slider.

Some themes have that option as "unique posts", and I would like to implement it in my theme

This is the script which is used for same purpose on Newsmag theme:

static $unique_articles_enabled = false;  //if true, the datasource will filter the rendered posts id

static function td_init() {
    /**
     * we need to hook after header because in mega menu we can have all kinds of modules and we don't want the unique
     * articles class to interfere with them.
     */
    add_filter('td_wp_booster_after_header', array(__CLASS__, 'on_td_wp_booster_after_header'), 10);

    /**
     * this hook is called each time a module is instantiated
     */
    add_filter('td_wp_booster_module_constructor', array(__CLASS__, 'on_td_wp_booster_module_constructor'), 5, 3);
}


//if we are on a page, read the page meta and see if td_unique_articles is set
static function on_td_wp_booster_after_header() {
    $page_id = get_queried_object_id();

    if (is_page()) {

        // previous meta
        //$td_unique_articles = get_post_meta($page_id, 'td_unique_articles', true);

        $meta_key = 'td_page';
        $td_page_template = get_post_meta($page_id, '_wp_page_template', true);
        if (!empty($td_page_template) && ($td_page_template == 'page-pagebuilder-latest.php')) {
            $meta_key = 'td_homepage_loop';

        }

        $td_unique_articles = td_util::get_post_meta_array($page_id, $meta_key);
        if (!empty($td_unique_articles['td_unique_articles'])) {
            self::$keep_rendered_posts_ids = true; //for new module hook
            self::$unique_articles_enabled = true; //for datasource
        }
    }
    if (td_util::get_option('tds_ajax_post_view_count') == 'enabled') {
        self::$keep_rendered_posts_ids = true;
    }
}


//we hook td_module constructor if  `unique articles` is enabled
static function on_td_wp_booster_module_constructor($module, $post) {
    if (self::$keep_rendered_posts_ids == true) {
        /**
         * @todo in viitor daca ne trebuie ceva mai bun trebuie refactorizat sa foloseasca api-ul de la module sau constructorul din td_module
         */
        // exclude td_module_trending_now din unique articles
        if (get_class($module) != 'td_module_trending_now') {
            self::$rendered_posts_ids[] = $post->ID;
        }
    }
}

} td_unique_posts::td_init();

  • 1
    Note that how this is implemented will have major performance considerations. The easiest method using exclude parameters, is also the worst case scenario for fast page load times and scaling traffic, luckily it's not the only way to do it. You'll also need to make code changes to get this working, which might mean forking or replacing widgets and other things – Tom J Nowell Jan 9 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.