Tagged: 

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #454

    hello everyone,

    ich wish to have additional links in the sidebar (left): on every single page i will show some links to posts from this categorie. i believe this is for better user expirience and better linking for sites from single.php.

    So i searched for this code, which works fine for me. copied from this page http://www.galuba.net/?p=1684

    <?php
    if (is_single()) {
    global $post;
    $categories = get_the_category();
    foreach ($categories as $category) :?>
    <div class='box box_small'>
    <h3>Artikel aus dieser Kategorie</h3>

    <ul>
    <?php
    $posts = get_posts('numberposts=5&category='. $category->term_id);
    foreach($posts as $post) : ?>

    <li><a>"><?php the_title(); ?></a></li>
    <?php
    endforeach;
    ?>

    <li><strong><a>term_id);?>" title="Zeige alle Artikel der Kategorie <?php echo $category->name; ?>">Zeige alle Artikel der Kategorie <?php echo $category->name; ?></a></strong></li>
    <?php
    endforeach;
    ?>
    </ul>
    </div>
    <?php
    }
    ?>

    The only problem, the whole sidebar moved to the bottom of the articles, before footer. the sidebar is no longer at the right site.

    I copied the code bevor every other code, at row 1 in sidebar.php, because i wish to have this code, even when i use some widgets.

    Any suggestions? Thank you for your support.

    #31438
    #31439

    The code you’ve added doesn’t have a container specifying a width and doesn’t specify a width itself. It’s also not within the sidebar area so it won’t inherit the styles.

    I suggest turning your code above into a widget and adding it under WP Admin -> Appearance -> Widgets to position it correctly.

    #31440

    Thank you James for your advice. You are right, i see it now, the code is not inside the sidebar container.

    Turn the code in a widget seems a good move but how should i do it?.

    So much as i know a widget can, same as normal posts or page, not execute php-code for security reasons.

    #31441

    This article is a good place to start in creating a widget: http://justintadlock.com/archives/2009/05/26/the-complete-guide-to-creating-widgets-in-wordpress-28

    The code you posted in the opening post can be used as a function, take out the opening:

    if (is_single()) {

    and closing

    }

    If you want to restrict the pages the widget appears on, you can select the appropriate widget area to add this to, or you can use the Widget Logic plugin for more precise control.

    Let me know how you get on.

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘additional code in sidebar move sidebar to the bottom of the page’ is closed to new replies.