1. This website uses cookies to improve service and provide a tailored user experience. By using this site, you agree to this use. See our Cookie Policy.
    Dismiss Notice

Adding YouTube To Your Autoblog

Discussion in 'Blogging' started by mbceo, Sep 30, 2009.

  1. mbceo

    mbceo Junior Member

    Feb 9, 2009
    Likes Received:
    I finally figured out how to frickin' add youtube videos randomly to my blog based on the category of the blog post, so I thought I would share this.

    This method also will keep all of the visitors on your site to view the videos.

    Hope this helps someone out.

    The first step is to get the actual code from Google. This is the easy part.

    When you go through this step, it will generate a code based on a keyword you supply them. Just give them any keyword right now. You will change that in a second.

    Once you have the code, place it in your blog post (single.php).

    Now, look for a section of the code that says the following:

    [{ query : "your keyword"}], null, null, options);
    In this section, replace the "your keyword" with the following code:

    $category = get_the_category(); 
    echo $category[0]->cat_name;
    This will find the category of the blog post, and use this as the keyword for your youtube query. I assume this works in all wordpress themes, as this is the standard codex for wordpress, but I am not sure.

    Your code will now look like:

    [{ query : "<?php
    $category = get_the_category(); 
    echo $category[0]->cat_name;
    ?>"}], null, null, options);
    It may also work for tags, but you would need to strip down the tags to just one tag. I believe the above code works because even though you might have multiple categories, when you are looking at a post, you are only in one category.