• On my blog i have to sidebars. One is the common one, which shows the menu, the second one I want to use to show a page-related picture or some small text. So every page has it’s own sidebar. The blog is made with pages.
    I know how to do this using iinclude_page, but then I have to make a template for every page and I want just to write the page, and tell in someway which picture or piece of text (can be a posts in a specific category) I want to see on the sidebar. I’ve been thinking of miniposts, but I can’t find a way to connect one minipost to a specific page_ID. Is there a way to solve this??

Viewing 7 replies - 1 through 7 (of 7 total)
  • You can use if statements to echo the appropriate content…

    <?php
    if (is_page(1)) {
    echo('whatever content you want to put here or link to image or ?');}
    elseif (is_page(2)) {
    echo ('something else here');}
    else {}
    ?>

    To simplify, if several of the pages have the same side content, you can use a shorthand method of referring to the pages (so you only have to write the content once) like so:

    if (is_page(1) || is_page(2) || is_page(2)) {
    
    }

    OR, you could put the content for each separate sidebar into a file (these would just contain the content, so don’t use the html, head or body tags, just content type html, links, images and such) and use an include statement instead of writing the actual content, like:

    <?php
    if (is_page(1)) {
    include (TEMPLATEPATH . 'filename1.php'); }
    elseif (is_page(2)) {
    include (TEMPLATEPATH . 'filename2.php'); }
    else {}
    ?>

    This allows easier editing of each file via the Manage>Files admin page so that you don’t have to dig through the entire source of the page.php or index.php or category.php file to find the appropriate content to edit.

    HTH

    Thread Starter katootje

    (@katootje)

    I’ve found a solution in the execphp widget. I dropped this widget on the second sidebar.
    De php code in de widget is:
    <?php
    global $wp_query;
    $pagina = $wp_query->post->ID;
    $image = “https://www[complete url]/img_$pagine.jpg”;
    if (file_exists ( $image)){
    echo “<img src=\”https://www.complete url/img_$pagina.jpg\”> “;
    } else {
    echo “<br>”;
    }
    ?>
    it’s working. Now I only have to make a second statement for the text files. But that (i hope) will not be any problem. I can tell I’m a bit proud of myself, because I have very little knowlegde of php.

    I used the php widget, but I think I can just put the code in de sidebar and make it nog dynamic.

    Thread Starter katootje

    (@katootje)

    1 small question. I have the complete url now in the code. I see you using TEMPLATEPATH.
    How can I use this?
    $image = TEMPLATEPATH . ‘/uploads/img_$pagina.jpg’;
    and in the echo:
    “img src=” TEMPLATEPATH . “/uploads/img_$pagina.jpg/” “;

    I don’t know what the output of templatepath is and how I can use this in the code.
    It’s not a big deal, complete url will work, but it’s shorter and the code can be used simply on different websites.

    If you want to reference the theme directory, use bloginfo, as in:

    href="<?php bloginfo('template_directory'); ?>"

    to reference the DEFAULT uploads directory, use:

    href="/wp-content/uploads/img_'.$pagina.'jpg"'

    you for sure would not use a / after the image extension .jpg

    when you are writing an echo statement and want to reference something with php, you have to step out of the literal content and reference the variable, as in:

    echo '<p>This is actually what will be written... in this case, the name of the post:<br />'.$post->post_name.'back in the html or content here.</p>';

    if you need html attributes inside the html tags, you use double quotes that don’t have to be escaped, as in

    echo '<p class="foo">this is html etc<br />'.$post->post_name.'back in the html or content here</p>';

    hth

    Thread Starter katootje

    (@katootje)

    thanks, for now it’s working. I can put text in that sidebar by uploading a txt-file. Hope to find something to put text there by a plugin in wordpress, so text can be edited more easier than deleting the text file and upload a new one. Something that can connect/relate/link (don’t know the exact english term for it) something as a minipost to one specific page. So yo u make a minipost and have the oppurtunity to tell on which page it has to be shown
    (sorry not native english, know my written english sucks)

    When are page related sidebars scheduled to be included in WordPress as standard functionality? I am holding off publishing my site until then.

    I’m not sure if this is a solution for my problem but here it goes.

    I have some custom pages that I added and I would like the sidebar to be gone. I removed the calls from the custom page template and I tried editing the css to make the main content stretch across the entire page to fill where the sidebars were. Well of course I wasn’t thinking and this changed the layout of all the pages not just the custom pages. How do I target just the custom pages?

    I’m new to php but I am learning as I go along.

    https://francetales.com
    main blog page
    https://francetales.com/links
    main pages
    https://francetales.com/testing
    custom page. The footer floats to the right when the content doesn’t fil up the space, but even when I expanded the size of the div for the content the footer still went to the right and the rounded corners are missing. I only removed the sidebar call.

    Help?!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘plugin or something wanted to make a page-related sidebar’ is closed to new replies.