kasiblog
Forum Replies Created
-
Forum: Plugins
In reply to: Query Post Within Category and OffsetI have a similar problem for another theme (Branford Magazin) and I am trying to adapt your solution to that theme. The Theme uses one specific category for the Feature.
So, it seems this is first main item:
$main_query = new WP_Query("showposts=1"); $category = wp_get_object_terms($main_query->post->ID, 'category'); $cat_offset = $category[0]->term_id; echo $category[0]->term_id;
– Line 1 saves the latest post from all categories into the Variable main_query
– Line 2 gets the category from the latest post
– Line 3 saves the ID from that category into the variable cat_offsetWhat does Line 4 do?
Okay, and this is the second important bit for the place where the remaining articles are displaced, in this case for category 12
<?php $offset = 0; if ( 12 == $cat_offset ) {$offset = 1;} query_posts("showposts=1&cat=12&offset=$offset"); ?>
Line 1 puts the variable offset into False.
Line 2 say that if the Category Number (12) is equal to the Category Number of the Feature-Article, then Offset is True
Line 3 says to post the remaining article(s).If I want to use for another category number, I just have to replace 12 with 44 or 767 or whatever number, right?
If I want to show more than of the remaining posts, than I change the number behind showposts, right?
Then the normal loop follows for this category.
The third important bit is this
<?php if ($main_query->have_posts()) : ?> <?php while ($main_query->have_posts()) : $main_query->the_post(); ?>
I don’t understand this if-clause. Why is it needed? It seems that already above the newest posts is in main_query? Why would you have to check whether there is a post (have_posts)? Is it so that the_post and the_excerpt and the_content give back the newest article?