• ibblogosphere

    (@ibblogosphere)


    Hi everyone. I think this would be really easy for someone with php knowledge.

    I would like the following to only display on the homepage. I have attempted to wrap the… <?php if ( is_home() ) { ?> content <?php endif; ?> …but it gives an error message in my sidebar.
    Here’s the code and thanks in advance!

    <?php
    // this is where you enter the IDs of which categories you want to display
    $display_categories = array(11);
    foreach ($display_categories as $category) { ?>
    <div id=”sidebar_header”> </div><div id=”sidebar_gig”>
    <?php query_posts(“showposts=10&cat=$category”);
    $wp_query->is_category = false;
    $wp_query->is_archive = false;
    $wp_query->is_home = true;
    ?>

    <h3>”><?php
    // this is where the name of each category gets printed
    single_cat_title(); ?></h3><div class=”sub_text”>This week’s gigs ?</div>
    <?php while (have_posts()) : the_post(); ?>

    ” rel=”bookmark” class=”title”>

    * <?php
    // this is where title of the article gets printed
    the_title(); ?>?

    <?php the_excerpt(); ?>
    ” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”>More?
    <?php endwhile; ?>

    </div>
    <div id=”sidebar_footer”>
    <div class=”icons”><!– AddThis Button BEGIN –>
    <?php echo “<div>
    <script type=\”text/javascript\”>
    var addthis_pub=\”strutter27\”;
    var addthis_logo = ‘https://www.boxadesign.co.uk/thejoycollective/wp-content/themes/mimbo2.2/images/joy_logo.gif&#8217;;
    var addthis_brand = ‘The Joy Collective’;
    </script>
    <img src=\”https://s7.addthis.com/static/btn/sm-plus.gif\” width=\”16\” height=\”16\” alt=\”Bookmark and Share\” style=\”border:0\”/><script type=\”text/javascript\” src=\”https://s7.addthis.com/js/200/addthis_widget.js\”></script></div>”; ?>
    <!– AddThis Button END –></div>
    <div class=”footnote”>”>view all gigs</div>
    </div>

    <?php } ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • t31os

    (@t31os)

    I have tidied up the code you posted a little firstly…

    <?php
    // this is where you enter the IDs of which categories you want to display
    $display_categories = array(11);
    foreach ($display_categories as $category) { ?>
    <div id="sidebar_header"> </div><div id="sidebar_gig">
    <?php query_posts("showposts=10&cat=$category");
    $wp_query->is_category = false;
    $wp_query->is_archive = false;
    $wp_query->is_home = true;
    ?>
    <h3>">
    <?php
    // this is where the name of each category gets printed
    single_cat_title(); ?></h3><div class="sub_text">This week's gigs ?</div>
    <?php while (have_posts()) : the_post(); ?>
    
    " rel="bookmark" class="title">
    
    *
    <?php
    // This prints the title
    the_title(); ?
    // This prints the excerpt
    the_excerpt();
    ?>
    " rel="bookmark" title="Permanent Link to <?php the_title(); ?>">More?
    <?php endwhile
    echo '
    </div>
    <div id="sidebar_footer">
      <div class="icons"><!-- AddThis Button BEGIN -->
        <div>
        <script type="text/javascript">
          var addthis_pub="strutter27";
          var addthis_logo = "https://www.boxadesign.co.uk/thejoycollective/wp-content/themes/mimbo2.2/images/joy_logo.gif";
          var addthis_brand = "The Joy Collective";
        </script>
        <img src="https://s7.addthis.com/static/btn/sm-plus.gif" width="16" height="16" alt="Bookmark and Share" style="border:0"/>
        <script type="text/javascript" src="https://s7.addthis.com/js/200/addthis_widget.js"></script>
        </div>
        <!-- AddThis Button END -->
      </div>
      <div class="footnote">view all gigs</div>
    </div>
    ';
    }
    ?>

    Which part of this piece of code needs to show on the home page?

    If all, then you need to sort out that random </div> which shouldn’t be there….

    Then just do…

    <?php if(is_home()) { ?>
    Your content
    <?php } ?>

    I think you missed the closing curly bracket when you tried before… as in the }.

    I mainly tied up the Javascript for you, so it’s easier to fiddle with…… it’s single quoted though, so if you do any ‘ then remember to escape it using \ like this \’ …. otherwise it should be a little neater then before….

    Code could do with a little more work, but i’m not your personal coder (..lol..), so just post if you still need help…

    Thread Starter ibblogosphere

    (@ibblogosphere)

    Hi there, thanks for spending time doing that for me. It through out an error however but that’s cool it maybe something I’m doing wrong. I’m new to php and wordpress is slowly helping me learn.

    On the plus side your ‘if home’ statement work so thanks very much for that t31os.

    See ya.

    t31os

    (@t31os)

    You’re welcome….

    As said i think you just forgot the closing curly bracket. ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Only show sidebar section on homepage’ is closed to new replies.