retrieve first post in category page?
-
anyone know how to retrieve the first post in the category page?
when i say the the first post i mean the first post not the latest post…
-
what do you exactly mean?
first posts = the post you entered first (The oldest post)
am i right?
yes from the category page
okay use this code
$category_post = new WP_Query('category_name=PUT YOUR CATEGORY NAME&showposts=1&orderby=date&order=DESC'); while($insider_ideas -> have_posts()) : $insider_ideas -> the_post(); //here you can anything you want the_title(); //title the_content(); //The contents endwhile;
hmm doesn’t seem to work also this is in the category page so I’m not specifying specific categories.
okay now i’m so confused. you wanted to retrieve oldest (first post) of the particular category page, am i right?
or you want order all the posts oldest – latest?
please paste your code if you can so i can do necessary amendments.
not a particular category, every category in the category page, so for example in the foods category page it retrieves its first post than in the wine category page it retrieves that first post and so on and so on… till it does that for all the category pages.
okay understood…. will you be able to send me your archive page code?
<?php get_header(); ?> <?php if (have_posts()) : ?> <div class="post"> <table class="category_description"> <tr><td rowspan="2" valign="middle"> <div class="category_image"></div> </td> <td height="120px" class="series_info"> <span style="font-size:16px; font-family:Arial; color:#1569C7"><strong>Series Information</strong></span> <table> <tr> <td><span style="font-size:14px; font-family:Arial; color:#A4A4A4"><strong>Title:</strong> <?php single_cat_title(''); ?></span></td> </tr> <tr> <td><span style="font-size:14px; font-family:Arial; color:#A4A4A4"><strong>Genre:</strong> Currently not availible</span> </td> </tr> </table> </td> </tr> <tr> <td class="series_description"> <span style="font-size:16px; font-family:Arial; color:#1569C7"> </td> </tr> </table> </div> <?php $titlecount = 0; $titlecount2 = 0; $titlecount3 = 0; $episodecount = 1; $episodecount2 = 1; ?> <?php while (have_posts()) : the_post(); ?> <?php $all_the_tags = has_tag(); if (!($all_the_tags)){ ?> <?php $episodecount++; ?> <?php } else { ?> <?php if ($all_the_tags); $all_the_tags = get_the_tags(); foreach($all_the_tags as $this_tag) { if ($this_tag->name =="nova") { ?> <?php $episodecount2++; ?> <?php } else { // it's neither, do nothing ?> <!-- not tagged as one or the other --> <? } } } ?> <?php endwhile; ?> <?php $posts=query_posts($query_string . '&order=dsc'); while (have_posts()) : the_post(); ?> <?php $all_the_tags = has_tag(); if (!($all_the_tags)): ?> <?php $episodecount--; ?> <?php $titlecount++; if($titlecount == 1): ?> <table width="635px" class="category_posts"> <tbody> <tr style="border-left:1px solid #D1D1D1; border-top:1px solid #D1D1D1; border-right:1px solid #D1D1D1;"> <th class="category_td" style="width:15%; color: #34A9D6; font-size: 13px; text-align: center;"><strong>Episode</strong></th> <th class="category_td" style="width:70%; color: #34A9D6; font-size: 13px; text-align: center;"><strong>Title</strong></th> <th class="category_td" style="width:15%; color: #34A9D6; font-size: 13px; text-align: center;"><strong>Views</strong></th> </tr> </tbody> </table> <?php endif; ?> <?php if($titlecount%2 == 0) { ?> <table width="635px" class="category_posts2"> <tr> <td class="category2_td1" style="width:15%;"><span class="episode"><a href="<?php the_permalink() ?>" rel="bookmark" >Episode <?php echo $episodecount ?></span></td> <td class="category2_td2" style="width:70%;"><span class="subtitle"><a href="<?php the_permalink() ?>" title="<?php echo the_subtitle(); ?>" rel="bookmark" ><?php echo the_shorten_subtitle(); ?></a></span></td> <td class="category2_td3" style="width:15%;"><?php the_views(); ?></td> </tr> </table> <?php } else { ?> <table width="635px" class="category_posts2"> <tr> <td class="category_td1" style="width:15%;"><span class="episode"><a href="<?php the_permalink() ?>" rel="bookmark" >Episode <?php echo $episodecount ?></a></span></td> <td class="category_td2" style="width:70%;"><span class="subtitle"><a href="<?php the_permalink() ?>" title="<?php echo the_subtitle(); ?>" rel="bookmark" ><?php echo the_shorten_subtitle(); ?></a></span></td> <td class="category_td3" style="width:15%;"><?php the_views(); ?></td> </tr> </table> <? } ?> <?php endif; ?> <?php endwhile; ?> <div style="margin-top: 10px"> <?php while (have_posts()) : the_post(); ?> <?php $all_the_tags = has_tag(); if ($all_the_tags): ?> <?php if ($all_the_tags); $all_the_tags = get_the_tags(); foreach($all_the_tags as $this_tag) { if ($this_tag->name =="nova") { ?> <?php $titlecount2++; $episodecount2--; if($titlecount2 == 1): ?> <table width="635px" class="category_posts"> <tbody> <tr style="border-left:1px solid #D1D1D1; border-top:1px solid #D1D1D1; border-right:1px solid #D1D1D1;"> <th class="category_td" style="width:15%; color: #34A9D6; font-size: 13px; text-align: center;"><strong>OVA</strong></th> <th class="category_td" style="width:70%; color: #34A9D6; font-size: 13px; text-align: center;"><strong>Title</strong></th> <th class="category_td" style="width:15%; color: #34A9D6; font-size: 13px; text-align: center;"><strong>Views</strong></th> </tr> </tbody> </table> <?php endif; ?> <?php if($titlecount2%2 == 0) { ?> <table width="635px" class="category_posts2"> <tr> <td class="category2_td1" style="width:15%;"><span class="episode"><a href="<?php the_permalink() ?>" rel="bookmark" >OVA <?php echo $episodecount2 ?></span></td> <td class="category2_td2" style="width:70%;"><span class="subtitle"><a href="<?php the_permalink() ?>" title="<?php echo the_subtitle(); ?>" rel="bookmark" ><?php echo the_shorten_subtitle(); ?></a></span></td> <td class="category2_td3" style="width:15%;"><?php the_views(); ?></td> </tr> </table> <?php } else { ?> <table width="635px" class="category_posts2"> <tr> <td class="category_td1" style="width:15%;"><span class="episode"><a href="<?php the_permalink() ?>" rel="bookmark" >OVA <?php echo $episodecount2 ?></a></span></td> <td class="category_td2" style="width:70%;"><span class="subtitle"><a href="<?php the_permalink() ?>" title="<?php echo the_subtitle(); ?>" rel="bookmark" ><?php echo the_shorten_subtitle(); ?></a></span></td> <td class="category_td3" style="width:15%;"><?php the_views(); ?></td> </tr> </table> <? } ?> <?php } else if (($this_tag->name =="Mov")||($this_tag->name =="mov")) { ?> <?php $titlecount3++; if($titlecount3 == 1): ?> <table width="635px" class="category_posts"> <tbody> <tr style="border-left:1px solid #D1D1D1; border-top:1px solid #D1D1D1; border-right:1px solid #D1D1D1;"> <th class="category_td" style="width:85%; color: #34A9D6; font-size: 13px; text-align: center;"><strong>Title</strong></th> <th class="category_td" style="width:15%; color: #34A9D6; font-size: 13px; text-align: center;"><strong>Views</strong></th> </tr> </tbody> </table> <?php endif; ?> <table width="635px" class="category_posts2"> <tr> <td class="category_td2" style="width:85%;"><span class="subtitle"><a href="<?php the_permalink() ?>" rel="bookmark" ><?php echo ShortenTitle(the_subtitle()); ?></a></span></td> <td class="category_td3" style="width:15%;"><?php the_views(); ?></td> </tr> </table> <?php } else { // it's neither, do nothing ?> <!-- not tagged as one or the other --> <? } } ?> <?php endif; ?> <?php endwhile; ?> </div> <p><?php next_posts_link('? Older Entries') ?> <?php previous_posts_link('Newer Entries ?') ?></p> <?php else : ?> <div class="post"> <h2>Not Found</h2> <p>Sorry, but you are looking for something that isn't here.</p> <?php include (TEMPLATEPATH . "/searchform.php"); ?> </div> <?php endif; ?> <?php get_sidebar(); ?> <?php get_footer(); ?>
tried your code there are lot of errors giving.
any way this is the code you should use.
<?php $cat_type = single_cat_title('',false); $first = new WP_Query('category_name='.$cat_type.'&showposts=1&orderby=date&order=ASC'); while($first -> have_posts()) : $first -> the_post(); //Put what ever you want to appear (Title , Content etc.) the_title(); the_content(); endwhile; wp_reset_query(); ?>
you should put this code after this line
<?php if (have_posts()) : ?>
and before while loop start.
so this code will retrieve your very first post. after that your normal posts will appear.
well I’m just starting a new loop so the code i gave you is kinda irrelevent but thanks I’ll try it
– it worked perfectly thanks alot, this way is alot easier than altering the category so it allowed me to rate it thanks.
- The topic ‘retrieve first post in category page?’ is closed to new replies.