• Resolved designlabCPH

    (@designlabcph)


    Hi – I’m a newbie here, so please bare with me, I’ve tried searching here and the net, but without a solution so far.

    I’ve just started on the “Smashing WordPress Themes” and on page 74 (working with conditional tags), I’m supposed to put in these two ‘tests’, to see if it works. Well, one deos, the other does not for some reason.

    Now I’ve put his ion the loop file of the twentyten theme, just after the beginning of the loop (as there’s no-where in the book where it states which file and where to put the code in):

    <?php if (is_home() || is_single_post()) { ?>
    				<div class="ad-block">
                    	<a href="https://tdh.me" title="Boy the book! ">
                        	Did you know I wrote another book as well? <br />
                            <strong>Get the Book</strong>
                            </a>
                            </div>
                            <br />
    <?php } ?>
    <?php if ( is_single() ) {
        echo 'Hello World, Is Single';
    } else {
        echo 'Not Single';
    }
    ?>

    Now, the first piece of code (is_home()) does show on the homepage as it should – the second piece (is_single_post())) does NOT show when viewing the page with the single post.

    The same goes for the second piece of code:
    On homepage, it echoes ‘Not Single’ before every Gallery post (which is not on single post page), but nothing echoes out on the rest of the posts, that (as far as I know) are supposed to be single_post pages.

    I’ve tried with is_page as well which does NOT output anything as well. But using is_archives works fine.

    I’ve tried to re-install the twentyten theme, but that didn’t help

    What am I doing wrong? This is driving me nuts, so I really hope someone can clarify this for me.

    Thx in advance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • in twenty ten, single posts use single.php which calls loop-single.php; i.e. using is_single() in loop.php will not have any effect.

    as for is_home() see:

    https://codex.www.ads-software.com/Conditional_Tags#The_Main_Page
    and
    https://codex.www.ads-software.com/Conditional_Tags#The_Front_Page

    Thread Starter designlabCPH

    (@designlabcph)

    alchymyth:
    Thx for your very quick answer! ??

    *heh* .. I thought that and put in the conditional tag in the loop-single where it worked fine.
    But then wondered, why the tutorial stated the ‘if’ is_single, if you already are on that page? Does not make sense to me.
    On the page itself, I can echo it without the ‘if’ statement, so thought I was missing a point somewhere?

    So, is there no way to call it from the “general loop” of twenty ten – ie. gather all those tags and statements in one place (functions.php and then how?), or would I have to modify all the different files every time I wanted a change to one or the other?

    Sorry for all the questions, the ifand is_single just baffled me.

    why the tutorial stated the ‘if’ is_single

    i guess that the tutorial is not written with twenty ten in mind; most ‘older’ themes don’t use the ‘get_template_part()’ method.

    if you want a ‘general loop’, you need indeed to rewrite some of the templates.

    for example, you could build a theme with just index.php (plus style.css and functions.php) and have all the conditional statements in index.php (possibly outsourced into functions.php), to distinguish between posts and pages and archives and front pagea, etc…

    Thread Starter designlabCPH

    (@designlabcph)

    Ok, what you write makes more sense to me ??

    The book is the “Smashing WordPress Themes” printed this year (but before the WP 3.2) and actually has the twentyten theme in mind. Just in case others sits and wonder like me.
    But guess I got to ask the writer about the why’s and for what’s ??

    Thank you very much for your quick reply’s! ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Theme] is_single & is_page not working in Twenty Ten?’ is closed to new replies.