Support » Fixing WordPress » I don’t know if this is possible… different ad shown on each category of posts

  • Lori

    (@lori)


    Hello,

    I am starting a blogging site and I am trying to figure out how to put different ad codes in each category of posts. For example, I want to put ads about pets and animals in the “Pets” category.
    I am making each blog (which is available to users) have many different categories, where they can organize each of their posts.

    So when I click on “Pets” in the list of categories at the bottom right of each blog’s home page, it will take me to all that blog’s posts listed under “Pets”, and it will show pet ads. Same with other categories, too. Is this possible? If so, how do I configure this and what files do I change?

    Thanks for your help, I am new to wordpress.

    ~ Lori

Viewing 7 replies - 1 through 7 (of 7 total)
  • Ming

    (@ming)

    Hi Lori,

    The page that displays categories is called archive.php. It’s in wp-content/themes/your current theme. If you open it up near the top you’ll see a bunch of condition statements that tells the page what to do if it’s a monthly archive, daily archive, category archive, etc. So if I’m understanding you right you just need to edit the archive.php page so it looks like you want. Then, where you want the ad to appear you’ll enter this:


    if (is_category('pets')) { code to show pet ad }
    elseif (is_category('extremebowling')) { display bowling ad }
    elseif (is_category('squirrelsonwaterskis')) { display squirrel ad }
    ...

    Hope that makes sense, let me know if you have questions.

    davidchait

    (@davidchait)

    Lori –

    If you use Google Adsense, it’ll ‘read’ the pages and give you semi-appropriate advertising — no need to custom specify pages.

    However, if you wanted to use something like phpAds (which I use), you could pass the current category. In 1.5, it’s a bit more difficult to grab the category for a category view:

    if (is_category()) // we’re in some cat view
    {
    $cat_obj = $wp_query->get_queried_object();
    // now you can use:
    //$cat_obj->cat_ID
    //$cat_obj->cat_name
    //$cat_obj->category_nicename
    // to pass the category being viewed along to other code
    }

    inside of a given post in the post loop, I think:
    $post->post_category

    will give you the ID. you can then use:
    get_catname($post->post_category);

    to get the name. Something like that. 😉

    -d

    Thread Starter Lori

    (@lori)

    I don’t know why, but I don’t have the folder “Themes” in my wp-content folder, nor do I find the file “archive.php” anywhere. I think maybe categories.php in the admin folder is the same thing?

    I don’t know if I am using the latest version of wp because I download blogs from my control panel called cpanel, if you are familiar with that, there is a folder called “Fantastico”, and in that folder we can easily download many software, and WordPress is one of them. Downloading blogs from this interface is easier for me than manually downloading to my computer, then to my website, because I will be making hundreds of these blogs for hundreds of bloggers. So I don’t know if cpanel gives us the newest version of wordpress.

    Because this may not be the same version as Ming is talking about, how do I edit the archive file if my version does not have one? Is it categories.php?

    Don’t think this will help but this is one of my blogs http://blogsclub.com/a1. Try logging in as username test and password test and maybe that’ll tell ya what version it is, or if I should have this file. I’m confused as a brick. :p

    Thank you for your help! 🙂

    Ming

    (@ming)

    You’re using version 1.2.1 (checked by viewing the source). That’s the most recent stable, security version before 1.5 (which only came out a month ago). You might want to email your host and see if they have plans to upgrade Fantastico with 1.5.

    The is_category function doesn’t exist in 1.2 so you’ll have to use some good ol’ PHP. It sounds like David Chait was doing this in 1.2 so he’ll probably have the solution.

    Ming

    (@ming)

    Oops, 1.2.1 is not the second newest version. 1.2.2 is the newest version before 1.5.

    Thread Starter Lori

    (@lori)

    Thank you Ming.

    David Chait can you please tell me what file I edit for version 1.2.1? If there’s nothing I can do I guess I’m going to have to manually download all my blogs to get the newest version you are talking about. 🙁

    Thanks in advance!

    Thread Starter Lori

    (@lori)

    Ming or somebody, I’d like to try the php you specified in my index.php file, since my version only shows categories in index.php like this: http://www.blogsclub.com/a1/index.php?cat=1, 2, 3, 4, etc.

    It seems I could edit just the index file, but I don’t want to mess it up. Where would I put that in the index?

    Also, I understand that if somebody goes to a specific category then the specified ad will be displayed. But, what about just the index page of the blog, no category selected? I would like the home page of the blog to show another ad code. I know that by putting the ad code just on the index page it will display the ad on the index page, but it will display the ad on the category pages as well, therefore the category pages will be displaying both the ad put on the index file, as well as the ad specific to that category.

    Is there a way I can specify another ad code to be displayed ONLY on the main index page, and not display on category pages? That is, if this will work in my version. I don’t want to mess anything up. :((

    Thanks to anyone who tries to help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘I don’t know if this is possible… different ad shown on each category of posts’ is closed to new replies.