WordPress.org

Ready to get started?Download WordPress

Forums

Make something only show on post, not on main page? (13 posts)

  1. jonathanmead
    Member
    Posted 6 years ago #

    Okay, so I have this "subscriber promotion" box I made to include in each post, at the bottom.

    I want it to show up when you're actually on the post... ie http://www.illuminatedmind.net/2008/07/22/enlightenment-is-overrated/

    but I don't want it to show up on the main page.

    Is there any way that I can do this without inserting the code in each post manually?

    Thanks for your help...

    Jonathan

    [sig moderated]

  2. moshu
    Member
    Posted 6 years ago #

    Template_Hierarchy should help.

  3. skaufmann
    Member
    Posted 6 years ago #

    This also might be a bit more valuable
    http://codex.wordpress.org/Conditional_Tags

  4. jonathanmead
    Member
    Posted 6 years ago #

    I'm really new to using conditional tags. How do I implement them say on my conditional include, if it's on a single page, rather than the main template? Thanks.

  5. jonathanmead
    Member
    Posted 6 years ago #

    I guess what I would use... is_single()

    My question is how do I call this query? I've never really used php before.

    I want to call a div with other html inside it. So would I call the query is_single() and then put the html after that? How does that work?

    Thanks!

  6. skaufmann
    Member
    Posted 6 years ago #

    Down about 3/4 of the page there is a is_single code example. You'll want to use something like this where you want the content to show up:

    if (is_single())
    {
         echo 'This is just one of many fabulous entries in the ' . single_cat_title() . ' category!';
    }

    I'm not completely familiar with them either but it's not too complicated. Play around with it and you'll figure it out.

  7. moshu
    Member
    Posted 6 years ago #

    If you use the single.php (the template file for displaying the single post view) you don't need any kind of conditionals. That's an overkill and absolutely not required to make it work.

    Put whatver code/text you want ONLY in the single.php file and it will be shown only in single post view. That's it. Any advice saying otherwise is wrong...

  8. skaufmann
    Member
    Posted 6 years ago #

    Moshu, but it looks like the subscribe content is in his sidebar. If you don't want something to show just on the main page but everywhere else you will probably want to us something like is_front_page(). Your code would look something like

    if (is_front_page()){
        echo '';
    }else{
        echo 'whatever you want returned here';
    }

    If I understand the conditional correctly, this will echo nothing if it is front page and return your promo if any other page, such as page 2 of your blog,.

  9. Evita
    Member
    Posted 6 years ago #

    @jonathanmead
    You could also create a new sidebar.php (eg. sidebar-single.php = copy the existing sidebar.php with the code for the subscribe content), delete <?php get_sidebar(); ?> in your single.php and simply include the new sidebar with:
    <?php include (TEMPLATEPATH . '/sidebar-single.php'); ?>.
    Then all sites of your blog will have the standard sidebar and only the single-sites the new one (donĀ“t forget to delete the subscribe code on the original sidebar.php).
    With this method you can create easily various sidebars for categories, pages etc..
    Sometimes this method is easier to handle for newbies.

  10. jonathanmead
    Member
    Posted 6 years ago #

    Actually, the content I wan to show up is only on the actual post page. Right now it's showing up on the main page, whether I use the "more" function or not.

    It's not for sidebar purposes.

    I don't have a single.php. I guess the person that made my theme didn't use it.

    Skaufman, I'll try your suggestion. That sounds like it should work for me. So you can put anything within those single quote (') marks? Even html?

    Sorry if I sound like a total noob. =)

  11. skaufmann
    Member
    Posted 6 years ago #

    Yes, echo sort of means "print this". Only non-php can go there such as HTML or text, if you want more PHP in the middle of your echo you need to end the echo, insert PHP, then start the echo again to print the rest of your content all between the { } brackets.

    If you need that and can't figure it out, just post it here. I'll take a look at it.

  12. moshu
    Member
    Posted 6 years ago #

    1. Everybody should learn to read correctly the post they are answering to. Quote:

    Okay, so I have this "subscriber promotion" box I made to include in each post, at the bottom.

    2. You are all overcomplicating it with php, conditionals and other crap.

    3. Save your index.php as single.php. Edit it (add the box and whatever). Done.

  13. jonathanmead
    Member
    Posted 6 years ago #

    Thank you Moshu and everyone else.

    I'm starting to get the hang of this now. =)

Topic Closed

This topic has been closed to new replies.

About this Topic