PhP help (again!!!)
by endlesspsych
Hello can anyone help me here? Want to alter this code so that my sidebar doesn’t appear on any page other than the front page of my blog
</div><!-- #container -->
<?php wp_reset_query() ?>
<div id="primary" class="aside main-aside sidebar">
<?php arras_above_sidebar() ?>
<ul class="xoxo">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Primary Sidebar') ) : ?>
<li class="widgetcontainer clearfix">
<h5 class="widgettitle"><?php _e('Welcome to Arras!', 'arras') ?></h5>
<div class="widgetcontent">
<div class="textwidget">
<p><?php _e('Arras is a WordPress theme designed for news or review sites with lots of customisable features.', 'arras') ?></p>
</div>
</div>
</li>
<li class="widgetcontainer clearfix">
<h5 class="widgettitle"><?php _e('Recent Posts', 'arras') ?></h5>
<div class="widgetcontent">
<?php
$r = new WP_Query(array('showposts' => 10, 'what_to_show' => 'posts', 'nopaging' => 0, 'post_status' => 'publish', 'caller_get_posts' => 1));
if ($r->have_posts()) :
?>
<ul>
<?php while ($r->have_posts()) : $r->the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?> </a></li>
<?php endwhile ?>
</ul>
<?php
wp_reset_query();
endif;
?>
</div>
</li>
<li class="widgetcontainer clearfix">
<h5 class="widgettitle"><?php _e('Tag Cloud', 'arras') ?></h5>
<div class="tags widgetcontent">
<?php wp_tag_cloud(); ?>
</div>
</li>
<?php endif; ?>
</ul>
</div><!-- #primary -->
<div id="secondary" class="aside main-aside sidebar">
<ul class="xoxo">
<!-- Widgetized sidebar, if you have the plugin installed. -->
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Secondary Sidebar #1') ) : ?>
<li></li>
<?php endif; ?>
</ul>
<?php arras_below_sidebar() ?>
</div><!-- #secondary -->
Or is this something I should do from where this is called rather than in the sidebar file itself? As it is appears here?
<?php get_header(); ?>
<div id="content" class="section">
<?php arras_above_content() ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php arras_above_post() ?>
<div id="post-<?php the_ID() ?>" <?php arras_single_post_class() ?>>
<?php arras_postheader() ?>
<div class="entry-content clearfix">
<?php the_content( __('<p>Read the rest of this entry »</p>', 'arras') ); ?>
<?php wp_link_pages(array('before' => __('<p><strong>Pages:</strong> ', 'arras'),
'after' => '</p>', 'next_or_number' => 'number')); ?>
</div>
<?php arras_postfooter() ?>
<?php
if ( arras_get_option('display_author') ) {
arras_post_aboutauthor();
}
?>
</div>
<?php arras_below_post() ?>
<a name="comments"></a>
<?php comments_template('', true); ?>
<?php arras_below_comments() ?>
<?php endwhile; else: ?>
<?php arras_post_notfound() ?>
<?php endif; ?>
<?php arras_below_content() ?>
</div><!-- #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
I would delete the sidebar code out of all your templates except for one page template, and use that template to create a page to set as your homepage. If you’d like me to modify the code, feel free to email me & I can give you a quote
Well the good news is I can now get rid of the Sidebar – the bad news is it just leaves me with an empty space and screws with my format.
This is achieved by changing
into
The easy hack for this is to edit sidebar.php.
Enclose the content you want to dynamically remove in say
—-THE REST OF YOUR TEMPLTE HERE—-
Not exactly the style I would have chosen but it conforms to WordPress style. You’ll need to ensure whatever block level object (div container) sidebar.php is contained within is dynamically resizeable in your css; so that’s probably in index.php. If it isn’t you’ll not be able to reclaim the space, you want it to collapse; there are obviously more elegant ways to do this but I’m assuming it’s to do things quickly.
Haven’t got a mass of time right now but have at least tested the above code and it works. You’re on your own with changing the rest of your template though
Ok, I’ve just given that for categories but similar applies for anything but front page – just use wordpress api.
Can resize the container div either in CSS or by having php change the width of container div, e.g. <div id="blah" >
In response to your tweet, I can’t really modify your existing code because I don’t have the other files (or time) to test things.
Here’s an example from editing the standard TwentyTen sidebar.php to allow changing of the “primary” div block based on page type that you can follow elsewhere (it changes the sidebar to a red strip if a category page):
Opera has a nice feature called Dragonfly, which lets you click on page elements and browser the DOM tree to see the CSS properties as applied. On 21st floor, it seems you have a div for “content” and one for “sidebar”.
You could conditionally change the widths using similar technique as above, and probably have a separate sidebar-empty.php which you can again conditionally include using get_sidebar( “empty” ) instead of get_sidebar(). You’d have to edit a few files though (page.php, index.php, post.php, etc) so is messy.
The only elegant way around this I can see is to have the width of the “content” block dynamically change width depending on “sidebar” block (using CSS not PHP), and then do all the PHP work in sidebar.php so it’s in one place and not replicating code. Is a nicer solution but requires much more fiddling with CSS layout. I usually get into an argument with CSS for a day or so until I remember all it’s quirks so not going to suggest how to do that
Hmmmm…. it’s (obivously) filtered oot my code. Drat. I’ll see if I can find your email addy.