WordPress.org

Ready to get started?Download WordPress

Forums

the million dollar TEXT WIDGET question (6 posts)

  1. presseroo
    Member
    Posted 3 years ago #

    So i figured out how to have a different header background image on everyone of my WP3 pages.

    Yet, the next mountain to claim now is to also have different TEXT widget boxes on every page (that i would use to explain each of the header images as there is plenty of empty space for that in my sidebar).

    I am already using the BODY CLASS
    <body class="page page-id-2 page-parent">
    to distinct each page, but now, how do i alter the CSS to achive above??

    Currently i have a mere
    /* Sidebar - Texts */

    .sidebar .textwidget {
    padding: 0 10px 20px 10px;
    }
    bit of code for the text widget, but i wonder if and how to start adding code to have a different text widget displaying different text on different pages - somehow i think it's not as easy as just altering the CSS despite the BODY CLASS??

    Maybe i would have to actually also alter the sidebar.php file, in which i currently only have:
    <div class="sidebar">

    <h3>Die Themen:</h3>

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

    but also here, how to fit in the various textwidgets so that they also show up as such in my Widgets section and can be written into each individually??

  2. aphill70
    Member
    Posted 3 years ago #

    You could simply add some code like this to your sidebar.php:

    <?php
      if(is_page('page-slug')) : ?>
        text to display
    <?php elseif(is_page('page-slug')) : ?>
        text to display
    <?php elseif(is_page('page-slug')) : ?>
        text to display
    <?php endif; ?>

    You could simply repeat the elseif pieces of code until you have handled all your pages. The other option would be to create a unique sidebar widget area for each page and do something similiar to the above just using different dynamic_sidebar registration and then you could just assign the widget to the correct sidebar.

    Hope this helps

  3. presseroo
    Member
    Posted 3 years ago #

    the good news first - no harm done.

    the bad news; no show of any text.
    I have inserted this:

    <?php
    if(is_page('page-id-7')) : ?>
    text to display here
    <?php elseif(is_page('page-id-16')) : ?>
    text here 2
    <?php elseif(is_page('http://astroberatung.cz.cc/?page_id=23')) : ?>
    and text to display here 3
    <?php endif; ?>

    (meaning i also tried full URL instead of just page-id)
    but no matter, nothing sowing up at all - almost thought it would be to easy.... now what??

  4. aphill70
    Member
    Posted 3 years ago #

    use

    <?php
      if(is_page(7)) : ?>
        text to display
    <?php elseif(is_page(16)) : ?>
        text to display
    <?php elseif(is_page(23)) : ?>
        text to display
    <?php endif; ?>
    ?>

    Also be sure these are actual pages and not posts because you will have to use a different template tag if these are posts.

  5. presseroo
    Member
    Posted 3 years ago #

    Thanks a million aphill70
    we are getting somewhere, only that i have now a ?> to many...
    text 2 to display ?>

    Probably the final statement came along twice??

    Yep, took that out and we're done, who knew WP could be this easy!

  6. aphill70
    Member
    Posted 3 years ago #

    Glad i could help sorry about the typo

Topic Closed

This topic has been closed to new replies.

About this Topic