Divi is a WordPress theme and page builder by Elegant Themes that provides a visual drag-and-drop interface for creating website layouts. The Divi Blog Module, Post Slider, and Portfolio modules allow you to display posts with customizable layouts, but do not include a built-in option for sorting by view count.

Post Views Counter Pro integrates with Divi to enable ordering posts by view count in these modules. The integration is implemented in includes/integrations/divi.php and activates automatically when both Post Views Counter Pro and Divi are active on your site.

How It Works

The Divi integration enables sorting by post views through a CSS class trigger mechanism. When you add the CSS class orderby-post-views to a supported Divi module, the integration:

  1. Detects the class on the module instance during rendering
  2. Intercepts the module’s query using a pre_get_posts hook
  3. Sets the query to order by post views: $query->query_vars['orderby'] = 'post_views'
  4. Marks the query with $query->pvc_orderby = true for internal tracking
  5. Cleans up the temporary query modification after the module renders

This approach ensures ordering applies only to the specific module with the CSS class, not globally across your site.

Supported Modules

Sorting by post views is supported for these Divi modules:

  • Blog module (et_pb_blog)
  • Post Slider module (et_pb_post_slider)
  • Portfolio module (et_pb_portfolio)

Other Divi modules do not support ordering by views through this integration.

Setup

Prerequisites

  • Post Views Counter Pro installed and activated
  • Divi theme or Divi Builder plugin installed and activated

Enable the Integration

  1. Navigate to Post Views > Integrations
  2. Locate the Divi integration option
  3. Enable the integration toggle
  4. Save changes

The integration initializes automatically when both plugins are active.

Add the CSS Class to a Module

To sort a supported Divi module by post views:

  1. Open your page in the Divi Builder
  2. Add or edit a Blog, Post Slider, or Portfolio module
  3. Open the module settings panel
  4. Navigate to Advanced > CSS ID & Classes
  5. In the CSS class field, enter: orderby-post-views
  6. Save the module and update the page

Divi integration settings

The module will display posts ordered by view count (highest first). The CSS class is case-sensitive and must be entered exactly as shown.

Configuration

Module Settings Compatibility

After adding the CSS class, the module continues to accept all standard content settings:

  • Post Type selection
  • Post Count / posts per page
  • Included / Excluded Categories
  • Other display options specific to each module

The ordering by views works alongside these settings without conflict.

Displaying View Counts in Divi Layouts

To display view counts within Divi layouts, use the [post-views] shortcode:

  1. Open a page or template in the Divi Builder
  2. Add a Code or Text module where you want the view count to appear
  3. Insert the [post-views] shortcode
  4. Configure shortcode parameters as needed
  5. Save the module and publish your layout

Ensure your post types are enabled for tracking at Post Views > Counting > Tracking Targets.

Counter Mode Compatibility

The Divi integration works with all counter modes: PHP Mode, JavaScript Mode, and REST API Mode. No specific counter mode is required for Divi compatibility. Choose your counter mode based on your site’s caching configuration and tracking requirements.

If you experience counting issues with cached pages, review your caching compatibility settings at Post Views > Counting > Performance & Caching.

Troubleshooting

Posts Not Sorting by Views

Symptoms: Divi module displays posts but the order does not reflect view counts.

Solutions:

  • Verify the CSS class is entered exactly as orderby-post-views (case-sensitive, no spaces or typos)
  • Confirm you are using a supported module: Blog, Post Slider, or Portfolio
  • Check that posts have recorded views by viewing individual posts and checking counts in the WordPress admin
  • Clear any page caching and Divi’s static CSS cache, then reload the page

View Counts Not Displaying

Symptoms: The [post-views] shortcode shows no output or appears as plain text.

Solutions:

  • Ensure the Divi integration is enabled at Post Views > Integrations
  • Use a module that processes shortcodes (Code or Text module)
  • Verify the post type is enabled for tracking at Post Views > Counting > Tracking Targets
  • Check visitor exclusion settings at Post Views > Counting > Visitor Exclusions to confirm your user role or IP is not excluded from tracking

Counts Not Incrementing

Symptoms: Views are not being counted for pages built with Divi.

Solutions:

  • Review counter mode settings at Post Views > Counting > Tracking Behavior
  • If using a caching plugin, verify caching compatibility at Post Views > Counting > Performance & Caching
  • Ensure tracking is enabled for the post types displayed in your Divi layouts

Integration Not Appearing

Symptoms: Divi integration option is not visible in the Integrations tab.

Solutions:

  • Confirm Divi theme or Divi Builder plugin is installed and active
  • Verify you are using Post Views Counter Pro (this integration is not available in Lite)
  • Check for plugin conflicts by temporarily deactivating other plugins

Wrong Module Type

Symptoms: CSS class is added but posts do not sort by views.

Solutions:

  • Verify you are using Blog, Post Slider, or Portfolio module specifically
  • Other Divi modules (such as the Blog Grid module or custom post type modules) do not support this integration
  • The CSS class orderby-post-views has no effect on unsupported module types