I have 1379 posts published in a WordPress blog.
For some weird reason, I just noticed that pagination only works until page 154 (which is around 2006, whilst the first post was published in 1999)..
https://bombacarta.com/page/154/ works (last page)
https://bombacarta.com/page/155/ doesn't (but it should..)
Archives by date do work (even for posts older than 2006).
Do you have any idea of what's causing this?
This is the function I'm using in index.php to get the posts:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'category' => -7,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 8,
'paged' => $paged,
);
$articoli = get_posts( $args );
foreach ($articoli as $post) : setup_postdata($post); if( $post->ID == $do_not_duplicate ) continue;
echo '<article>...</article>';
endforeach; wp_reset_postdata();
I need that $do_not_duplicate because I have a featured post I'm showing just in the first page (home page).
EDIT: In the home page I also have 2 other loops that pull a specific page by ID and the featured post. Find the pastebin with the 3 functions here.
EDIT 2: There are just a few posts in cat 7 (excluded from the loop) - there are posts < 2006 from other categories as well. So it doesn't make a difference to have that category excluded.
Related
I'm trying to configure the Wordpress pagination in de Index homepage.
I've used the WP_Query with the regard of get_query_var('paged') before, just as the code shows:
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$query = new WP_Query( array(
'cat' => 7,
'posts_per_page' => 2,
'paged' => $paged
) );
?>
Then I used the native Wordpress function previous_posts_link() to go back onte the list of posts.
The problem that happens is that when the page loads, the url of the page changes, but the posts that shows are the same as before. Even to page 3 or 4, it just shows the same list of pages.
Where am I going wrong?
When i visit mysite.com/category/*** It only displays last post of that category.
But i want it to display recent ten posts of that category.
In short...
I want my site http://bishwash.com.np/category/entertainment/ to display posts like http://www.onlinekhabar.com/category/bichitra-world/
you can get the recent posts with wp_recent_posts($arg,ARRAY_A );
<?php $args = array(
'numberposts' => 10,
'offset' => 0,
'category' => 1,
'orderby' => 'post_date',
'order' => 'DESC',
'include' => ,
'exclude' => ,
'meta_key' => ,
'meta_value' =>,
'post_type' => 'post',
'post_status' => 'publish',
'suppress_filters' => true );
$recent_posts = wp_get_recent_posts( $args, ARRAY_A );
?>
You can use get_posts to retrieve posts.
<ul>
<?php
global $post;
$myposts = get_posts('numberposts=5&category=1');
foreach($myposts as $post) :
?>
<li><?php the_title(); ?></li>
<?php endforeach; ?>
</ul>
Change category=1 to your category ID number.If you to get post from XYZ category and XYZ category had 13 ID number then it would be something like this category=13.
In categroy.php page before
<?php if ( have_posts() ) : ?>
//paste the following code
$catID = the_category_ID();
$args = array( 'numberposts' => '10','category' => $catID);
$recent_posts = wp_get_recent_posts( $args );
setup_postdata($recent_posts);
At the end of loop
wp_reset_postdata();
The number of posts is set globally for all index type pages (including the home page and archives and category) in settings, reading
It seems you have limited it to 1 ? Then it's better design to set it to 10 because that will apply to all pages, and design a specific template for the home page, where you limit the number of posts with the methods given to to.
You can achieve that in two ways :
- build a page template, with a specific query, create a page with this template, and define it as homepage in settings -> reading
- create a home.php file in your theme
In both cases, it's better to have a child theme, not to loose modifications when your theme is updated.
Create the template (sample.php) and write code like
$catquery = new WP_Query( 'cat=3&posts_per_page=10' );
or use CATEGORYNAME
Note: When we click the link it redirects to to the sample.php and the category name is dynamic that means when we click the category its automatically stored to the CATEGORYNAME
I'm having some trouble displaying a list of posts from a Wordpress Category that will exclude a certain number of post based on a custom field using Advance Custom Fields.
Here's the current code I'm using that hides it nicely:
while ( have_posts() ) : the_post();
$is_taken = get_field('taken_check', $this_id);
if ($is_taken!=1) {
get_template_part( 'basket_selection' );
}
endwhile;
However, it simply just hides the post but still considers it as a post on the "posts_per_page" function.
For example, There are 20 posts in total and I've set the limit to 10 posts per page. If I hide 3 posts with the code above, it will only display 7 posts in page 1 and 10 posts in page 2.
Is there a way to simply just ignore the hidden posts and not count it as a "post"?
Try this:
Apply Custom Fields Parameters in get_post query itself.
$posts = get_posts(array(
'posts_per_page' => 10,
'post_type' => '<YOUR_POST_TYP>',
'meta_key' => 'taken_check',
'meta_value' => '<DEFAULT_VALUE_OF_taken_check>'
));
Lots to read here: http://codex.wordpress.org/Template_Tags/get_posts
I've managed to solve it by changing the get_posts to wp_query within the category.php.
I first added this code to detect the current category viewed and filter the query to only display taken_check = 0.
$this_cat = get_category(get_query_var('cat'), 'ARRAY_A', false);
foreach ($this_cat as $this_cat){
$this_catid = $this_cat;
break;
}
$args = array(
'posts_per_page' => 10,
'post_type' => 'post',
'cat' => $this_catid,
'orderby' => 'title',
'order' => 'ASC',
'paged' => $paged,
'meta_query' => array(
array(
'key' => 'taken_check',
'value' => '0',
)
)
);
$wp_query = new WP_Query($args);
I then just continued with the default loop sequence. The only weird code is the unnecessary foreach loop to detect the current category based on the current page and not from a post. Still puzzled as to why I can't just use $this_cat[0] since it's an array. It keep returning blank.
Oh well, but it works now with pagination, so I'm happy :)
Thanks for all the help!
I have a homepage with four displayed posts and one that is emphasized.
The one that is emphasized is not a problem, it's a large post whose details i collect using special loop.
But for those four posts (that have pagination), I just can't seem to exclude that emphasized one.
For example, if emphasized post has ID of 8, this should do the trick:
$args=array(
'paged' => $paged,
'posts_per_page' => 4,
array('post__not_in' => array(8))
);
query_posts($args);
while ( have_posts() ) : the_post();
echo '<li>';
the_title();
echo "<span> ".$post->ID."</span>";
echo '</li>';
endwhile;
But for some reason it's not filtering anything, always displays all the posts.
Any ideas why this is happening?
Why is the post__not_in in another array? I would recommend putting it on the same level:
$args=array(
'paged' => $paged,
'posts_per_page' => 4,
'post__not_in' => array(8)
);
If that doesn't help, I would recommend checking approaches mentioned here.
I need to create a wordpress-site which shows 5 posts on the front and in a different loop: 2 posts of the next page. These show up if you visit the second page. Do you have any ideas? I wanna show "More articles" by displaying "older" posts in a different loop.
Thanks
For the first page, limit your listing to 5 posts per page in wordpress settings.
Then you create the second page and apply a page template in witch you have made a custom query to fetch 2 posts.
$cat = get_cat_ID($category);
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$post_per_page = 2; // -1 shows all posts
$do_not_show_stickies = 1; // 0 to show stickies
$args=array(
'category__in' => array($cat),
'orderby' => 'date',
'order' => 'DESC',
'paged' => $paged,
'posts_per_page' => $post_per_page,
'caller_get_posts' => $do_not_show_stickies
);
$temp = $wp_query; // assign orginal query to temp variable for later use
$wp_query = null;
$wp_query = new WP_Query($args);
if( have_posts() ) :
...
To read more, see Wordpress Codex Reference