• Resolved poper

    (@poper)


    Hi,
    I’ve check this codex article about sidebar customization but i’ve one question.

    I want to use some specific code (in the sidebar) for several specific pages (i.e. code x for pages 8,9,10; code y for pages 1,35), according to the article this should work:

    <?php
    // let's generate info appropriate to the page being displayed
    if (is_home()) {
    // we're on the home page, so let's show a list of all top-level categories
    echo "HTML for home page";

    } elseif (is_category()) {
    // we're looking at a single category view, so let's show _all_ the categories
    get_calendar();
    echo "HTMl for categories pages";

    } elseif (is_single()) {
    // we're looking at a single page, so let's not show anything in the sidebar
    get_calendar();
    echo "HTML for single posts";

    } elseif (is_page()) {
    // we're looking at a static page. Which one?
    if (is_page('8')) {
    // our about page.
    echo "HTML for page 8";

    } else {
    // catch-all for other pages
    echo "<p>Vote for Pedro!</p>";
    }
    } else {
    // catch-all for everything else (archives, searches, 404s, etc)
    echo "<p>Pedro offers you his protection.</p>";
    } // That's all, folks!
    ?>

    I wonder if it’s possible to assign differents values to that piece of the code above:

    // we're looking at a static page. Which one?
    if (is_page('8')) {
    // our about page.
    echo "HTML for page 8";

    in order to use the HTML not only in page #8 but also in #4, 5 etc..
    I don’t know PHP so I don’t know if this is possible.
    Thanks in advance.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Absolutely! The “8” is just an example – you can use it with any of your page_id #s.
    And just a reminder, you can omit whatever you don’t need from that code: categories, single etc.

    Thread Starter poper

    (@poper)

    Thanks for you answer, but I understand that, but I want to know if that piece of code can be assigned to different pages at the same time (to avoid repeating code and increase the size of the file).

    // we’re looking at a static page. Which one?
    if (is_page(‘8 or 9 or 10‘)) {
    // our about page.
    echo “HTML for pages 8, 9 or 10”;

    I mean translate ‘8 or 9 or 10’ to PHP code.
    Thanks again and sorry for my English.

    I am not a coder by any means 🙁 – but I have seen examples around here like in this topic:
    http://wordpress.org/support/topic/30742?replies=3#post-173713

    Thread Starter poper

    (@poper)

    Thanks a lot moshu, I’m gonna try it

    Are you trying to do this?

    if ( is_page('3') || is_page(12) || is_page(22) || is_page(11) || is_page(13))
    {
    }

    or are you trying to avoid that?

    Thread Starter poper

    (@poper)

    strugglefish I’ve tried something similar:

    elseif (is_page()) {
    // we're looking at a static page. Which one?
    if (is_page('5' || '9' || '10' || '11')) {
    wp_list_pages('sort_column=menu_order&exclude=8,3&title_li=');
    } elseif (is_page('8' || '3')) {
    // our about page.
    echo "HTML";
    } else {
    // catch-all for other pages
    echo "html";
    }

    It works, but It always show the HTML for the first option (even if the displayed page is #8 or 3)
    Thanks a lot

    This line is wrong:
    if (is_page('5' || '9' || '10' || '11')) {
    copy what was posted in his post!

    Thread Starter poper

    (@poper)

    Moshu and strugglefish thanks a lot, it works like a charm!

    Glad it worked out for you 🙂
    Happy blogging!

    dbhanush

    (@dbhanush)

    Hello, I want my sidebar to appear right next to the comments/posts, instead it appears at the bottom of the page… PLease help… will appreciate it. Also, in the future i want to insert another sidebar adjacent to the current sidebar. Please guide me as to how can that be done. Thank you very much…..

    moshu

    (@moshu)

    Well, you royally screwed up the default template – that is not for newbies to modify. If you don’t have a very good understanding of HTML and CSS – look for another theme that is close to what you want and modify that one. I don’t touch Kubrick, sorry.
    Themes: http://themes.wordpress.net

    And BTW, you cannot just “add” another sidebar – that means a re-design of the theme.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Customizing sidebar’ is closed to new replies.