Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

how do i set to display the last 7 category post and pagination WordPress

  • SOLVED


how do i set to display the last 7 category post and pagination for older post for my home page
here's what i have
it is displaying all categories on the home page taking the front page to long to load


<?php get_header(); ?>


<div id="contentwrap">

<div id="maincontent">


<div >


<?php
$page_id = 44; // 123 should be replaced with a specific Page's id from your site, which you can find by mousing over the link to edit that Page on the Manage Pages admin page. The id will be embedded in the query string of the URL, e.g. page.php?action=edit&post=123.
$page_data = get_page( $page_id ); // You must pass in a variable to the get_page function. If you pass in a value (e.g. get_page ( 123 ); ), WordPress will generate an error.

$content = apply_filters('the_content', $page_data->post_content); // Get Content and retain Wordpress filters such as paragraph tags. Origin from: http://wordpress.org/support/topic/get_pagepost-and-no-paragraphs-problem
$title = $page_data->post_title; // Get title
echo $content; // Output Content
?>
</div>

<?php

$taxonomy = 'category';

$param_type = 'category__in';

$term_args=array(

'orderby' => 'ID',

'order' => 'DESC'

);

$terms = get_terms($taxonomy,$term_args);

if ($terms) {

foreach( $terms as $term ) {

$args=array(

"$param_type" => array($term->term_id),

'post_type' => 'post',

'post_status' => 'publish',

'posts_per_page' => 6,

'caller_get_posts'=> 1

);

$my_query = null;

$my_query = new WP_Query($args);

if( $my_query->have_posts() ) { ?>

<div class="category section">

<h8><?php echo $term->name;?></h8>

<ul><?php while ($my_query->have_posts()) : $my_query->the_post(); ?>

<div class="galleryitem" id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><img src="<?php if ( function_exists('p75GetThumbnail') )echo p75GetThumbnail($post->ID); ?>" alt="<?php the_title(); ?>" /></a>

<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title2('', '...', true, '50') ?></a></h3>
<div id="bottom-left"> <h3><?php if(function_exists('the_views')) { the_views(); } ?> </h3></div>



</div>
<?php endwhile; ?>

</ul>

</div>

<?php }

}

}






wp_reset_query(); ?>

</div> <!-- maincontent -->

<div id="pagenavi">
<div id="older" class="alignleft"><?php next_posts_link('Older Entries') ?></div>
<div id="newer" class="alignright"><?php previous_posts_link('Newer Entries') ?></div>
</div>

</div> <!-- contentwrap -->

<?php get_footer(); ?>

Answers (3)

2011-10-27

S├ębastien | French WordpressDesigner answers:

not sur to understand.

If i look at globalstarhiphop.com, there is 7 dates. For each date, there is the post published at this date.
The navigation go to the next date.

So in the homepage, we have 7 dates, and in the next page we have the 7 next dates.
Like that :

HOMEPAGE

Oct 26 2011
post1 of this date
post2 of this date
etc...
Oct 25 2011
post1 of this date
post2 of this date
etc...
Oct 24 2011
post1 of this date
post2 of this date
etc...
Oct 23 2011
post1 of this date
post2 of this date
etc...
Oct 22 2011
post1 of this date
post2 of this date
etc...
Oct 21 2011
post1 of this date
post2 of this date
etc...
Oct 20 2011
post1 of this date
post2 of this date
etc...

------------------------->PAGE 2

Oct 19 2011
post1 of this date
post2 of this date
etc...
Oct 18 2011
post1 of this date
post2 of this date
etc...
Oct 17 2011
post1 of this date
post2 of this date
etc...






Is it what you want ? You want 7 categories in the home (with the 6 last post of each category) and 7 next cat├ęgories in the next page ??
like that :

HOMEPAGE :

CATEGORY ID=100 (for example)
6 most recent posts of this category

CATEGORY ID=99 (for example)
6 most recent posts of this category

CATEGORY ID=98 (for example)
6 most recent posts of this category

CATEGORY ID=97 (for example)
6 most recent posts of this category

CATEGORY ID=96 (for example)
6 most recent posts of this category

CATEGORY ID=95 (for example)
6 most recent posts of this category

CATEGORY ID=94 (for example)
6 most recent posts of this category

CATEGORY ID=93 (for example)
6 most recent posts of this category

------------------------->PAGE 2

CATEGORY ID=92 (for example)
6 most recent posts of this category

CATEGORY ID=91 (for example)
6 most recent posts of this category

CATEGORY ID=90 (for example)
6 most recent posts of this category

or do you want the same categories on the next page, but the next posts
like that :


------------------------->PAGE 2
CATEGORY ID=100
6 next recent posts of this category
(post7 -> post12)

CATEGORY ID=99
6 next recent posts of this category
(post7 -> post12)

CATEGORY ID=98
6 next recent posts of this category
(post7 -> post12)

CATEGORY ID=97
6 next recent posts of this category
(post7 -> post12)

CATEGORY ID=96
6 next recent posts of this category
(post7 -> post12)

CATEGORY ID=95
6 next recent posts of this category
(post7 -> post12)

CATEGORY ID=94
6 next recent posts of this category
(post7 -> post12)

CATEGORY ID=93
6 next recent posts of this category
(post7 -> post12)

2011-10-26

Maor Barazany answers:

Just after this line

if ($terms) {


Add this -


$terms = array_slice($terms, 0, 7);



Maor Barazany comments:

Sorry, my reply will only give you last 7 categories, but I forgot you asked for pagination too.
Will think about it and post soon again.


Maor Barazany comments:

I think that for the pagination you will be needing to build custom pagination with php.
If I understood correctly, you want to have 6 posts grouped by from each category, displaying 7 categories in each page.
WP archive pages show archives of single post items per term (category, tag, custom taxonomy), and paginate the single items.
You want to paginate the terms themselves, and I don't know a way to do that without developing custom pagination with php based on the items you want to paginate through (the terms).


rod rideau comments:

i think there is a way
by placing the correct value and code after the $my_query = new WP_Query($args);

if( $my_query->have_posts() ) { ?>

then moving the <div id="pagenavi">
<div id="older" class="alignleft"><?php next_posts_link('Older Entries') ?></div>
<div id="newer" class="alignright"><?php previous_posts_link('Newer Entries') ?></div>
</div>

before reset query
this should work right?

and the other option would be
setting the pagination by the 7 times 6 (number of post )
after 42 post create next page


Maor Barazany comments:

I tried to look at globalstarhiphop.com and my antivirus yelled it has a malware script there.


Maor Barazany comments:

I think that what you suggested won't work (have you tried it?)
your <em>$my_query->have_posts()</em> is within a foreach loop, which loops the categories, and for each one of them instantiates a new WP_Query object to show the 6 posts.

Moving the pagenavi before reset query will look on the last query, and not the sum of all different WP_Query Objects.


rod rideau comments:

what software are u using for virus protection I need to test that.. thanks.
yeah I tried moving it.. it didn't work. so how do I get it to look at the sum of all queries?


Maor Barazany comments:

As I wrote in my previous reply - you should use php to develop it and combine them all, but you will have to do develop also custom pagination, since WP pagination is not intended naturally to do what you want to.

I use ESET NOD32 for virus protection.

2011-10-26

Abdessamad Idrissi answers:

If I understand your question; you need to display all the latest posts from seven categories? what are the idies of this categories?
Could you explain more :)


rod rideau comments:

what are indies
look at globalstarhiphop.com