Forums

[resolved] Displaying Pages in Sidebar (3 posts)

  1. michaeldupuisjr
    Member
    Posted 3 years ago #

    I'm wondering if there is a way to display content from Pages in the sidebar (outside of The Loop).

    I'd like to create Pages that I can edit via the WordPress interface, and have that content update across the site's archive pages, category pages, the homepage, etc.

    For example, I might have a Page called Jazz_Sidebar_Pic. And that Page will simply be a picture of Miles Davis. I'd like to have that picture "pulled" into the sidebar of my Jazz category pages, and when I want to change the picture to Charles Mingus, all I'll need to do is edit the Jazz_Sidebar_pic page.

    I think this is pretty simple, but I can't figure out the template tags to use (get_page()?). Example code would be greatly appreciated.

    Thanks!

  2. stvwlf
    Member
    Posted 3 years ago #

    to do it by page slug:

    <?php $about_page = get_page_by_title('about');
    echo "<p>$about_page->post_content</p>"; ?>

    put the code in your sidebar.

    To selectively display the page (only when a condition is true)

    <?php
    if ( ... condition ...) {
      $about_page = get_page_by_title('about');
      echo "<p>$about_page->post_content</p>"
    } elseif ( ... condition ...) {
      $another_page = get_page_by_title('another');
      echo "<p>$another_page->post_content</p>"
    } ?>
  3. michaeldupuisjr
    Member
    Posted 2 years ago #

    Great -- thank you very much!

Topic Closed

This topic has been closed to new replies.

About this Topic