Forums

[resolved] Sidebar as a static archive index (2 posts)

  1. lola rennt
    Member
    Posted 10 months ago #

    Dear WordPressers,

    I have a very simple request. It is exactly the same question posed in this thread, but it remains unanswered. It is probably a novice mistake - but any insight is welcome!

    Basically I want my sidebar to display an index archive of posts (as links). I managed to do this by copying the code from the archive page to the sidebar. Now the problem is that when I click on a post it displays the post on a single.php page correctly but the sidebar also displays that single post.
    I would want the sidebar to stay static, so it should keep on displaying the archive index as a whole. Additionally I want the post which is active to be highlighted in the sidebar - that would be awesomeness ofcourse : )!

    But first things first. Here is my code, what am I doing wrong?

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Thanks so much for your initial help!

  2. lola rennt
    Member
    Posted 9 months ago #

    I managed to solve the problem with the template tag get_posts which succesfully renders an archive list of all posts. And it is customizable with simple tags. Perfect!
    Here is the code:

    <?php
    $args = array( 'numberposts' => 100, 'orderby'=> 'post_date');
    $postslist = get_posts( $args );
    foreach ($postslist as $post) :  setup_postdata($post); ?>
    	<div>
    		<?php the_date(); ?>
    		<br />
    		<?php the_title(); ?>
    		<?php the_excerpt(); ?>
    		<?php the_category(' '); ?>
    	</div>
    <?php endforeach; ?>

Reply

You must log in to post.

About this Topic