WordPress.org

Forums

[resolved] Hiding an element on my homepage but not single posts (5 posts)

  1. james-sc
    Member
    Posted 4 years ago #

    Hello all,

    Apologies if this has been posted elsewhere but I can't seem to find the specific answer I'm looking for.

    Recently I came across Readability.com and wanted to feature their functionality on my blog. (If you click it you'll see the little box on the top-right there). I found the code on their site and put it into a text widget in my sidebar.

    Now it works great, but it doesn't work on the homepage - nor do I want it to. As it doesn't, I want to hide it on the homepage and just have it available for posts only. I've used CSS to hide other undesirable divs and such on my blog but they are global; I only want to hide the box on the homepage.

    Any ideas how to do it? I'm guessing I have to make some sort of change to index.php but HTML/CSS is as far as my coding knowledge goes, I wouldn't have a clue how to edit the php. With this in mind, if you do have an answer I'd love to hear it but I am a n00b so as simple as possible would be great!

    Thanks

    James

  2. dan.tee
    Member
    Posted 4 years ago #

    I'm a noob too, but this should work - you need to make a template for your homepage. This is really dead easy. (hopefully if I get anything wrong here, a guru can correct me so you might be best hanging on a bit before implementing my advice!)

    Copy whichever php doc it is that is currently composing your homepage (it's going to be the one that you added the offending code to). It'll be page.php, or post.php something like that. call this new php doc homepage.php or something like that.

    Open it in your preferred editing program (or even in the Appearance Editor) and add the following to the page, before the first <?php> call or any thing at all - literally right at the top:

    <?php
    /*
    Template Name: homepage
    */
    ?>

    Then remove the code that makes the unwanted box appear. Save and upload to your theme's directory.
    Then in the dashboard, add a new page called home or whatever, and choose your homepage template from the template options on the right. This will make a page with all the functionality of your normal blogging homepage but without the box that you wish to hide.

    Finally, go to settings in the dashboard and 'reading' There, you'll find the bit that lets you specify where the blog appears - home page or otherwise.

    Now. That's what I'd do. As I said, I could be completely wrong - hopefully some more learned wordpresser can confirm the above or tell you to utterly ignore what I've just said!

    Cheers,

    Dan

  3. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

    well, if you are looking to just hide something by css, you can target specific pages in WP...(usually)

    the body gets barious classes assigned to it by post page, like home gets a body class of..... home!

    So if your div class was blah, normally you would hide it by using .blah in your css right?

    To hide .blah on just the home page you would use .home .blah, like

    .home .blah {
       some: css;
    }

    Now I'm not sure if a css hide is exactly what you wanted or what? But that's one way

  4. dan.tee
    Member
    Posted 4 years ago #

    having got past the .blah, that a much more elegant and easy solution than mine! I'd go for that one!

  5. james-sc
    Member
    Posted 4 years ago #

    Thank you guys, CSS trick worked a treat! Didn't know body tags had classes in WP... with a bit more research I probably could have worked this out myself!! Ahh well.

    Thanks again!

Topic Closed

This topic has been closed to new replies.

About this Topic