WP Theme Lesson #6c: Get Archives and Links

tutorial-series.gif Today’s lesson is fairly easy. You’ll learn how to call for an archive link listing and the blogroll links. Tomorrow’s lesson is the calendar and search form.

Before we start, I want to explain why I’ve been breaking down my lessons into smaller lessons. Everything that you’re learning took self-taught people MONTHS to digest! It’s important that you understand everything I’m showing you the first time around so you won’t have to go back and re-check.

Step 1 – Add archive links.

Type the following codes in the Sidebar area, under the Categories listing:

<li><h2><?php _e(‘Archives’); ?></h2>
<ul>
<?php wp_get_archives(‘type=monthly’); ?>
</ul>
</li>

Give it some tab spacings for organization. Let’s see if your codes match mine:

add-archives.gif

Save your file, refresh the browser, here’s the result:

archives.gif

What happened?
You used the wp_get_arhives() PHP function with the type attribute and monthly value to call for the archive links by month.

  • <li> – open list item
  • <h2> – open sub-heading
  • <?php _e(‘Archives’); ?> – text of the sub-heading
  • </h2> – close sub-heading
  • <ul> – open unordered list under the sub-heading, within the list item
  • <?php wp_get_archives(‘type=monthly’); ?> – call for archive links by month, nest each link within <li> and </li> tags. If you check your source codes (View > Page Source). You’ll see that wp_get_archives() generated list item (LI) tags for each link, just like the wp_list_cats() function.
  • </ul> – close the unordered list sitting under the sub-heading
  • </li> – close list item

Step 2: Add blogroll links

Type the following codes under the Archives link listing:

<?php get_links_list(); ?>

add-blogroll.gif

Save, refresh, and here’s the result:

blogroll.gif

By default, my blogroll is no different from yours. Here’s how it looks in the source codes:

blogroll-source.gif

The organization is not all there because the get_links_list() function generates the codes for you, just like the wp_list_pages() function you learned about, from yesterday’s lesson. However, it stuck with rule number one, which is close everything in the order that you open them. I circled the list item and unordered list tags for you to see.

That’s the end of today’s lesson. Come back tomorrow for the calendar and search form.

Follow this WordPress Theme Tutorial Series from the beginning.

What's Next?

Hey, I just love your lessons, there are very helpful and very easy to understand. But I have one question. I’m using WordPress and I have found a nice theme that I have modified. The problem is that I want to change the column for my sidebar, it’s a two column now and I want to change it to a one column sidebar and leave the extra space for the index file. How do I do that?

Small Potato:

Please post this at http://www.wpdesigner.com/forums and link me to the theme you’re talking about so I can help you. Thanks.

[...] ID, Link Title #5e Posts Nav Link #6 Sidebar (and Categories) #6b Page-Link Listing (wp_list_pages) #6cGet Archives and Links #6d Search Form and Calendar #6e Widgetizing Sidebar #7 [...]

Cathy:

Love this learning opportunity! I am having trouble with php_e. It returns this: Fatal error: Call to undefined function php_e()

It happened in an earlier lesson and I simply changed it to display without the php_e but when it happened today I started wondering why this might happen. Any clue?

Thanks

Cathy:

Oh – I just found my problem! I was not leaving a space between php and _e. Sorry – silly me.

chris:

SP, where can we get a documentation of a list of attributes that we can use?

like

chris:

SP, where can we get a documentation of a list of attributes that we can use?

like php wp_get_archives(‘type=monthly etc..

wordpress.org DOCS

wow that was simple, especially the blogroll links lol, i just have to remember that one code.

e}{odus:

very good!!

I just saw on the following blog a drop down list for both
archives and categories. I would love to learn how to do THAT.

see it at http://bothack.wordpress.com/

nada

Small Potato;

I have a query here, why wouldn’t the Blogroll be the default size like pages?

Is it always like this that i don’t have to resize the word ‘Blogroll’?

Small Potato,

Thanks so much for your great tutorial! Before, I didn’t get along with PHP at all and had merely no idea about the possibilities of CSS. Thanks to your tutorial, I’m now able to customize my own blog with my own design. Thanks again!

My question: Is it possible to open blogroll links in a new browser window (target=_blank)?

With only one command involved (php get_links_list), I can’t imagine how to do that. Thanks for any help in advance!

Many greetings from Switzerland

Bubble

You can control that through your links management page.

I am wondering how one would go about using wp_list_bookmarks in place of get_links_list or get_links.

Any thoughts on how to modify this?

if you want your theme to stay up to date, simply replace get_links_list with wp_list_bookmarks

Cozmika:

Hy!

Can you tell something more about css editing blogroll


Step 2: Add blogroll links

Type the following codes under the Archives link listing:

How can I edit it so it wouldn’t be Blogroll which is deafult)

Cheers :)

Go in links management, change the Blogroll category to something else.

Is there a way to control the title of the blogroll like we could with the pages list? This is really essential for my design.

No, but I’m not sure.

For reference I used wp_list_bookmarks(‘title_li=&categorize=0′);

SP,
Wow, what more can I say man? I am “one of those” people who have made several attempts to learn this whole WP and PHP thing with next to no success in the past. As you mentioned in the intro to this lesson, I try to digest too much too fast and seem to get lost (not to mention it takes true talent such as yours to really teach something like this). I am plugging away over the past 3 days in bits and so far, I’m with ya man. Experienced a few bugs trying to load the whole Xampp thing initially, and been working diligently to solve my own coding errors (the truest way to learn, I feel); so far soo good. Thanx a million bro. Hope your time devoted to this gives you your edge in your goal to a million!!

Thanks Erik, your comment is much appreciated. Although I haven’t posted anything about the million dollar challenge for a while, I’m working on it behind the scenes :)

how can I edit the ‘blogroll’ name to be something else? Such as ‘Links’ or ‘My Favorite Websites’?

wp_list_bookmarks(’title_li=TITLE HERE′);

where do i put that exactly? and do i have to add the
info? i tried a couple of different ways with no luck

Put that piece of code wherever you want the list to appear in your template :)

Sorry this piece of code!

<?php wp_list_bookmarks(’title_li=TITLE HERE′); ?>

yea it gives me an error for some reason. I tried taking out the and putting that one in and I get the error. I tried putting them both in, and I still get an error. LOL – I’m so clueless! Here’s the error I get after I save & refresh: Parse error: syntax error, unexpected ‘=’ in C:\xampplite\htdocs\wordpress\… on line 115. I know it’s talking about the ‘=’ symbol in there, but if I take that out, I would get an error either way. Any clue what I’m doin’ wrong… cuz I have NO idea! (btw, thanks for all your help)

The ul tags aren’t needed, validator make an error with those tags. Doens’t change anything to the outcome.

the ul tags are needed to code valid xhtml lists

Shaiful:

Greetings linnette,

Hope you solved the issue.

Else,

Do not copy and paste the codes.
Type it out.

Reason is because of the ‘ mark in between the brackets.

Cheers

david:

In terms of changing the title “BlogRoll”, I was able to do so through the Admin Panel of WordPress. It is under the ‘Blogroll’ heading, and ‘Categories’ subheading. You can either add a new category, or Edit the one called ‘BlogRoll’. I changed it to read “Links”, and it automatically updated.

Absolutely wonderful tutorial. Even though I know most of the code and what it does, I’m not frustrated and feeling like you’re baby talking to me. I am also still learning things through your tutorial. Which is the reason I’m using it. I’m a WordPress beginner.

My Comment: Do you have any idea why WordPress would make these codes behave in such different ways? For example: Categories and Archives don’t have the title already in the function, but Blogroll and Pages do. Why is that? They should have picked one way or the other to display them.

Thanks again for this tutorial, I am definitely going to suggest this to anyone who wants to customize WordPress.

I don’t know VIRA.

Ive been trying this before but always had to rush out so this is a nice easy step by step way for me to learn in a bit of free time (granted ill come back to keep checking what im doings correct) lol

serpentemx:

Hi man!, well firstly thank you so much for dedicating this time to beginners like me, and now the question:

I’m having problems in this part of the tut.

I had to take out the

and replace it like this: Archives

otherwise it gives me an error.

could you help me please?

Thanks man!

Mark:

Hey men,

When i put the following code in my index.php:

Then i save it and refresh my browser but all i got was a white page, could you explain why and how i fix it? If possible, could you email my back. I want to learn this very much.

Greets from Holland!

jicoro:

Thanks again. I won’t get tired saying thank you…(kaawaan ka nang diyos) <—–GOD BLESS

[...] ????WP Theme Lesson #6c: Get Archives and Links [...]

I don’t even know if you still read these comments, seeing as how the domain has changed hands, but I figured I’d post anyway.

First off I’d like to say thanks for this tutorial. While I already know most of the concepts you painstakingly address, such as closing any open tags and explaining the purpose of function calls, I have a great deal of respect for your explanations. Even someone without a background in web coding or any form of programming should be able to grasp the ideas in your tutorials. I plan to express my thanks once I have my own website/blog up and running.

Regarding the code in the last screenshot in this lesson, the li tag for the Blogroll item has the id “linkcat-1″.
However, in my source code, this li has id “linkcat-2″ and class “linkcat”. Since this would affect my choice of selectors in my stylesheet, I was just wondering if you’d know the reason why I have a 2 instead of a 1 for the id, and why I have a class at all. There’s no id “linkcat-1″ anywhere else on the page.

Hope you get to see this. Thanks!

great tutorial!

i’d like to update the info here: get_links_list() has been depracated and you should now use: wp_list_bookmarks() instead. see http://codex.wordpress.org/Template_Tags/wp_list_bookmarks for more info.

Ziv, i have “linkcat-2? and class “linkcat” too, don’t know why.

[...] WP Theme Lesson #6c: Get Archives and Links oleh Small Potato diterjemahkan oleh Mochammad [...]

Is there a way to change the default of the Blogroll heading to ? Unlike the other sidebar sections, this has no “title line” to modify – so I assume it’s in a configuration file of some sort?

My code was stripped from my previous comment. I’m wanting to change the h2 tag of the word Blogroll to an h3 tag.

Nice & Congratulations… very good tutorial… :)

Kris:

The “Archives” is giving me an error. It won’t work and keeps coming up as

Fatal error: Call to undefined function php_wp() in (domain) on line 80

I’m using a Mac so I can’t use the Offline Word Press, so I made a dummy WP blog on my domain

CAN SOMEONE HELP ME?

Kris:

OOps, I typed that wrong. It says

FATAL ERROR: CALL TO UNDEFINED FUNCTION PHP_E IN (domain) ON LINE 80

Kris:

I don’t know what I did the fifth time, but the fifth time I typed it, it worked. Maybe I was making some mistake over and over again that I didn’t realize until now.

JOEK:

I’m not sure why but whenever I use I don’t see anything when I refresh but if I resort to using Archives it displays Archives as expected. I’ve checked my code thoroughly and don’t appear to have made any mistakes, so why am I not seeing anything?

Thanks
J

JOEK:

Ignore my post above, the code seems to have disappeared so now it makes absolutely no sense.

Fantastic!

To change the title of wp_list_bookmarks() you have to turn off categorization (otherwise, each category is used at a title:

wp_list_bookmarks(‘title_li=Links&categorize=0′);

note that it adds the H2 header tags for you (unlike wp_list_pages and wp_list_categories, where you have to add them yourself)

To get a consistent display, the code looks like this (replace braces with angle-brackets):

{ul}
{?php wp_list_pages(‘title_li={h2}Pages{/h2}’); ?}
{?php wp_list_categories(‘title_li={h2}Categories{/h2}&orderby=name&show_count=1&hierarchical=0′); ?}
{li}{h2}Archives{/h2}
{ul}
{?php wp_get_archives(‘type=monthly&show_post_count=1′); ?}
{/ul}
{/li}
{?php wp_list_bookmarks(‘title_li=Blogs&categorize=0′); ?}
{/ul}

Too bad there isn’t a wp_list_archives().

nice tutorial, we wish that we will find more details in every part of the tutorials in future