• Home
  • About

szehau's weblog

Life, Internet, Software, Gadgets, Programming and Investments

  • life log
  • internet
  • programming
  • software
  • working holiday
  • gadget
  • project

Recent WordPress Posts in Sidebar

January 5, 2006 01:32 by Sze Hau 7 Comments

I had tried out the code Recent WordPress Post in Sidebar suggested by EngLee. Although the code did shows the recent posts correctly but some functions (eg: is_page() and is_home() are not working properly when it is after the portion of the code. My guess is the wordpress loop in the code modified value of some global variables.

I have a workaround for it. Before using the is_home() or is_page() function, I save the returned in a temporay variable, call the recent posts loop, and use the temporary variable later when neccessary.

Today when I search for wp_get_archives() in WordPress WIki, I found that I can generate recent wordpress posts in the more easier way. Here is the code:


<li>
	<h2>Recent Posts</h2>
	<ul>
		<?php wp_get_archives('type=postbypost&limit=10'); ?>
	</ul>
</li>

Simple and tidy :)

More from my site

  • Vista Talks backs in Google Search ResultsVista Talks backs in Google Search Results
  • Gong Xi Fatt CaiGong Xi Fatt Cai
  • New wordpress theme for szehau.comNew wordpress theme for szehau.com
  • Working Holiday at New Zealand – The journey begunWorking Holiday at New Zealand – The journey begun
  • DmozDmoz
  • New WordPress Theme and BlogNew WordPress Theme and Blog

Filed Under: programming

About Sze Hau

Geek. Love programming. Coffee addicted. Married with a child. Working towards financial freedom.

Comments

  1. EngLee says

    January 5, 2006 09:21 at 9:21 am

    LOL. That function is so much easier!

    As for the is_home() or is_page() functions, I also faced the same problem. But I fixed it another way.

    if (is_home()) {

    } else if (is_page()) {

    }

    That would do the job. This means that if you want something to appear in home and page, you have to write it in both cases.

    Reply
  2. LcF says

    January 5, 2006 13:48 at 1:48 pm

    wordpess wiki is OLD. you should visit codex.wordpress.org for documentation.
    Here is the updated documentation for wp_get_archives:
    http://codex.wordpress.org/Template_Tags/wp_get_archives

    Reply
  3. Dawn Isaac says

    January 20, 2006 12:59 at 12:59 pm

    Awesome Thanks.

    Reply
  4. uri says

    March 21, 2006 21:02 at 9:02 pm

    Hi,
    could you explain your workaround for the is_page() disfunctioning after using EngLee’s method? I’m only a beginner with PHP so I couldn’t understand how to solve it from the explanations you both gave here.
    My problem is like that: I have a footer which can be wide (if it is a wide page) or narrow (for narrow page). I used EngLee’s method in this page:
    http://uriashi.com/?page_id=38
    (in the left sidebar, you can see I even used the_excerpt_rss() instead of the_title() in order to display the images that I put for each post)
    in the footer there’s an conditional if that says something like “if it is page 38 – display the wide footer”, but as you can see, after implementing the query_posts it messed it as you said and the footer displayed is the narrow one.
    thanks in advance,
    uri

    Reply
  5. szehau says

    March 21, 2006 21:16 at 9:16 pm

    Hi uri,

    Let say you have a code does something like this:

    // Call query_posts

    query_posts ("whatever");

    if (is_page()) {
    // dispaly A
    } else {
    // display B
    }

    Instead of doing that, change to this:

    // Save whatever is_xxx() function

    $is_page = is_page();
    $is_post = is_post();

    // Call query_posts

    query_posts ("whatever");

    if ($is_page) { // the different is here
    // dispaly A
    } else {
    // display B
    }

    if ($is_post) { // the different is here
    // dispaly C
    } else {
    // display D
    }

    Hope this will help :)

    Reply
  6. uri says

    March 21, 2006 22:31 at 10:31 pm

    It does! thanks a lot!

    Reply
  7. PeterVk says

    April 13, 2008 16:22 at 4:22 pm

    I know this post is a bit old – but thanks! Worked perfectly. Wish I’d found this earlier in the morning…

    Reply

Leave a Reply to PeterVk Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Email News Letter

Sign up to receive updates daily and to hear what's going on with us

  • Facebook
  • Google+
  • Instagram
  • Twitter

More Posts

5 Essential Things You Need To Have At Your Home During The COVID-19 Pandemic

June 1, 2021 22:15 By Sze Hau Leave a Comment

LED Downlight

Troubleshooting A Flickering LED Downlight

February 13, 2016 00:29 By Sze Hau Leave a Comment

Repair A Broken iPhone Lightning Cable

January 30, 2016 00:54 By Sze Hau Leave a Comment

Sponsored Links

Blog Network

  • Personal Fincance Personal Finance – Personal Money Tips, Stock Investment, Small Business and Make Money Online
  • Snippet IT Information technology news, ideas and experiences and opinions

szehau’s weblog

szehau is a software programmer that has strong interest in the world of programming and Internet. He is graduated in University of Malaya, Malaysia with a Bachelor’s degree in Software Engineering. He draws on his passsion for web programming to share with others how to build a successful websites.

Recent

  • 5 Essential Things You Need To Have At Your Home During The COVID-19 Pandemic
  • Troubleshooting A Flickering LED Downlight
  • Repair A Broken iPhone Lightning Cable
  • New Gadget – MacBook Pro with Retina Display (2015)
  • One Watt LED Night Light

Search

Tags

adsense advertisement baby blog blogtal Canon EOS 400D Chinese New Year Christchurch CNY DiGi electronic Facebook FBM Flickr Flickr Uploadr Google Google Maps Google Search Results Google Webmaster Central H1N1 income tax investment joke KLCI KLSE Lake Tekapo Maxis Maybank2u Motueka movie mutual funds New Zealand PC Fair 2009 Queenstown restaurant for dinner sharing stock trackback travel Twitter unit trust visa wordpress wordpress plugin working holiday

Copyright © 2025 · Magazine Pro Theme on Genesis Framework · WordPress · Log in