Wednesday, 21 November 2012

How to draw multiple circles on your Google Map.

The problem:  I have a Wordpress website and I want to display a map with multiple placemarkers and have circles displayed over the placemarkers.


The solution. 

Firstly I installed this plugin on my Wordpress installation

Google Maps V3 Shortcode Multiple Markers for Wordpress .  This plugin enables you to put multiple placemarkers on your Google Map.  

In adding the circles to the placemarkers I found this example code a great help . 
Example of how to place Circles on Placemarkers in Google Maps

The key code is here
[code]
// Add a Circle overlay to the map.
        var circle = new google.maps.Circle({
          map: map,
          radius: 3000000 // 3000 km
        });
circle.bindTo('center', marker, 'position');

[/code]

So now all we need to do is intergrate that into the plugin .  Although you'll probably want to turn down the size of that radius.  Here's what I did to the site I'm working on.

After you've installed the plugin as I've recommended above then .

OPEN wp-content/plugins/google-maps-v3-shortcode-multiple-markers/Google-Maps-v3-Shortcode-multiplemarkers.php

there are 2 instances of

$returnme .=' var marker = new google.maps.Marker({

look for the code

$returnme .= ' html: site[2] });
   ';


underneath those commands.  After this add

[code]

    //  adding the circle code // littleripples.com
     $returnme .= "// Add a Circle overlay to the map. - // start
        var circle = new google.maps.Circle({
          map: MultipleMarkerMapDemo,
          radius: 50000 // 3000 km
        });/**/
        circle.bindTo('center', marker, 'position');";

   

[/code]


SAVE -> UPLOAD

and thats it :)  




Friday, 16 November 2012

I want to add Dropdown menus to my Wordpress Theme Dfmarine.

In the end I did this by adding a widget space and using the plugin Dropdown Menu Widget   This method means you still build the menus as you would in 'appearance > menus'  but would call the menu up from the Widget.

wordpress drop down menu not working

wordpress how to make my template use dropdown menus



Tuesday, 13 November 2012

wordpress menu link Forbidden You don't have permission to access /index.php on this server.

After getting the above issue the answer for me was as simple as this.

> I went to Settings > Permalink Settings

and click on 'Default' instead. 

>  then I checked the website and my menu links worked fine.

> on going back to > Settings >Permalink Settings  > Common Settings

and reset the selection to 'Post Name'  and by some sort of miracle the menu's work again. :)

Friday, 9 November 2012

Wordpress Twitter Widget Pro doesn't update - Heart Internet issues

The first problem here was with the Wordpress Plugin - Twitter Widger Pro not updating.  I eventually found the cause of this to be with Heart Internet.  Check here for the fix  Twitter Widget Pro Not Updating Fix for Heart Internet. 

Although this fix at first seemed to work fine I found that it would only work intermittently; and kept showing a 'No Tweets Available' message. 

The following code is probably a ugly hack; but to be fair at this point my experience of the Wordpress framework and logic is very basic.  However it does now work; so feel free to use.

OPEN twitter-widget-pro/wp-twitter-widget.php

FIND

if ( count( $tweets ) == 0 ) {


REPLACE this with the following IF statment


        if ( count( $tweets ) == 0 ) {
        global $wpdb;
    // here I'm going to check the database for any old results
//$tweet_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->options WHERE option_name LIKE '%_transient_twp_%' " ) );
 $tweet_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->options WHERE option_name LIKE '%%_transient_twp_%%' ;" ) );
// echo"$tweet_count
";

    if($tweet_count==0){
        $widgetContent .= '
  • ' . __( 'No Tweets Available', $this->_slug ) . '
  • ';
    } else {
    $lasttweetrow = $wpdb->get_row("SELECT * FROM $wpdb->options WHERE option_name LIKE '%_transient_twp_%'
    ORDER BY option_id DESC
    LIMIT 1;");

    $options = $lasttweetrow->option_value;   
    $options_array = explode(';', $options);
    $tweetrow = $options_array[11];       
    $tweet_array = explode(':', $tweetrow);
    $tweet = $tweet_array[2];
    $tweet = str_replace("\"", "", $tweet);

    $tweetusernamerow = $options_array[34];       
    $tweetusername_array = explode(':', $tweetusernamerow);
    $tweetusername = $tweetusername_array[3];
    $tweetusername = str_replace("\"", "", $tweetusername);

    $tweetcreatedrow = $options_array[52];       
    $tweetcreated_array = explode(':', $tweetcreatedrow);
    $tweetcreated = $tweetcreated_array[3];
    $tweetcreated = str_replace("\"", "", $tweetcreated);




    $args['title'] = "Twitter: $tweetusername";

            $args['title'] = apply_filters( 'twitter-widget-title', $args['title'], $args );
            $args['title'] = "Twitter";
            $widgetContent .= $args['before_title'] . $args['title'] . $args['after_title'];
           

    $widgetContent .= "

  • $tweet



  • ";

        }

            }


    Wordpress and a search to the database inside the code

    Hi

    Here's a couple of tips when starting out with a bit of Wordpress development.  What I need to do is add a check within a plugin.  Take a look here How to connect to the database from inside Wordpress for the code you need.

    Here's a couple of tips that I've had to find out. 

    * firstly you may  need to declare the $wpdb; object above your call to the database

    Secondly

    why cant i use % in wpdb prepare statement

    why cant i use percentage sign in wpdb prepare statement


     in a LIKE statement just double up the %% 

    ie

    $tweet_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->options WHERE option_name LIKE '%_transient_twp_%' ;" ) );


    will be

    $tweet_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->options WHERE option_name LIKE '%%_transient_twp_%%' ;" ) );

    Thursday, 8 November 2012

    Twitter Feed Widget works intermittently .

    Twitter Feed Widget works intermittently .


    I wondering how this effects the mysql and if theres a way I can make sure the MySQL  doesn't update if a null result.

    >  the above doesn't seem possible as there are tweets in the MySQL but they're not being included.

    >  on line 571 of wp=twitter-widget.php then you'll see the code

    if ( count( $tweets ) == 0 )

    which runs the 'No Tweets Available' message.


    line 555 .

    $tweets = $this->_getTweets( $args );


    line 737

        private function _getTweets( $widgetOptions ) {
            $key = 'twp_' . md5( $this->_getFeedUrl( $widgetOptions ) );
            return tlc_transient( $key )
                ->prevent_background()
                ->expires_in( 5 ) // cache for 5 minutes
                ->updates_with( array( $this, 'parseFeed' ), array( $widgetOptions ) )
                ->get();
        }



    I can't find anywhere that writes to the database - having said I can see the tweets come up in 'wp_options'  listed under '_transient_twp_'


    if I do a search for most recent and

    SELECT *
    FROM `wp_options`
    WHERE `option_name` LIKE '%_transient_twp_%'
    ORDER BY `option_id` DESC
    LIMIT 1

    this will bring back the result I want.


    $lasttweetrow = $wpdb->get_row("SELECT * FROM $wpdb->wp_options WHERE `option_name` LIKE '%_transient_twp_%'
    ORDER BY `option_id` DESC
    LIMIT 1");



    Which has made the if ( count( $tweets ) == 0 )  code into.

        if ( count( $tweets ) == 0 ) {
        // here I'm going to check the database for any old results
    $lasttweetrow = $wpdb->get_row("SELECT * FROM $wpdb->wp_options WHERE `option_name` LIKE '%_transient_twp_%'
    ORDER BY `option_id` DESC
    LIMIT 1");

    $options = $lasttweetrow->option_value;  
    $options_array = explode(';', $options);
    $tweetrow = $options_array[11];      
    $tweet_array = explode(':', $tweetrow);
    $tweet = $tweet_array[2];

    }

    Tuesday, 6 November 2012

    Wordpress Plugin Twitter Widget Pro has stopped updating

    The following solution is for the above problem if you have Heart Internet; however it is possible the same problem may effect other hosts as well.

    The solution you need is on this page; Twitter Widget Pro not updating.  
    I would note though that not only did I first need to delete the plugin I also needed to delete it from the MySQL data base.  I recommend doind a search for your twitter username in MySQL and make sure all details are deleted ( BACKUP FIRST )