Problem with Categories in Wordpress! - wordpress

My Original question was this:
I have a wordpress installation where
the Home page is set to display post
from a specific category. To achieve
this, I created a template "home.php"
and put the following code:
query_posts( 'cat=4&order=desc' );
When I visit the site's home page, it
display posts from the category but
the Navigation does not work? I have
permalink structure set
"/%category%/%postname%/"
Please let me know if I am doing
something wrong.
Update:
Now, I have solved this using this code:
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$args = array (
'cat' => 4,
'orderby' => 'date',
'order' => 'desc',
'posts_per_page' => '10'
);
query_posts($args . '&paged=' . $paged);
Now the problem is that first time, it displays everything fine but if you visit any other archive page, it start displaying posts from other categories. For example, the above code displays posts from Cat=>3 as well. And on page, where I want to display posts from Category = 3, it display posts from category 4 as well.
Please help...
Thanks

What do you mean by "Navigation"? What code are you using for the navigation? Are you limiting the amount of posts?
If you have problems with the pagination. You can use this:
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("cat=4&order=desc&paged=$paged"); ?>
Please, Clarify your problems to help you.

Related

WordPress index archives not working (Prev / Next)

I'm having a strange issue whereby my blog index archives pages (Previous Link) isn't working and is going to a 404 page.
I have a page set as the site's Index, and the News (Blog) section is located at a seperate page called 'news'. Archive pagination works fine for category archives, it just appears to be the index.php loop that is not allowing the archives pagination to work for some reason. Any help would be greatly appreciated, here's my code from my theme's index.php file that dips into the loop for posts:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
// 'cat' => -13, // Exclude Guide To's
'order' => 'DESC',
'paged' => $paged,
'ignore_sticky_posts' => true
);
$latest_posts = new WP_Query( $args );
if ( $latest_posts->have_posts() ) {
while ( $latest_posts->have_posts() ) {
$latest_posts->the_post(); ?>
<?php get_template_part( 'content', 'post' ); ?>
<? } }
?>
If I understand you correctly, you have set a static front page. In that case
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
is wrong. paged is used for any page, except a static front page. Static front pages uses page. So you should change the above mentioned line to
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
EDIT
Your next_posts_link should also be adjusted for custom queries. You have to set the $max_pages parameter
next_posts_link( 'Older Entries', $latest_posts->max_num_pages );
EDIT 2
Seems like your rewrite rules seems to be the problem. Add the following to your functions.php and reload your index page a few times.
function bt_flush_rewrite_rules() {
flush_rewrite_rules();
}
PLEASE NOTE You should delete this function immediately after reloading your index page a few times. flush_rewrite_rules() are a really expensive operation that is quite tough on resources, so it should ONLY be used if really really necessary

wordpress - excluding a category from a post list in a custom theme that doesn't look like the codex

I'm hoping someone can help. I'm not a php coder, but I've been tweeking and customising a premium theme for wordpress anyway, and I'm stuck.
I'm trying to exclude a specific category from a page which lists all the categories by default. Ok, no problem. It should be:
<?php query_posts($query_string . '&cat=-134'); ?>
right?
I'm pretty sure the category number is 134, but I could be wrong. The premium theme I'm using is called Risen, and there's a lot of different kinds of posts - so maybe what I think is a category is really a tag in a custom taxonomy - in which case ???
When I hover over it in the category listing I get this:
example.com/wp-admin/edit-tags.php?action=edit&taxonomy=risen_multimedia_category&tag_ID=134&post_type=risen_multimedia
I'm pretty sure I've found where I need to include my argument, and that is here in the template:
// Get posts
$multimedia_query = new WP_Query( array(
'post_type' => 'risen_multimedia',
'posts_per_page' => risen_option( 'multimedia_per_page' ) ? risen_option( 'multimedia_per_page' ) : risen_option_default( 'multimedia_per_page' ),
'paged' => risen_page_num() // returns/corrects $paged so pagination works on static front page
) );
I've tried adding
'tag' => -134
to this array to no avail.
Being a premium, and apperently tweaked, theme there is a lot of guessing here but I think you have talked yourself into the solution, except for one detail. Use tag__not_in not tag=-134
// Get posts
$multimedia_query = new WP_Query( array(
'post_type' => 'risen_multimedia',
'posts_per_page' => risen_option( 'multimedia_per_page' ) ? risen_option( 'multimedia_per_page' ) : risen_option_default( 'multimedia_per_page' ),
'paged' => risen_page_num() // returns/corrects $paged so pagination works on static front page
'tag__not_in' => array(134)
) );
tag_id=-134 might work (I'd have to test it) but tag expects the tag slug not an ID.
tag (string) - use tag slug
http://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters

Page url showing page/2 but getting posts from first page

I'm struggling a theme that I got, the theme uses query_posts() and pagination used to work. Now pagination is not working on this page, and it keeps on showing posts from the first page on the second. Meaning, the url shows page/2 but I keep on seeing the first posts of the category, i.e. the first 4 on every page.
Here is the code used to get the posts:
global $current_category;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
global $query_string;
$args = "";
if ($current_category['post_type'] == "product") {
$args=array(
'showposts' => 4,
'paged' => $paged,
'post_type' => 'product'
);
} else {
$args=array(
'showposts' => 4,
'category_name' => $current_category['name'],
'paged' => $paged
);
}
query_posts($args);
And here's the loop:
if (have_posts()) : while (have_posts()) : the_post();
<outputs code here>
endwhile;
else :
<output no results code here>
endif;
if ( is_home() ) wp_reset_query();
Now, can anybody please point me in the right direction?
//update:
I have already tried this solution as well, so far, I can only tell that the paged variable never gets updated in the query.
//update 2:
This page was done custom, and setting it as the home page via Settings -> Reading inhibits the above behaviour. When leaving it as a normal page, and setting home as recent posts, the pagination works fine.
if you have any custom queries in the template, make sure to integrate the 'paged' parameter.
Pagination Parameters
Go through these codex pages:
Preserving Existing Query Parameters
Related: Pagination
I have fixed this after some very long research. My code now looks as follows:
global $current_category, $paged;
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}
This just replaces the first 3 lines of the original code in the answer. The rest looks exactly the same.

Custom post type pagination

I'm trying to print out a number of posts from multiple post types. However, I can't seem to implement the pagination - once I go to .../category.../page/2 I get a page not found error. It seems like it doesn't even try to read what's inside of my archive.php file.
I'm 100% sure that there's no problem with permalinks, since I've tried resetting them and etc.
I suppose it has something to do with the fact that in admin settings the number of posts per page is set to 10, but i really need to be able to edit this number dynamically.
I've tried a variaty of fixes from here, but non of them seem to work: http://wordpress.org/support/topic/pagination-with-custom-post-type-getting-a-404?replies=1#post-1616810
I'm sorry if it's highly repetitive question - none of other fixes I found worked for me.
Thanks a lot!
You can do something like this (not tested):
$posts_per_page = 10;
$post_type = 'YOUR_POST_TYPE'
$args = array( 'post_type'=> $post_type, 'posts_per_page' => $posts_per_page, 'paged' => get_query_var('paged') );
query_posts( $args );
// here loop

WordPress - Each page of paged posts all show same posts

I set up a pagination function for my wordpress blog. When clicking to the next page, the URL is correct: "/page/1", "/page/2", "/page/3" etc, but the actual posts don't change from page to page (page 2 and page 3 still display the first page of posts). Here's the code I'm using for the loop:
Edit 4/24/10: I removed the 'offset' => 1, parameter and the paging now works, but now the question becomes: how do I use the offset parameter and still page?
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$sticky=get_option('sticky_posts');
$args=array(
'offset' => 1,
'category__not_in' => array(-6),
'paged'=>$paged,
'showposts' => 6,
);
query_posts($args);
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
Any help/insight would be much appreciated. Thank you!
I removed the 'offset' => 1, parameter and the paging now works, but now the question becomes: how do I use the offset parameter and still page?
See How to: Offsets and Paging « Weblog Tools Collection and WordPress › Support » Query_posts, offset and pagination

Resources