• Resolved jt101

    (@jt101)


    You’ll see on all my main pages, on the left hand side there is the title of the page and a mini description on the graphic of a noticeboard. For example: Big Blogs
    “You’re at my blog main page. Here you can follow my journey as it happens and view all archived posts to follow the journey so far.”

    I would like to feature a different one on each of my archives page. i.e. relate the sidebar to a unique post (which I can edit on the backend)
    For example: http://www.thebreadcrumbtrail.org/archives/category/travel-australia

    I have tried adding

    if ( is_archive ()) { ?> <?php $post_id = 39;
    $queried_post = get_post($post_id); echo $queried_post->post_content;?> <?php } ?>

    to my sidebar.php, but it did not work.

    I have however noticed, that I have one archive.php file, yet my posts are filed under “archives” e.g. http://www.thebreadcrumbtrail.org/archives/date/2009/12

    Here is my sidebar .php:

    <?php /* Local File */ ?>
    
    <!-- sidebar start -->
    	  <div id="sidebar">
    			<p>&nbsp;</p>
    			<p>&nbsp;</p>
    			<p>&nbsp;</p>
    			<p>&nbsp;</p>
    			<p>&nbsp;</p>
    
    		<div class="intro">
    
    			<?php if (is_page('home')) { ?> <?php $post_id = 11;
    				$queried_post = get_post($post_id); echo $queried_post->post_content;?> <?php } ?>
    			<?php if (is_home()) { ?> <?php $post_id = 19;
    				$queried_post = get_post($post_id); echo $queried_post->post_content;?> <?php } ?>
    			<?php if (is_page('Trails')) { ?> <?php $post_id = 25;
    				$queried_post = get_post($post_id); echo $queried_post->post_content;?> <?php } ?>
    			<?php if (is_page('ESE Travel')) { ?> <?php $post_id = 31;
    				$queried_post = get_post($post_id); echo $queried_post->post_content;?> <?php } ?>
    			<?php if (is_page('Gallery')) { ?> <?php $post_id = 36;
    				$queried_post = get_post($post_id); echo $queried_post->post_content;?> <?php } ?>
    			<?php if (is_page('Crumbs About Us')) { ?> <?php $post_id = 5;
    				$queried_post = get_post($post_id); echo $queried_post->post_content;?> <?php } ?>
    			<?php if (is_page('Links')) { ?> <?php $post_id = 39;
    				$queried_post = get_post($post_id); echo $queried_post->post_content;?> <?php } ?>
    			if ( is_page('archives')) { ?> <?php $post_id = 39;
    				$queried_post = get_post($post_id); echo $queried_post->post_content;?> <?php } ?>
    
    			<p>&nbsp;</p>
    			<p>&nbsp;</p>
    			<p>&nbsp;</p>
    			<p>&nbsp;</p> 
    
    		</div>
    
    			<div id="sidebar_top"></div>
    			<ul>
    			<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Left Sidebar') ) : ?>
    				<li>
    					<h3>Categories</h3>
    					<ul>
    						<?php wp_list_cats('sort_column=name&optioncount=0&hierarchical=0'); ?>
    					</ul>
    				</li>
    				<li>
    					<h3>Archives</h3>
    					<ul>
    						<div id="archives">
    <select name="archive-dropdown" onChange='document.location.href=this.options[this.selectedIndex].value;'>
      <option value=""><?php echo attribute_escape(__('Select Month')); ?></option>
      <?php wp_get_archives('type=monthly&format=option&show_post_count=1'); ?> </select>
    						</div>
    
    					</ul>
    				</li>
    
    				<li>
    					<h3>Meta</h3>
    					<ul>
    						<?php wp_register(); ?>
    						<li><?php wp_loginout(); ?></li>
    						<li><a href="http://validator.w3.org/check/referer">Valid <abbr title="eXtensible HyperText Markup Language">XHTML</abbr></a></li>
    						<li><a href="http://gmpg.org/xfn/"><abbr title="XHTML Friends Network">XFN</abbr></a></li>
    						<?php wp_meta(); ?>
    					</ul>
    				</li>
    			<?php endif; ?>
    			</ul>
    	  </div>
    <!-- sidebar end -->

    Any ideas?

    Thanks in advance

    James

Viewing 5 replies - 1 through 5 (of 5 total)
  • This works just fine in the WordPress Default theme’s wp-content/themes/default/sidebar.php when viewing a date, category, or tag based archive:

    <?php
    if ( is_archive ()) {
    echo 'this is an archive .......';
    }
    ?>

    As for the archives vs archive thing — having archives as part of your Permalink doesn’t change the fact that WordPress, according to the Template Hierarchy, will use the archive.php template to render posts in the appropriate conditions.

    Related:
    Stepping Into Templates
    Conditional Tags

    Thread Starter jt101

    (@jt101)

    Awesome. I just copied your code and then edited the echo part. Not sure why it wasn’t working before, as it looks exactly the same. Previously I was infact using <?php if ( is_archive ())

    Anyway, thanks Michael. However, can I be more specific. I want to specify ‘this is an archive …….’ for a specific date or category e.g. http://www.thebreadcrumbtrail.org/archives/date/2009/03
    or
    http://www.thebreadcrumbtrail.org/archives/category/travel-australia

    THanks

    James

    However, can I be more specific. I want to specify ‘this is an archive …….’ for a specific date or category e.g.

    Not sure what you are asking there.

    Thread Starter jt101

    (@jt101)

    Ok, at the moment, I wrote

    <?php if ( is_archive ()) { ?> <?php $post_id = 570;
    $queried_post = get_post($post_id); echo $queried_post->post_content;?> <?php } ?>

    into my sidebar.php

    So now, everytime I pull up a page of archives it displays a unique message in the sidebar. Cool. But, my archives are divided into categories or months.

    How can I further specify a unique message say for my category “travel-australia” or the month of “January” using the code above.

    I mean I want a different message for every category and every month. Or at least every category.

    Thanks

    if (is_month('201003') ){
    echo 'this is a March 2010 archive';
    }
    if (is_category(array(9,'blue-cheese','Stinky Cheeses'))) {
    echo 'this is a category 9, blue-cheese, or Sticky Cheeses category archive';
    }

    See Conditional Tags for more.

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

The topic ‘Displaying unique sidebar for Archives’ is closed to new replies.