WordPress.org

Ready to get started?Download WordPress

Forums

Add New Sidebar Information For Each Page (5 posts)

  1. coreymcollins
    Member
    Posted 3 years ago #

    So, I know that the title of this will be a seemingly short answer - just create a sidebar for each new page. But that's not exactly what I'm looking for.

    The site I'm creating will post free albums from bands looking to get their stuff out there. When a new release comes up, I'd like to add it to the site by adding a new Page. Now, the site has two main DIVS - content and sidebar.

    The main content of the post/Album Pages will be the lyrics/any notes that go along with the album. In the sidebar, I'd like to display album art, a track listing and the download link. However, I'm not sure how to go about this for each new album.

    I worked a little on a site for someone recently - they had created the full WP site and I was just taking over updates and general day-to-day management. In some of the Pages they had created, there was a block of text at the bottom just wrapped in an H2 tag. All of the rest of the content appeared in the main body of the website while this H2 text appeared in the sidebar. I don't really know how it works, but that's the kind of thing I'm looking for.

    Any hints?

    Thanks so much!

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    You need to look at get_posts or WP_Query plus conditionals.

  3. coreymcollins
    Member
    Posted 3 years ago #

    I appreciate the response, but would you be able to point me a little further toward what I'm looking for? I'm looking at the WP_Query stuff, but it seems to be focused on grabbing posts and pages that fit certain criteria. What I'm looking to do is take certain information entered as part of a Page (wrapped in a DIV, perhaps?) and have it display in the sidebar rather than in the main body. I'm not sure if I was totally clear in my post, or perhaps there's a specific part of the WP_Query that I should be looking at for that sort of information.

    Thanks!

  4. esmi
    Forum Moderator
    Posted 3 years ago #

    You cannot grab part of a Page or Post. You have to grab the whole Page or Post. What you do with it after you pulled it from the database is then just down to your needs and your PHP programming skills but I wouldn't recommend parsing Post/Page content for specific blocks of content within a Page/Post. That could end up slowing your site down significantly.

  5. cappybara
    Member
    Posted 3 years ago #

    I end up having to do this all the time for clients who want different data in the sidebar on each page.

    The best method I've found is using the Reusables plugin: http://wordpress.org/extend/plugins/reusables/

    It's unfortunately out of date, and written for PHP4 (you might have to replace a few <? items with <?php to get it work in certain environments), but it does its job well. Just create a Reusable Region in your sidebar, then make a new Reusable every time you make a new album, and select that reusable on the edit menu for that Page.

    Another, cleaner approach that doesn't rely on plugins you might consider is using add_meta_box to directly add that information on each page as meta which you can access with a variety of functions. This approach is a little code heavy, but there are several plugins out there that can automate much of the process for you, and it leads to much less work on your end.

    Hope this helped!

Topic Closed

This topic has been closed to new replies.

About this Topic