|
| 1 | +<h1 align="center">unique-wp-query</h1> |
| 2 | + |
| 3 | +<p align="center"> |
| 4 | + <a href="https://github.com/firstandthird/unique-wp-query/actions"> |
| 5 | + <img src="https://img.shields.io/github/workflow/status/firstandthird/unique-wp-query/Test/main?label=Tests&style=for-the-badge" alt="Test Status"/> |
| 6 | + </a> |
| 7 | + <a href="https://github.com/firstandthird/unique-wp-query/actions"> |
| 8 | + <img src="https://img.shields.io/github/workflow/status/firstandthird/unique-wp-query/Lint/main?label=Lint&style=for-the-badge" alt="Lint Status"/> |
| 9 | + </a> |
| 10 | + <img src="https://img.shields.io/npm/v/unique-wp-query.svg?label=npm&style=for-the-badge" alt="NPM" /> |
| 11 | +</p> |
| 12 | + |
| 13 | +unique-wp-query is a Wordpress plugin that can be used to ensure no post is |
| 14 | +loaded more than once per screen |
| 15 | + |
| 16 | +## Features |
| 17 | + |
| 18 | +* ensures only one of each post is loaded |
| 19 | + |
| 20 | +## Installation |
| 21 | + |
| 22 | +just put the root folder in your __wp-content/plugins__ directory and Activate |
| 23 | +from the plugins console |
| 24 | + |
| 25 | +## Usage: |
| 26 | + |
| 27 | +From the demo: |
| 28 | + |
| 29 | +```php |
| 30 | +$latest_posts1 = new Unique_WP_Query([ |
| 31 | + 'post_type' => 'post', |
| 32 | + 'posts_per_page' => 3, |
| 33 | + 'post_status' => 'publish', |
| 34 | + 'post__not_in' => array(18) |
| 35 | +]); |
| 36 | +$latest_posts2 = new Unique_WP_Query([ |
| 37 | + 'post_type' => 'post', |
| 38 | + 'posts_per_page' => 3, |
| 39 | + 'post_status' => 'publish', |
| 40 | +]); |
| 41 | +while ($latest_posts1->have_posts()) { |
| 42 | + $latest_posts1->the_post(); |
| 43 | + echo get_the_title(), '<br>'; |
| 44 | +} |
| 45 | +echo "<br><br>---------------------------------------------------------------------<br><br>"; |
| 46 | +while ($latest_posts2->have_posts()) { |
| 47 | + $latest_posts2->the_post(); |
| 48 | + echo get_the_title(), '<br>'; |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +The second list will not include any posts that were in the first |
| 53 | + |
| 54 | + |
| 55 | +## Demo: |
| 56 | + |
| 57 | +``` |
| 58 | +This repo includes a docker-compose with a dummy theme that demonstrates the plugin, to use it: |
| 59 | + - __docker-compose up__ |
| 60 | + - Open a browser and log in to the Wordpress server |
| 61 | + - Add some dummy posts and then load the main page |
| 62 | +``` |
| 63 | + |
| 64 | + |
| 65 | +<a href="https://firstandthird.com"><img src="https://firstandthird.com/_static/ui/images/safari-pinned-tab-62813db097.svg" height="32" width="32" align="right"></a> |
| 66 | + |
| 67 | +_A [First + Third](https://firstandthird.com) Project_ |
0 commit comments