amazon

Tuesday, March 12, 2019

How to create shortcodes in Wordpress

Problem:

We need to create  a custom code sniper inside our wordpress, for example add a message with the date and time then the page is open.

Solution:

1.- Create a function inside funtion.php of our wordpress
 
function sc_mycustomcodefunction() {
//bla bla bla, custom dode of our funtion
return ‘today will be agreat day’;
   }

2.- Create the shortcode

add_shortcode('SC01', 'sc_mycustomcodefunction');

3.- Inside the page of wordpress call the whostcode following the next sintaxys.

[SC01]

Details:
The function that contains the php code is sc_mycustomcodefunction
The shorcode is created with a wordpress function add_shortcode inside function.php
The parameters of the standard wordpress function add_shortcode are: ( <ShorCodeName>,<FunctionName> )
ShorCodeName is SC01 in our exxample
FunctionName is sc_mycustomcodefunction

Saturday, May 23, 2015

Adding #Charts to a website using javascrip with DataBase connection

Problem:   
You have some data in your DataBase that you would like to explode with Charts to offer Analytics solution to your visitors.

Solution:    
One simple way is to use highcharts, a company that has a collection of utilities to paint Charts using a simple script and of course with data base connecction and much more.

Sample:
$dbcon = mysql_connect("localhost", "bartolo", "******");
mysql_select_db("DATABASE", $dbcon);
$result = mysql_query("SELECT * FROM table");
while ($row = mysql_fetch_array($result)) {
   $data[] = "['".$row['name']."',".$row['tot']."]";
}
?>

...
$(function () {
    $('#container').highcharts({
        chart: {
            type: 'pie',
            options3d: { enabled: true, alpha: 45, beta: 0 }
        },
        title: { text: 'Chosse the best Broker' },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {  allowPointSelect: true, cursor: 'pointer', depth: 35,
                dataLabels: { enabled: true, format: '{point.name}' }}
        },
        series: [{
            type: 'pie',             name: 'Browser share',
            data: [  <?php echo join($data, ','); ?> ]
        }]
    });
});
  </script>

...
Source:

 

Wednesday, May 13, 2015

Web Scraper

$request_url ='https://www.google.es/search?q=Barcelona';

// The Regular Expression filter
 $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";

 function get_domain($url)
 {
  $pieces = parse_url($url);
  $domain = isset($pieces['host']) ? $pieces['host'] : '';
  if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
   return $regs['domain'];
  }
  return false;
 }

 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $request_url); // The url to get links from

 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // We want to get the respone

 $result = curl_exec($ch);

 $regex='|<a.*?href="(.*?)"|';
 preg_match_all($regex,$result,$parts);
 $title = preg_match('/title="(.+)">/', $html, $match);
 $links=$parts[1];
 asort($links);

 foreach($links as $link){
  $pos = strpos($link, '://');
  $exclude = strpos($link, 'google');  //remove google own results

  if ($pos!=0 && $exclude==0){
    $posini = strpos($link, 'http');
    $link = substr($link, $posini);
    echo "<a href='".$link."'>".get_domain($link)."</a> -> ".$link."<br>";
  }
 }

 curl_close($ch);


Sample:
http://viladecansoutlet.es/scrap.php

Sources:

Friday, May 1, 2015

Update joomla metada keywords from MySQL 'update' query

Problem:   

You are too lazy to update keywords from article manager in the backend, and need a quick option to do that without installing any random plugin that do that for you (I found that plugins don't works as you except).

 Solution:    

Go to MySQL administrator page and open your SQL windows to write a new SQL query to update your keywords, the joomla table / field where are stored meta about SEO keywords is _content , and the fieldname is "metakey".
Now with that you only need to run that sample SQL query to update SEO keywords.

SQL Query:
UPDATE *_content SET metakey = 'keyword1,'keyword2,'keyword3,'keyword4,'keyword5'
*Take careful that this query will update all your articles, if you would like to make some filter remember to use SQL conditions like WHERE id=x...

 

Sunday, April 26, 2015

how to rollover on CSS Image

Problem:   

You need to make a rollover on a sprite css image.

 Solution:    

You only need to make a ":rollover" class on your master css file like this:
 ...
.buttons{background-image:url('../images/sprite.png');background-position:-13px -21px}
.buttons:hover{background-image:url('../images/sprite.png');background-position:-13px -21px}
 ...
The tip is to add ":hover" to a different css class, that class will be loaded when the mouse pass over your css image sprite.

Your HTML code remains as:
...
<li class="buttons">&nbsp;</li>
...
 

Monday, February 9, 2015

joomla web too slow load

Problem:   

Your joomla web site spend a lot of time to load, too much time...

 Solution:    


Check if your site has been hacked, look at "include" folder file "joomla_rss.php" and rename it of just delete it.

Saturday, January 17, 2015

Connect Excel 32 Bits to MySQL ODBC in 32 BIts under Windows 64 Bits

Problem:   
You are using Windows 7 in 64 bits and MS Excel in 32 Bits, and you are not able to connect Excel to MysQL trought ODBC DNS 64 Bits.

 Solution:    
You need to create a ODBC for MySQL in 32 Bits to avoid architecture problems while connection Excel and DS over ODBC.
The Solution is full documented on the next link:

Source:
http://stackoverflow.com/questions/25039573/how-to-connect-ms-excel-2007-with-mysql