So I'm using wordpress with a updownupdown plugin (plugin for upvoting/downvoting posts). What I am trying to do is to show post with ,let's say at least 10 upvotes, on the homepage and hide the post with not enough points.
I tried to us this code in index.php
if (have_posts()) :
while (have_posts()) : the_post();
if (up_down_post_votesscore( get_the_ID()) > 10){
//content
}
endwhile;
endif;
and it kind of works, it hides all the post with less than 10 upvotes, but it doesn't put all the qualifying posts in one page (homepage has a pagination), so let's say there is 2 pages with 5 posts and there is 2 posts in each page with needed amount of upvotes, so instead of putting those 4 posts in one page, it shows only 2 qualifying post in each page.
Sounds like your posts retrieval is limited. You may want to change how many posts are obtained using:
query_posts( 'posts_per_page=20' );
reference: http://codex.wordpress.org/Function_Reference/query_posts
or do something like this if you're using get_posts:
$args = array(
'posts_per_page' => 20
);
get_posts( $args );
Reference: http://codex.wordpress.org/Template_Tags/get_posts
Related
I have a site where on the home page there are teasers for the 3 most recent posts.
If I make a post sticky then it actually adds a fourth post display and so on.
After searching I found this script which seem to initially work:
<?php
$sticky = count(get_option('sticky_posts'));
$the_query = new WP_Query( 'posts_per_page='. ( 3 - $sticky));
?>
This seemed to do the job perfectly. However I found if one of the posts was a recent post and was also set to sticky then this would affect the amount displyed.
For example, it the second most recent post was made sticky then it would result in only two posts displaying.
Any ideas on how the above code can be altered to always show three posts, sticky or not?
Thanks
$args = array(
'posts_per_page' => 3,
'ignore_sticky_posts' => 1
);
query_posts($args);
-- use while loop here ---
and after that use
wp_reset_query();
I am trying to change the HTML structure and CSS styles of the first 4 posts in the main WP_Query in archive.php
I am doing this simple thing where I checked the global $wp_query variable.
if ( have_posts() ) :
if( 4 > $wp_query->current_post ) :
the_title();
endif;
while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile;
else :
get_template_part( 'no-results', 'archive' );
endif;
This works fine, the first 4 posts in the query get displayed in whatever HTML/CSS I apply to them before the get_template_part() gets called in.
The problem is when I go to the next page in the pagination, a different set of 4 posts get displayed. The 4 new posts of the second page in the pagination.
I don't want that. I want the same 4 posts that appear on the first page to keep appearing as I go to the next or previous pages. I need to give the first 4 posts a different HTML structure, not just CSS styling and I need them to persist throughout the pagination.
I tried changing the main query with pre_get_posts and using offset but that gave me a set of problems in the theme and the admin panel that I decided against it.
How may I achieve that?
EDIT My first attempt at this problem was to do a second query and leave the main query intact but then I wouldn't be able to check the post_count in the first query to see if it's bigger than 4 because I'm always showing only 4 posts_per_page that's why I need them to be in the same query because I'm going to hide the first 4 posts on the category page that doesn't have more than 4 posts and only show them on the category page that has more than 4 posts.
EDIT 2 To make this simpler to understand, if it's getting too messy.
IF CATEGORY (QUERY) HAS MORE THAN 4 POSTS
DISPLAY 4 POSTS WITH CUSTOM HTML/CSS
THEN GET TEMPLATE PART AND DISPLAY THE REST OF THE POSTS WHILE EXCLUDING THE FIRST 4 POSTS BECAUSE DUPLICATES
ELSE
DISPLAY DEFAULT TEMPLATE PART
Here's a loop I use to show the first four posts, it has a wp_reset_postdata that might be required so your pagination loop is unaffected.
<?php $rp_query = new WP_Query( 'showposts=4' );
if ( have_posts() ) : while ( $rp_query->have_posts() ) : $rp_query->the_post(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<? endif; ?>
Solution is already built-in and available as plugin.
Please try Blog Designer PRO plugin - https://codecanyon.net/item/blog-designer-pro-for-wordpress/17069678?ref=miyanialkesh7
Best regards,
Alkesh
I have a search results page under construction, and it splits the posts out in to categories (products, recipes, articles), in 3 separate sections down the page. The categories (recipes and articles) were fine and easy - creating a query to use in 2 separate loops, but I'm having trouble with the custom post type.
I want to pull these in with the loop as well if possible, but not sure whether to do it on the post type or taxonomy. The products are obviously split in to sub categories under the taxonomy, so when I tried it, it was pulling the same product multiple times.
Right now, having given up on trying to pull them through using the taxonomy, I am trying this:
<?php
$args = array(
'post_type'=> 'products'
);
$products = new WP_Query($args);
if ( have_posts() ) :
?>
<div class="product suggestions cfx sub-range">
<h2>We found xx products...</h2>
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
This code isn't pulling anything through...will a different query work, or should I still be trying to use the custom taxonomy?
When I search for a solution, pretty much everything I can find is creating a search.php page for displaying only custom post types, or just adding the custom post type to search results, not having a separate loop for custom post types along side the loops for categories...
Thanks
I think I got it. I changed the slug from products and it started working for some reason. So now i have this:
<?php
$args = array ('post_type'=>'product-ranges');
$products = new WP_Query($args);
if ( have_posts() ) :
?>
<div class="product suggestions cfx sub-range">
<h2>We found xx products...</h2>
<?php while ( $products->have_posts() ) : $products->the_post();
?>
I need to create manual pagination for WordPress custom post type; situation is explained below.
custom post type is 'survey'
I want each survey question to be displayed on single page and then upon clicking next button, the page should be reloaded and the next question should be displayed, So survey's structure should be like
Starting Page: http://www.example.com/survey-title/
Question 1: http://www.example.com/survey-title/q/1/
Question 2: http://www.example.com/survey-title/q/2/
Question 3: http://www.example.com/survey-title/q/3
End Page: http://www.example.com/survey-title/result/
On the bases of question number(q) passed, I can retrieve the required question.
What are the possible options (without possibly modifying the core wp structure) to achieve this?
P.S. it's intended to be similar functionality that we get by using <!--more--> tag to split the post/page contents into multiple paginated pages.
Any help regarding is highly appreciated.
You basically need to create a page to loop your posts with the custom type "survey", give it a number of posts per page and add a small trick to make the pagination work.
Sounds simple? Here's translated in code:
$args = array(
'post_type' => 'survey', //your post type
'posts_per_page' => 1 // number of posts you want to see per page, in your case, 1
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
echo '<div class="entry-content">';
the_content()
echo '</div>';
endwhile;
<!-- Add the pagination functions here. -->
<div class="nav-previous alignleft"><?php next_posts_link( 'Next Page' ); ?></div>
Are you posting data on every page or saving to POST only at the end? if it's the last case, this is not going to work.
I am using the PBD Load Next Post plugin and it's working great, but I can't figure out why the max_num_pages is returning 44 (number of posts in that category) instead of 4 (number of pages it should be). Here are all the codes that should be relevant:
http://pastebin.com/ezAbD2eH
Here is the page that it is running on: garthreckers(dot)com/category/united-states/ (sorry, not enough rep to post another full link)
It's also running on the Europe page but its returning 20 over there (number of posts again).
Also, the if(mobile...) is from the mooble plugin if that makes a difference. I have tried stripping out the code for that and deactivating and it still doesnt work.
Any help will be great since I have been trying to fix this problem for 3 days now with no success.
I know this may not be the best way but if you want to you can change the default number in the javascript as a workaround
Your JS http://pastebin.com/ezAbD2eH
Line 58:
var max = parseInt(pbd_alp.maxPages);
Change to:
var max = parseInt(pbd_alp.maxPages/12); //divide it by the number of posts per page.
if you want you can probably set that as a variable and use it elsewhere where your $arg is as well so that the number is set globally. Set $posts_per_page = 12 inside your PHP section.
var max = parseInt(pbd_alp.maxPages/<?php echo $posts_per_page; ?>);
I may have found your issue. Currently in your PHP code when displaying all your posts you have a query that calls for Categories
wp_list_categories('show_option_none=&orderby=name&show_count=1&hide_empty=1&use_desc_for_title=1&child_of='.$cat.'&title_li=');
Currently this is throwing off the number as it is showing max_num_pages based on the category list number. I would change the way you are displaying posts so that it is not using wp_list_categories to retrieve them.
Reference: http://codex.wordpress.org/Template_Tags/get_posts
<?php
$args = array( 'numberposts' => 3 );
$lastposts = get_posts( $args );
foreach($lastposts as $post) : setup_postdata($post); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php endforeach; ?>