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
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?
Currently I am trying to get wordpress pagination to display at the bottom of the page but nothing shows up, if I echo out "paged" it outputs 1 so I believe it is correctly reading the page it is on. The loop I am using is as follows:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'post_type' => 'company_list', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => 6, 'paged' => $paged);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
To echo out the actual pagination at the bottom of the page I am using:
echo paginate_links( $loop );
Currently no pagination is being displayed at the bottom of the page but the loop is working correctly. The page is also not set as a static front page.
Thanks.
1)You do not have to use question mark in your first row
$paged = (get_query_var('paged')) ?
2)also see :
https://stackoverflow.com/a/33757648/10210277
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.
I have the following code in the "archive.php" file (from my current active theme):
list($f_categ_name) = explode('/', get_category_parents($cat));
if ( $f_categ_name == "X_CATEG") {
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'category_name' => single_cat_title( '', false ),
'meta_key' => 'x_categ_type',
'orderby' => 'meta_value',
'order' => 'ASC',
'paged' => $paged,
);
// get results
$the_query = new WP_Query( $args ); // The Loop
?>
<?php if( $the_query->have_posts() ): ?>
I have 2 categories : A (with 15 posts) and B (with 7 posts) and they have the same parent category(let's say X_CATEG). So basically I run the same code but $the_query->have_posts() returns true for A category and false for B category. WHY?
Using $GLOBALS['wp_query']->request I was able to debug the executed query and both queries (for category A and B) returned all post IDs.
In the WP_Query arguments, category_name will be category slug Not Category title.
single_cat_title functions will return the page title if a category or tag archive is queried. see reference
So You should use category slug in WP_Query arguments instead of category title.
Hope this will help.
I have a blog page in my wordpress site http://jarm.shahumyanmedia.com/blog/.
Here the blogs are posts, and I need to display 5 posts for each page, but I can't display pagination link.
This is how I am getting posts:
$posts = get_posts( array(
'posts_per_page' => 5,
'orderby' => 'date',
'order' => 'DESC',
'category' => 5)
);
And this is how I am trying to get pagination links:
<?php wp_link_pages(); ?>
http://codex.wordpress.org/Template_Tags/wp_link_pages
But I don't see any output.
Install and active this plugin and add this code..
http://www.devdevote.com/cms/wordpress-plugins/wp-paging
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('paged='.$paged.'&posts_per_page=5&orderby=date&cat=5&order=DESC');
while (have_posts()) : the_post();
....
endwhile;
wp_paging();