Forums

Different sidebar content on different pages? (9 posts)

  1. inbetweendays
    Member
    Posted 1 year ago #

    I was wondering, what is the best way to have different sidebar content for each subpage on my WordPress site? I am attempting to use WordPress as a CMS and not really a blog at all. I love it's ease of use, and ease of use for clients. This however is one task I have been unable to figure out.

    Just to clarify, I want the top navigation to remain the same through all pages (Home, About Us, Contact, etc), but have different content in the sidebar of each page.

  2. syncbox
    Member
    Posted 1 year ago #

    use an if statement

    <?php if (is_page(1)) {echo ('whatever you are wanting for this page'); }
    else if (is_page(2)) {echo ('whatever you are wanting for this page'); }
    else {echo ('whatever you are wanting for all other pages that are the ones above'); }
    ?>

    if you have 2 or more pages that use the same stuff, you can shorten your statements and arguments -

    <?php if (is_page(1) || is_page(17) || is_page(42) {echo ('whatever you are wanting for this page'); }
    else if (is_page(2)) {echo ('whatever you are wanting for this page'); }
    else {echo ('whatever you are wanting for all other pages that are the ones above'); }
    ?>

    hth

  3. inbetweendays
    Member
    Posted 1 year ago #

    Works great... thanks! I guess the root of the problem was that I am just not that experienced in PHP yet.

  4. simonsopinion
    Member
    Posted 1 year ago #

    Is there an available plug-in that does this function?

    More specifically, this is what I'm trying to accomplish:

    1. I'm creating a series of posts...e.g. Posts 1-10.
    2. I want all visitors to start with post #1, and go thru the entire series sequentially. No forward jumping or skipping.
    3. For example, if the viewer is reading post #3, then the sidebar will only have links for post #1 and post #2. Post #4 thru #10 is not yet available.
    4. I will later send an email to give them access to the next post...until the entire series is completed.

    Is there any plugin that I can use for this?

  5. moshu
    Moderator
    Posted 1 year ago #

    Not really.
    But in any well designed theme when viewing a single post (#3) you have links to posts #2 and #4. No need for the sidebar.

    And next time start your own topic: Pages and posts have nothing in common, so your question is absolutely NOT related to this topic.

  6. vintagemaniac
    Member
    Posted 11 months ago #

    Just thought I'd add that you can use include also/instead;

    <?php if (is_page(1)) {include ('sidebar1.php'); }
    else if (is_page(2)) {include ('sidebar2.php'); }
    else {include ('sidebar.php'); }
    ?>

    Achieves the same result, just another approach. =)

  7. adrockmk2
    Member
    Posted 8 months ago #

    I'm new to this whole world, but I want to have this feature in my blog...where do I insert this code?

    Thanks!

  8. artsakh
    Member
    Posted 8 months ago #

    Same as adrockmk2 ...
    Where do I have to put it?

  9. moshu
    Moderator
    Posted 8 months ago #

    INstead of the get_sidebar call in your Page template(s).

Topic Closed

This topic has been closed to new replies.

About this Topic