Results 1 to 9 of 9

Thread: php wordpress wp_get_archives

  1. #1
    Join Date
    Jan 2006

    php wordpress wp_get_archives


    Not sure if this is the appropriate place to ask this.

    I have a blog using wordpress. i have customized it quite a lot and continue to do so. I am currently using the function wp_get_archives to get the number of posts created in each month. However i want to format these results on my blog in another way rather than just a list etc.

    currently the output is:
    <li><a href='url' title='May 2008'>May 2008</a>&nbsp;(3)</li>

    I would like to be able to parse this output and then print it in a different format. I am having a tough time knowing how to parse the output.

    Any info would be great, preferably using php.


  2. #2
    Join Date
    Feb 2003
    Aberdeen, Washington, USA
    Can you expand a bit more on how exactly you would like to display your archives? I may be able to help you...

  3. #3
    Join Date
    Jan 2006
    Thanks Jick,

    So my ultimate goal is to create a table for each calendar year.

    For 2007 the table will have 2 rows and 12 columns. Row one will contain Jan, Feb, Mar etc and row two will contain the number of posts for the month in the cell above it. Both the month and the number of posts will be clickable.

    Then underneath this 2007 table i will have a 2008 table.

    Each table will span the column with of my blog which is about 900 pixels and the height of the table will be about 80 pixels

    Thanks again

  4. #4
    Join Date
    Feb 2003
    Aberdeen, Washington, USA
    Shoot! I'm so sorry I didn't get back to you. I totally forgot about this thread. I just now noticed it again.

    Would you mind making a little image which illustrates what you want? Even something as simple as a BMP from Windows Paint that you throw together real quick or something. Or even a mock-up HTML file if you want to go that far. I just want to be sure what exactly you're going for. I think I might get what you're saying but I just want to be really sure.

    Sorry again...

  5. #5
    Join Date
    Jan 2006
    No problem Jick. It is the holidays after all!!

    So i have attached a jpg of the table. Of course i will end up creating some css for it to make it fit in with my blog, but for now this is the basic style i am looking for.

    Attachment 12005

    thanks again

  6. #6
    Join Date
    Feb 2003
    Aberdeen, Washington, USA
    OK! I see what you mean. I'm gonna do some testing to see how I can get that to work. I think I have an idea. Usually I'd just be trying to explain to you how to do it but in this instance I think it might be better for me to figure it out and then try to explain how I did it. I'll post back when I have something. Shouldn't be too long.

  7. #7
    Join Date
    Feb 2003
    Aberdeen, Washington, USA
    Alright, I think I got it. Give this a try:
    PHP Code:
    <table id="archives">
      <?php $years $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date ASC");
    $years as $year) {
    $months $wpdb->get_col("SELECT DISTINCT MONTH(post_date) FROM $wpdb->posts WHERE YEAR(post_date) = $year AND post_status = 'publish' AND post_type = 'post' ORDER BY post_date ASC"); ?>
          <td><?php echo($year?></td>
                <?php foreach($months as $month) {
    $month_text date('M'mktime(000$month1$year)); ?>
                  <td><a href="#month"><?php echo($month_text?></a></td>
                <?php ?>

                <?php foreach($months as $month) {
    $posts $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE YEAR(post_date) = $year AND MONTH(post_date) = $month AND post_status = 'publish' AND post_type = 'post' ORDER BY post_date ASC"); ?>
                  <td><a href="#month"><?php echo($posts?></a></td>
                <?php ?>
      <?php ?>
    Let me know how that works out. Hopefully that does what you need. I think the code is pretty simple. You should be able to tell what it's doing I think...

  8. #8
    Join Date
    Jan 2006
    Cheers Jick,
    Sorry for the late reply.

    That looks like it works! Thanks a lot
    I tested it on my sample blog and all seems good. I just need to create the links and format the table. I'll let you know if i have anymore problems

    Again, i really appreciate you helping me out.

  9. #9
    Join Date
    Feb 2003
    Aberdeen, Washington, USA
    No problem at all! I hope it all works out for you.

    Be sure to come back and mark the thread as resolved if everything works good.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.10298 seconds
  • Memory Usage 2,941KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (9)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (73):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates