1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Adding YouTube To Your Autoblog

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

  1. mbceo

    mbceo Junior Member

    Joined:
    Feb 9, 2009
    Messages:
    164
    Likes Received:
    25
    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.

    Code:
      
    [URL]http://www.google.com/uds/solutions/videosearch/index.html[/URL]
    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:

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

    Code:
    <?php
    $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:

    Code:
    [{ 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.

    Enjoy!!:D