WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Need if-else snippet for post-content on index.php (6 posts)

  1. Cathy Tibbles
    Member
    Posted 6 years ago #

    I would like to show ads (in javascript)in the post-content, only when it is not called in the index template. The codex mentioned <? if (is_home())- but says that it is deprecated now. what has replaced it?

    Also, I think I will run into a problem with where to place that snippet, as the post content is already in a query for (is_search()). Can this be done, and where would i place it?

    <?php
    	if (is_search())
    	{
    		the_excerpt();
    	}
    else		the_content();
    
    	?>

    I have tried everything else, even making my own post-content-ad division class in css, and that has gotten teh text wrapped around the ad the way I intended. But the ads are showing up on the index.php, which is not cool! :)

    thanks everyone,
    Cathy

  2. Cathy Tibbles
    Member
    Posted 6 years ago #

    it would also work, if I could just get it to show up in "the-content()", and not the excerpts. I'm thinking that must be possible... just not for me! any help?

  3. moshu
    Member
    Posted 6 years ago #

    only when it is not called in the index template.

    Then don't put it in the index :)

  4. Cathy Tibbles
    Member
    Posted 6 years ago #

    ok - that totally gave me pause! lol, yes, I have indeed checked the index.php, but it(the index) calls the post.php just as it(the index) calls the header, footer, etc. So, I was thinking that I need to then edit the post.php, no?

    The post.php adds things like the meta data, link_pages, the_content/ the_excerpt, footer, and separater for each post. It is one of the simplest themes I've found (in the backend) which is why I've chosen to modify it. So, if it is the post.php that I must edit, the above question applies I think.

  5. moshu
    Member
    Posted 6 years ago #

    Oh, that's crap :(
    I hate those themes that have a post.php or loop.php - they go against the whole idea of customizing themes and template files.
    The rationale behind having different template files (like index, archive, search, page, category etc.) is that you can have very different Loops and queries + you can do all that stuff you wanted to do very easily: modifying the proper template file. However is making a theme that takes away that flexibility - is an idiot. (You can quote me on this...)

  6. Cathy Tibbles
    Member
    Posted 6 years ago #

    Thanks for the info - I did try to delete the call to the post template, and input the direct loop (from the post template) and it worked great! Now the index.php has its own call to the loop.

    And my ads look great on the single & page templates.... And I just realized that I have to create the same "real" loop on every page where excerpts are used... hopefully not too many more! Categories, search results I think.

    wahoo, feels good to find a solution!

Topic Closed

This topic has been closed to new replies.

About this Topic