The MU forums have moved to WordPress.org

creating a widget? few questions, new to wordpress please help! (9 posts)

  1. dtrworld
    Member
    Posted 19 years ago #

    Hi to who ever has taken an intrest in this topic.
    The reason i am posting here is because i am in need of help wih my wordpress site, i have a couple questions in which i hope some one can help me with.

    1) How can i make a widget, i need one that displays the latest posts from my ipb forum or how can i add an include to display the latest posts in the side bar(s)

    2) How can i add google adsense in the top of the middle section of my wordpress site, above all the posts etc..
    I want it so its directly under the banner if possible?

    Any help will be greatlly appreciated!

    Kindest regards, Ben

  2. SteveAtty
    Member
    Posted 19 years ago #

    The best way of coding a widget is to take an existing one and use it as a shell to build your own code in.

    Google ads under the banner - Edit the header and put it in there. You may need to edit the stylesheet to change a few sizes. If you want to put it in various templates then you might be better off coding it as a chunk of php. This is the php code I've got and then I do an include in the header. Note that it tweaks some of the colours to match the ads to the header :

    <?php
    
    // Get the template name
    $x=explode('themes/',get_bloginfo('template_url'));
    // Set up the defaults.
    
    $gadwidth=728;
    $gadheight=90;
    $gadcolbor = "FFFFFF";
    $gadcolbg = "FFFFFF";
    $gadcolli = "0000FF";
    $gadcolte =  "000000";
    $gadcolurl = "008000";
    
    switch ($x[1]) {
    case "batavia":
        $gadcolbg="CCCC99";
        break;
    case "anarchy":
             $gadcolbg="000000";
             $gadcolte ="FFFFFF";
             $gadcolurl = "FFFFFF";
        break;
    case "blue-moon-10":
        $gadcolbg="1C2023";
        break;
    case "flex":
        $gadcolbg ="404040";
        break;
    case "radmod":
             $gadcolbg ="000000";
        break;
    case "steam":
             $gadcolbg ="73a0c5";
        break;
    case "quentin":
             $gadcolbg ="F2E2C1";
        break;
    }
    
    $full_code="<script type="text/javascript"><!--n google_ad_client = "pub-4296098225870941";n google_ad_width = ".$gadwidth.";n google_ad_height = ".$gadheight.";n g
    oogle_ad_format = "".$gadwidth."x".$gadheight."_as"; google_ad_type = "text_image";n google_ad_channel ="7151759043";n google_color_bg = "".$gadcolbg."";n google
    _color_border = "".$gadcolbg."";n google_color_link = "".$gadcolbg."";n google_color_text = "".$gadcolbg."";n google_color_url = "".$gadcolbg."";n//--></script>
    n <script type="text/javascript" n   src="http://pagead2.googlesyndication.com/pagead/show_ads.js">n</script>n";
    print $full_code;
    ?>
    
  3. dtrworld
    Member
    Posted 19 years ago #

    thanx mate, really appreciated i thought it would be more complicated then that ;)
    In regards to the widget/plugin will it work if i just put in a php include?

  4. SteveAtty
    Member
    Posted 19 years ago #

    for the Widget you just put it in the muplugins folder as long as you have the widget plugin installed or the latest version of WordPress MU from SVN.

    BTW - don't forget to change the Google account id in the code ... or I'll get all the money ;)

  5. dtrworld
    Member
    Posted 19 years ago #

    i have the latest version of wordpress, 2.2 i think it is.
    In regards to the code ive already changed that ;)

    I just want to include this
    <?php include("http://www.bikerforumz.com/latest_posts.php");?>
    into the side bar, pref at the top of the collum if possible. if you could give me a point in the right direction i would very much appreciate it.
    I would be more then happy to link back to your site in return, if you have one.
    I have about 18 sites in total which i will be using it on.

    Thanx again, you have been a great help so far!

  6. dtrworld
    Member
    Posted 19 years ago #

    Any help would be very appreciated, thanx.

  7. Phyrax
    Member
    Posted 18 years ago #

    Honestly if you're just doing an include, just open the sidebar.php file you're wanting to edit and include it after something like this:

    <?php /* Widgetized sidebar, if you have the plugin installed. */
    if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Custom Sidebar') ) : ?>

    What theme are you using, I may be able to tell you exactly what line #

  8. andrea_r
    Moderator
    Posted 18 years ago #

    you know this thread is five months old, right?

    And that widgets are now in the core bundle?

  9. Phyrax
    Member
    Posted 18 years ago #

    Lol, no I didn't realize that, since I did find this post on google :P

About this Topic