Support » Themes and Templates » Looking to remove part of the page

  • Hi, i love my theme but i want to exclude part of it when users go to other pages. At the moment it has a Featured News and Popular articles section on the Homepage which looks great but i dont want it on my other pages.

    Here is the page code:

    <———start———>

    <?php get_header(); ?>

    <!– BEGIN home –>
    <div id=”home”>
    <!– BEGIN featured –>
    <div id=”featured”>
    <h2>Featured News</h2>
    <?php
    $temp_query = $wp_query;
    query_posts(array(‘post__in’=>array(dp_settings(‘featured’))));
    if (have_posts()) : the_post();
    ?>
    <div class=”content”>
    <?php dp_attachment_image(0, ‘thumbnail’, ‘alt=”‘ . $post->post_title . ‘”‘); ?>
    <h3>“><?php the_title(); ?></h3>
    <p class=”date”><?php the_time(‘l, F j, Y’) ?></p>
    <?php ob_start(); the_content(”); echo str_replace(“\n”, ‘

    ‘, (dp_clean(ob_get_clean(), 700))); ?>
    </div>
    <div class=”details”>
    ” class=”readmore”>Read More »
    <p class=”r”>Filed Under: <?php the_category(‘, ‘) ?> <span class=”comments”><?php comments_popup_link(‘No Comments’, ‘1 Comment’, ‘% Comments’); ?></span></p>
    </div>
    <?php endif; ?>
    </div>
    <!– END featured –>
    <!– BEGIN popular –>
    <div id=”popular”>
    <h2>Popular Articles</h2>

      <?php dp_popular_posts(7); ?>

    </div><div class=”break”></div>
    <!– END popular –>
    </div>
    <!– END home –>
    <!– BEGIN content –>
    <div id=”content”>
    <?php
    $wp_query = $temp_query;
    if (have_posts()) : the_post();
    $arc_year = get_the_time(‘Y’);
    $arc_month = get_the_time(‘m’);
    $arc_day = get_the_time(‘d’);
    ?>
    <!– begin post –>
    <div class=”single”>
    <h2>“><?php the_title(); ?></h2>
    <?php the_content(); ?>

    <div class=”details”>
    <p class=”l”>Categories: <?php the_category(‘, ‘) ?></p>
    <?php the_tags( ‘<p class=”r”>Tags: ‘, ‘, ‘, ‘</p>’); ?>
    <div class=”break”></div>
    </div>
    </div>
    <!– end post –>
    <div id=”comments”><?php comments_template(); ?></div>
    <?php else : ?>
    <div class=”notfound”>
    <h2>Not Found</h2>
    <p>Sorry, but you are looking for something that is not here.</p>
    </div>
    <?php endif; ?>
    </div>
    <!– END content –>

    <?php get_sidebar(); get_footer(); ?>

    <———END———>

    When i try and remove the featured & popular code it comes up with a fatal error which is….

    Fatal error: Call to a member function on a non-object in /home/sites/eventindustrynews.co.uk/public_html/wp-includes/query.php on line 320

    Any help would be great!

Viewing 10 replies - 1 through 10 (of 10 total)
  • Put the bits you want to hide inside an is home clause like so…

    <?php if ( is_home()) { ?>
    
    your stuff to display on the home page only
    
    <?php } ?>

    Sorry t31os i have only basic coding knowledge, could you show me where to put the code?

    Many thanks

    Put this bit…

    <?php if ( is_home()) { ?>

    before…

    <!-- BEGIN home -->

    and this bit..

    <?php } ?>

    after…

    <!-- END home -->

    I would have thought, give it a shot..

    Thanks t31os,

    Its still comming up with an error, really got me stumped this one!

    What’s the error? Same as before?

    Do this as a test, add the following…

    <?php if ( is_home()) {
    echo 'this is the home page';
    } else {
    echo 'this is not the home page';
    ?>

    Place it before..

    <!-- BEGIN home -->

    So the start of your file will look like this..

    <?php get_header(); ?>
    <?php if ( is_home()) {
    echo 'this is the home page';
    } else {
    echo 'this is not the home page';
    ?>
    <!-- BEGIN home -->

    Now refresh your page and tell me if one of the messages above is displayed or if an error is still shown, and if so, please post the error message given.

    Hi t31os

    I inserted the test php code in my page.php as you have shown above and it is comming up with “this is not the home page” so the test worked.

    Any thoughts, your help is really appriciated!

    Regards

    Ok, what was the error coming up with my previous suggestion, same as before?

    The initial suggestion should have worked, the test was to confirm if it’s accepting the code, that’s all.

    This should work (what i suggested before basically).

    <?php
    get_header(); 
    
    if (is_home()) {
    ?>
    <!-- BEGIN home -->
    <div id="home">
    <!-- BEGIN featured -->
    <div id="featured">
    <h2>Featured News</h2>
    <?php
    $temp_query = $wp_query;
    query_posts(array('post__in'=>array(dp_settings('featured'))));
    if (have_posts()) : the_post();
    ?>
    <div class="content">
    <?php dp_attachment_image(0, 'thumbnail', 'alt="' . $post->post_title . '"'); ?>
    <h3>"><?php the_title(); ?></h3>
    <p class="date"><?php the_time('l, F j, Y') ?></p>
    <?php ob_start(); the_content(''); echo str_replace("\n", '
    
    ', (dp_clean(ob_get_clean(), 700))); ?>
    </div>
    <div class="details">
    " class="readmore">Read More ยป
    <p class="r">Filed Under: <?php the_category(', ') ?> <span class="comments"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span></p>
    </div>
    <?php endif; ?>
    </div>
    <!-- END featured -->
    <!-- BEGIN popular -->
    <div id="popular">
    <h2>Popular Articles</h2>
    
          <?php dp_popular_posts(7); ?> 
    
    </div><div class="break"></div>
    <!-- END popular -->
    </div>
    <!-- END home -->
    <?php
    }
    ?>
    <!-- BEGIN content -->
    <div id="content">
    <?php
    $wp_query = $temp_query;
    if (have_posts()) : the_post();
    $arc_year = get_the_time('Y');
    $arc_month = get_the_time('m');
    $arc_day = get_the_time('d');
    ?>
    <!-- begin post -->
    <div class="single">
    <h2>"><?php the_title(); ?></h2>
    <?php the_content(); ?>
    
    <div class="details">
    <p class="l">Categories: <?php the_category(', ') ?></p>
    <?php the_tags( '<p class="r">Tags: ', ', ', '</p>'); ?>
    <div class="break"></div>
    </div>
    </div>
    <!-- end post -->
    <div id="comments"><?php comments_template(); ?></div>
    <?php else : ?>
    <div class="notfound">
    <h2>Not Found</h2>
    <p>Sorry, but you are looking for something that is not here.</p>
    </div>
    <?php endif; ?>
    </div>
    <!-- END content -->
    
    <?php
    get_sidebar();
    get_footer();
    ?>

    If that doesn’t work please post the error returned..

    Returned error is

    Fatal error: Call to a member function on a non-object in /home/sites/eventindustrynews.co.uk/public_html/wp-includes/query.php on line 320

    The is_home() function must conflict with another function being called in your file…

    I couldn’t tell you which one unfortunately, it would be trial and error…. and there’s quite a few in your template, so it’ll take time to go through each one…

    query.php line 320 is..

    function is_feed () {
    	global $wp_query;
    
    	return $wp_query->is_feed; // This line
    }

    Perhaps someone who is more in tune with the is_home function can comment on why there is a conflict with your code…

    It’s proberly related to the custom queries in your template….. i could be wrong though…

    Thanks t31os

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Looking to remove part of the page’ is closed to new replies.