How to order a widget to ignore a function of functions.php
-
Hi, I’m using this function that modifies the number of posts showed only in homepage, without affecting other categories.
/** * Fixing the Number of Post * Used in Homepage */ function simplecatch_home_custom_query( $query ) { if ( is_home() ) $query->query_vars['posts_per_page'] = 5; // Change 5 to the number of posts you would like to show return $query; // Return our modified query variables } add_filter( 'pre_get_posts', 'simplecatch_home_custom_query' ); // Hook our custom function onto the request filter
This works perfect, but my problem is that a text widget in my home page is also using the posts_per_page argument, so that full widget gets multiplied by 5 (the new post_per_page that I am forcing with this function).
This is my text widget code (it’s a box widget that works as a “RANDOM POST” button):
<?php $args=array( 'orderby' => 'rand', 'cat' => '14', 'post_type' => 'page', 'post_status' => 'publish', 'posts_per_page' => 1, 'caller_get_posts'=> 1 ); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { echo ''; while ($my_query->have_posts()) : $my_query->the_post(); ?> <div style="width: 272px; padding: 5px; border: 4px solid gray; margin: 0; text-align: center; background-color: rgb(183, 222, 253); "><h4><font-size=6><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">Can?ó aleatòria</a></font><h4></div> <?php endwhile; } wp_reset_query(); // Restore global post data stomped by the_post(). ?>
So, what I think I need is something that makes that this widget on my homepage ignores this function, so it preserves his ‘posts_per_page’ => 1.
I would really apreciate your help, thank you very much in advanced.
PS: sorry for my English.
- The topic ‘How to order a widget to ignore a function of functions.php’ is closed to new replies.