=== Thistle Popular Posts ===
Contributors: popandthistle
Tags: popular posts, recent posts, widget, block, shortcode
Requires at least: 6.3
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Popular posts published in the last 30 days, with an optional automatic fallback to all posts. Works with classic and block themes.

== Description ==

Thistle Popular Posts first selects posts published within your chosen date window (30 days by default) and ranks them by views counted by this plugin. If there are no eligible recent posts, it can automatically display popular posts from your whole archive instead.

Add the list with the Thistle Popular Posts block, the classic widget, or the [thistle_popular_posts] shortcode. No theme edits or external accounts are required.

Features:
* Recently published posts first, with an optional all-posts fallback.
* An all-time mode that ignores publication dates.
* A configurable publication window of 1–365 days; default 30.
* Display 1–20 posts; default 5.
* Optional featured images and visible view counts.
* An option to exclude the article currently being read.
* Fonts and link colors inherited from your active theme.
* Local aggregate view counts; no external analytics service.
* View counts retained through deactivation and deletion unless you enable deletion in Settings.

Popularity is based on this plugin's counts since activation. Other plugins' counts and past analytics are not imported. Zero-view posts still qualify, with newer posts breaking ties. The date window refers to a post's publication date, not the date a view occurred.

== Installation ==

1. In WordPress, go to Plugins → Add New Plugin → Upload Plugin.
2. Choose thistle-popular-posts-1.0.0.zip, install it, and activate it.
3. Open Settings → Popular Posts. The 30-day window and automatic fallback are enabled by default.
4. Add the Thistle Popular Posts block in your editor, add the widget under Appearance → Widgets, or add a Shortcode block containing [thistle_popular_posts].
5. If your site uses a full-page cache, clear it after adding or changing the list.

The plugin does not insert a list automatically. Place a block, widget, or shortcode where you want the list to appear. A block theme's sidebar or footer can be edited in Appearance → Editor when the theme exposes those template parts.

== Frequently Asked Questions ==

= What exactly happens with the default settings? =

First, the plugin finds public, published posts with publication dates in the past 30 × 24 hours. It ranks those posts by its recorded view counts. If that eligible list is empty, it removes the date restriction and ranks all public, published posts by the same counts.

Private posts, drafts, scheduled posts, password-protected posts, and pages are excluded. If you enable "Exclude the current post," that exclusion applies to both queries.

= Does it fill a short recent list with older posts? =

No. If you request five posts but only two eligible recent posts exist, it shows those two. The fallback happens only when the recent list is empty.

= Does editing an old article make it recent? =

No. The filter uses the publication date, not the last-modified date. Dates are compared in GMT so the cutoff is consistent across site timezones.

= What appears immediately after installation? =

The list can appear immediately. Posts without recorded views still qualify. When counts are tied, newer posts appear first. As visitors read articles, the ranking reflects the new counts. View counts are hidden by default.

= Can I show an all-time list instead? =

Yes. Turn off "First use posts published within the publication window" in Settings → Popular Posts. The widget and block have equivalent controls. A shortcode can use recent_first="0".

= What shortcode options are available? =

[thistle_popular_posts]

[thistle_popular_posts title="Reader Favorites" count="5" days="30" recent_first="1" fallback="1" thumbnails="1" show_views="0" exclude_current="0"]

Use title="" to omit the heading. Use 1 or 0 for switches. Unspecified options inherit Settings → Popular Posts. Widget options are saved per instance; block and shortcode options override only the values you explicitly set.

= How are views counted? =

A small first-party JavaScript request records a view when a public single-post page is visible. Homepages, archive pages, feeds, pages, and previews do not count. Logged-in page responses do not enqueue the tracker, and the endpoint skips authenticated requests and recognized bot user agents.

The tracker can run on cached pages. A per-post timestamp in the browser tab's sessionStorage limits recounting the same post for 30 minutes in that tab. If sessionStorage is blocked, views can still be recorded, but that browser-side repeat limit is unavailable. If JavaScript or the counter's REST route is blocked, that visit will not count.

Counts are a lightweight measure of popularity, not unique visitors or fraud-resistant analytics. They can differ from other analytics products. No attempt is made to reconstruct views from before installation.

= Where is visitor data stored? =

The database contains only post IDs and their aggregate view counts in the site's prefixed thistle_popular_views table. The plugin does not store IP addresses, visitor identifiers, referrers, or browsing profiles, does not set cookies, and sends no data to external services. Session storage contains only a per-post timestamp and can be cleared by the browser. Describe this local counter and session storage in your site's privacy information as appropriate.

= How often does the list change? =

Ranked lists are cached for up to five minutes. Publishing or saving a post invalidates the plugin's ranking cache. A host, CDN, or full-page caching plugin can cache the page for longer; clear that cache after changes when you want immediate results.

= Can this work with any theme? =

The plugin uses standard WordPress block, widget, shortcode, style, and script APIs. A conventional theme that calls wp_head() and wp_footer() can use it. Available widget areas depend on the theme. The shortcode or block can be used in content even when there are no widget areas. A theme's custom CSS or other plugins can still require an adjustment on an individual site.

= What happens to counts when I deactivate or delete the plugin? =

By default, counts and settings are kept for reinstallation. To remove them, enable "Delete settings and view counts when this plugin is deleted," save settings, then deactivate and delete the plugin through WordPress. Deactivation alone never removes counts. On multisite, each site's settings and counts are separate, and the deletion preference is respected per site.

== Developer Notes ==

The CSS is scoped to .tpp-popular-posts. For a different thumbnail size, set --tpp-thumb-size on that element in your theme's additional CSS.

The thistle_popular_posts_cache_context filter can add a language or other public-query context to the plugin's cache key. It defaults to determine_locale(). Multilingual integrations that change query language independently of the WordPress locale should supply their own context.

== Changelog ==

= 1.0.0 =
* Initial release with publication-date filtering, empty-list fallback, a local view counter, block, classic widget, and shortcode.
