PDA

View Full Version : Wordpress Code Question



the goat
12-18-2008, 08:43 PM
I am trying to modify my sidebar and change what is currently a "blogroll" box into a "pages" box.

In the sidebar.php file I have this code:

<div class="box">
<ul>

<li>
<h3 class="sidebartitle" ><?php _e('blogroll'); ?></h3>
<ul class="list-blogroll">
<?php get_links('-1', '<li>', '</li>', '<br />', FALSE, 'id', FALSE, FALSE, -1, FALSE); ?>
</ul>
</li>
</ul>
</div>

And in the sylesheet I have this:

}
/*blogroll widget */
ul.list-blogroll li{
padding-left: 10px !important;


I tried changing blogroll to pages but to no avail, am I missing something simple or is this more complicated than I thought?

vangogh
12-18-2008, 08:53 PM
The WP template tag to show pages is wp_list_pages (http://codex.wordpress.org/wp_list_pages).

Try something like:



<div class="box">
<ul>

<li>
<h3 class="sidebartitle" >Your Heading Here</h3>
<ul class="list-pages">
<?php wp_list_pages; ?>
</ul>
</li>
</ul>
</div>

I changed the class from list-blogroll to list-pages. Just copy the same css in your stylesheet to the new class.

I think that should work.

the goat
12-19-2008, 06:42 PM
Thanks vangogh, that worked well except it adds an unclickable "pages" to the top of the nav section of the box. I took a screenshot so you can see what I mean, any idea where I went wrong?

I triple checked and the code is exactly what you recommended.

That second "Pages" above the "about" is what I mean

http://www.small-business-forum.net/attachment.php?attachmentid=15&d=1229730114

vangogh
12-19-2008, 08:21 PM
There are a couple of things you can try. It could be this line, though that might your main heading (like Meta below) which you probably want to want to keep.


<h3 class="sidebartitle" >Pages</h3>

I'm assuming you added Pages as your heading. One suggestion is removing that line and seeing if it's the one you want removed. I have a feeling this one is the Pages you want to keep.

The second suggestion and the one I think you're looking for is in how you use wp_list_pages. If you check the link I posted above you can see there are a lot of different arguments you can add to the tag. One of those arguments is title_li. If you don't specify it the default is that title_li displays the word Pages.

So to list the pages without the heading you want to use:


<?php wp_list_pages('title_li='); ?>

Just substitute the line above for the <?php wp_list_pages; ?> in the original code and you should be good to go.

For some added fun one of the arguments you can use and one I often end up using is 'exclude' Say you have 10 pages, but only want to show 8 of them in the menu. You can exclude the two you don't want to show from the list. You could also choose to include certain pages.

Some other things you can do are sort the pages in a few ways and control the depth of sub pages if you're using sub pages. Many of the other template_tags have their own set of arguments that can be used to control what the tags do.

the goat
12-19-2008, 09:43 PM
('title_li=') worked liked a charm, thank you so much for your help vangogh, I was pulling my hair out for a while there, and the people at the wordpress forums seem to be a little snobby when it comes to amateur code questions.

Oh and I use a plugin for excluding pages right now, it's cool to know I can do it with the code too, sometimes with code it seems like the more you learn the more you realize how little you know.

vangogh
12-19-2008, 09:59 PM
Glad to help. I learned a lot about working with WordPress by searching through the codex (http://codex.wordpress.org/). That's where the link to wp_list_pages above is located. You can do a lot with WordPress as long as you don't mind getting into the code a little.

I know what you mean about the WordPress forums. Some of the response come from people who clearly don't want to help. Not all. There are some helpful people there, but I do know the type of people you're talking about.

Yep, about the plugins. They do make your life easier, but there are some that make things easy by adding a lot of code when one minor change will do the same. If you want to learn more start reading the basics of how a theme is put together and then dive into the template_tags. You can also search through the conditionals. You can set something so it only shows on the home page of the blog and similar things.