File tree Expand file tree Collapse file tree 4 files changed +42
-14
lines changed
Expand file tree Collapse file tree 4 files changed +42
-14
lines changed Original file line number Diff line number Diff line change 11FROM wordpress:latest
2- COPY ./index.php /usr/src/wordpress/unique_wp_query.php
3- COPY ./test_theme /usr/src/wordpress/wp-content/themes/testtheme
2+ # COPY ./index.php /usr/src/wordpress/unique_wp_query.php
3+ # COPY ./test_theme /usr/src/wordpress/wp-content/themes/testtheme
4+ # COPY ./developer /usr/src/wordpress/wp-content/themes/developer
45RUN rm -rf /usr/local/etc/php/conf.d/opcache-recommended.ini
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ wordpress:
1212 WORDPRESS_DEBUG : 1
1313 volumes :
1414 - .:/var/www/html/wp-content/plugins/unique_wp_query
15+ - ./test_theme:/var/www/html/wp-content/themes/testtheme
1516db :
1617 image : mariadb
1718 ports :
Original file line number Diff line number Diff line change @@ -25,6 +25,17 @@ function __construct($args) {
2525 // Act as a flag for pre_get_posts
2626 $ args ['unique_wp_query ' ] = true ;
2727
28+ // don't get any pages specified by post__not_in:
29+ if (key_exists ( 'post__not_in ' , $ args )) {
30+ foreach ($ args ['post__not_in ' ] as $ key => $ id ) {
31+ Unique_WP_Query_Manager::add_post_id ($ id );
32+ }
33+ }
34+
35+ // don't get the current post or page:
36+ $ id = get_the_ID ();
37+ Unique_WP_Query_Manager::add_post_id ($ id );
38+
2839 // Initialize the WP_Query object like normal
2940 parent ::__construct ($ args );
3041
@@ -56,10 +67,10 @@ class Unique_WP_Query_Manager {
5667 * useful for content outside of the normal query
5768 */
5869 public static function add_post_id ($ id ) {
59- if (!in_array ($ id , Unique_WP_Query_Manager::$ used_post_ids , true )) {
60- Unique_WP_Query_Manager::$ used_post_ids [] = $ id ;
70+ if (!in_array ($ id , Unique_WP_Query_Manager::$ used_post_ids , true )) {
71+ Unique_WP_Query_Manager::$ used_post_ids [] = $ id ;
6172 Unique_WP_Query_Manager::$ used_post_count = count (Unique_WP_Query_Manager::$ used_post_ids );
62- }
73+ }
6374 }
6475
6576 /**
Original file line number Diff line number Diff line change 1- <?php
2- get_header (); ?>
31<div id="contentArea">
42<div id="mainContent">
5- <?php while ( have_posts () ) : the_post (); ?>
6- <h2><a href="<?php the_permalink (); ?> " title="<?php the_title_attribute (); ?> "><?php the_title () ?> </a></h2>
7- <?php the_content () ?>
8- <?php endwhile ; ?>
9- </div>
10- <?php get_sidebar (); ?>
3+ <?php
4+ $ latest_posts1 = new Unique_WP_Query ([
5+ 'post_type ' => 'post ' ,
6+ 'posts_per_page ' => 3 ,
7+ 'post_status ' => 'publish ' ,
8+ 'post__not_in ' => array (18 )
9+ ]);
10+ $ latest_posts2 = new Unique_WP_Query ([
11+ 'post_type ' => 'post ' ,
12+ 'posts_per_page ' => 3 ,
13+ 'post_status ' => 'publish ' ,
14+ ]);
15+ while ($ latest_posts1 ->have_posts ()) {
16+ $ latest_posts1 ->the_post ();
17+ echo get_the_title (), '<br> ' ;
18+ }
19+ echo "<br><br>---------------------------------------------------------------------<br><br> " ;
20+ while ($ latest_posts2 ->have_posts ()) {
21+ $ latest_posts2 ->the_post ();
22+ echo get_the_title (), '<br> ' ;
23+ }
24+
25+ ?>
1126</div>
12- <?php get_footer (); ? >
27+ </div >
You can’t perform that action at this time.
0 commit comments