Results 1 to 6 of 6

Thread: Wordpress Code Question

  1. #1
    Member Needs New Keyboard Array the goat's Avatar
    Join Date
    Aug 2008
    Location
    Beantown
    Posts
    167

    Default Wordpress Code Question

    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?

  2. #2
    Post Impressionist Array vangogh's Avatar
    Join Date
    Aug 2008
    Location
    Boulder, Colorado
    Posts
    13,546

    Default

    The WP template tag to show pages is wp_list_pages.

    Try something like:

    Code:
    <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.
    l Search Engine Friendly Web Design | Vanseo Design
    l Design, Development, Marketing, and SEO Tutorials | Steven Bradley's Notebook
    l Custom WordPress Themes |Get my book about Design Fundamentals

  3. #3
    Member Needs New Keyboard Array the goat's Avatar
    Join Date
    Aug 2008
    Location
    Beantown
    Posts
    167

    Default

    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

    Attached Images
    Last edited by the goat; 12-19-2008 at 11:45 PM.

  4. #4
    Post Impressionist Array vangogh's Avatar
    Join Date
    Aug 2008
    Location
    Boulder, Colorado
    Posts
    13,546

    Default

    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.

    PHP Code:
    <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 Code:
    <?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.
    l Search Engine Friendly Web Design | Vanseo Design
    l Design, Development, Marketing, and SEO Tutorials | Steven Bradley's Notebook
    l Custom WordPress Themes |Get my book about Design Fundamentals

  5. #5
    Member Needs New Keyboard Array the goat's Avatar
    Join Date
    Aug 2008
    Location
    Beantown
    Posts
    167

    Default

    ('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.

  6. #6
    Post Impressionist Array vangogh's Avatar
    Join Date
    Aug 2008
    Location
    Boulder, Colorado
    Posts
    13,546

    Default

    Glad to help. I learned a lot about working with WordPress by searching through the codex. 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.
    l Search Engine Friendly Web Design | Vanseo Design
    l Design, Development, Marketing, and SEO Tutorials | Steven Bradley's Notebook
    l Custom WordPress Themes |Get my book about Design Fundamentals

Posting Permissions

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