Output specific post from a category in WordPress
Let's say you slice a website and need a nicely looking block in a sidebar with one recent post from certain category. Like in case with this one below: Daily Style Quote.
Logically following you need to run "the loop" and ask WordPress for just one post from just this particular category.
Here we go:
<div id="dailyStyleQuote"> <div id="quoteText"> <?php query_posts('category_name=Daily Style Quote&posts_per_page=1'); ?> <?php while (have_posts()) : the_post(); the_content(''); ?> </div> <div id="quoteBottom"> <?php the_time('l, F j, Y'); ?> <?php $category_id = get_cat_ID( 'Daily Style Quote' ); $category_link = get_category_link( $category_id ); ?> <a href="<?php echo $category_link; ?>">archive</a> </div> <?php endwhile; ?> </div>
You might also like
| WordPress: drop-down pages menu with jQuery magic Using Wordpress as a content management system (CMS) for a web site is a great idea. You get both - static... | Desktop website performance tool – Apache JMeter Just a post ago i was wondering about testing my website's performance under heavy load and did this... | Why Design Your Own WordPress Theme? If your site runs in Wordpress, then you will have no doubt already encountered the concept of using... | Page permalinks in WordPress Got myself puzzled for a bit while slicing a Wordpress theme this weekend on how to get a permalink to... |
No comments yet.
Leave a comment
About
Advertisment
Read more
Breathtaking views of Yosemite Park: I just have to say here - the place is gorgeous. And it is totally worth driving for about 4-5 hours...
Log only certain file types being downloaded from your website with nginx access_log directive: Say you host a website where you have workshops in PDF and would like to get statistics on how many ...
How to rent a cheap apartment in New York City: Just like this guy wrote - paying $2450 for a 500 sq. ft 1 bedroom in New York City is a fact. A fa...
Simulating high-traffic for Linode VPS via LoadImpact: Thanks to the opportunity given to me by guys from LoadImpact.COM i recently tested my Linode 512 MB...
Apache vs. Nginx - testing performance under heavy load: It has come to my attention, when a client of mine recently experienced unexpected traffic spike, th...
Recent works / current clients
- BellatAuto Inc - New York / New Jersey used car auto dealer: design and coding.
- Colette Maison Lumiere - multimedia artist: design and coding for the CMS.
- Complete Body & Spa - New York City personal training and gym management company: Wordpress template coding.
- DaleStyle Blog Dale Sudakoff’s fashion blog: Wordpress template coding.
- DoctorKalitenko.COM - Sergey Kalitenko : antiaging hollistic doctor performing bioidentical replacement therapy. CMS coding and design.
- Great Jones Spa - premiere New York City Day Spa: coded and designed website and storefront




