Archive

Archive for the ‘Development’ Category

Como obter o ID de um post dentro e fora do Loop do WordPress

January 16th, 2010 lmmendes No comments

Ultimamente tenho andado a fazer algumas modificações ao meu blog e surgiu-me a necessidade de obter o ID de um post fora do loop (The Loop) do WordPress:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

Dentro do loop para obter o ID basta fazer o seguinte:

$post->ID

Já fora do loop para termos acesso ao ID do post vamos ter que aceder á variável global $wp_query, ou seja, para obtermos acesso ao ID do post:

global $wp_query;
$wp_query->post->ID

É tão simples como isso, para saberem mais informação sobre o $wp_query consultem o Codex aqui.

Categories: Development, WordPress Tags: ,

Remove WordPress iNove theme sidebar using custom fields

January 16th, 2010 lmmendes 1 comment

I’m using WordPress iNove theme v.1.4.6 and i needed a way to hide the sidebar for a specific post so i dove in the iNove theme code and figured out how to do this with the minimum changes to the original theme code.

First open the iNove theme ‘header.php’ file using your favorite editor, usually found at <wp install folder>/wp-content/themes/inove/header.php.

Now look for this piece of code (starting from the top of the file):

... some code ...
			$feed = 'http://' . $options['feed_url'];
		}
	} else {
		$feed = get_bloginfo('rss2_url');
	}
?>

Read more…

Installing nginx and rails passenger on Mac OS X Snow Leopard

October 17th, 2009 lmmendes 2 comments

I’m new to Mac OS X, nginx and rails so after much goggling i finally got everything to work so i resolved to compile the list of instructions that i followed.

First we need to download, compile and install PRE (Perl Compatible Regular Expressions) it’s required for nginx. You can find the most recent version here http://www.pcre.org/ , at time of writing this post the most recent version is 7.9

Compiling and installing PRE

1
2
3
4
5
6
7
8
mkdir ~/apps/src
cd ~/apps/src
curl -O ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.9.tar.gz
tar -xvzf pcre-7.9.tar.gz
cd pre-7.9
./configure --prefix=/usr/local
make
sudo make install

Installing Phusion Passenger via gem

1
gem install passenger

Now that you have Phusion Passenger installed you can install and configure nginx and passenger using a bundled script from passenger called “passenger-install-nginx-module” but that is no fun and usually don’t install the lasted stable version of nginx, so you can run the script and follow it’s instructions (that include auto-downloading and installing of nginx) or do it my way… the hard way.

So now we need to find where “gem” installed the nginx module so we can refer to it’s during the nginx configuration, so to get the module path you just need to run this:

1
passenger-config --root

In my case the command output is

1
/Users/<usename>/.gem/ruby/1.8/gems/passenger-2.2.5

You need to write down this output, you will need it in the next step.

Now it’s time do download and install nginx we will be installing version 0.7.62 (stable).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
cd ~/apps/src
curl -O http://sysoev.ru/nginx/nginx-0.7.62.tar.gz
tar -xvzf nginx-0.7.62.tar.gz
cd nginx-0.7.62
./configure \
--prefix=/usr/local \
--conf-path=/etc/nginx/nginx.conf \
--http-log-path=/var/log/nginx/access_log \
--error-log-path=/var/log/nginx/error_log \
--pid-path=/var/run/nginx.pid \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \
--with-md5-asm --with-md5=/usr/include \
--with-sha1-asm \
--with-sha1=/usr/include \
--with-http_realip_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--add-module='/Users/<username>/.gem/ruby/1.8/gems/passenger-2.2.5/ext/nginx'
make
sudo make install

Has you can see in line 20 you need to add the previous output that i told you to write down.

The nginx install path’s, bin, etc… :

bin: /usr/local/sbin/nginx
etc: /etc/nginx/
pid: /var/run/nginx.pid
document root: /usr/local/html/
error log: /var/log/nginx/error_log

Now let’s create a demo rails application to show things working

1
rails ~/Sites/blog

Edit /etc/nginx/nginx.conf (you can use your favorit text editor, i will be using vi)

1
sudo vi /etc/nginx/nginx.conf

Find the “http” section and add this lines

1
2
passenger_root /Users/<username>/.gem/ruby/1.8/gems/passenger-2.2.5;
passenger_ruby /usr/bin/ruby;

You should get something like this:

1
2
3
4
5
6
7
http {
    include       mime.types;
    default_type  application/octet-stream;
 
    passenger_root /Users/<username>/.gem/ruby/1.8/gems/passenger-2.2.5;
    passenger_ruby /usr/bin/ruby;
. . . .

Now adding the virtual host to nginx.conf to run ~/Sites/blog app ( /Users//Sites/blog )

Add a new server configuration (vhost) inside the http section of the nginx.conf file like this:

1
2
3
4
5
6
7
  server {
          passenger_enabled on;
          listen 80;
          server_name blog;
          root /Users/<username>/Sites/blog/public;
          rails_env development;
  }

Now save the file and let’s se if it’s all working.

Start the nginx like this:

1
sudo /usr/local/sbin/nginx

Let’s edit the /etc/host file to add the new vhost name ( blog )

1
vi /etc/hosts

add this to the bottom of the file, save and exit

1
127.0.0.1       blog

Now point your browser to http://blog and you should the the standard rails app page if you experince any problem starting nginx use this command to see nginx error log

1
tail -f /var/log/nginx/error_log

All done, i hope it helps you.

MySQL Error: #1005 – Can't create table '….#sql-e7c_89.frm' (errno: 150)

August 1st, 2009 unsignedint 1 comment

Se estiverem a tentar criar uma relação entre duas tabelas usando o MySQL e obtiverem o seguinte erro:

#1005 - Can't create table '.\twitta\#sql-e7c_89.frm' (errno: 150)

Experimentem activar o modo de debug do motor de innoDB de forma a obter mais informações sobre o erro e a poderem-no perceber.
Read more…

Categories: MySQL Tags: , ,

HttpFox – HTTP analyzer addon for Firefox

May 12th, 2009 unsignedint No comments

httpfox
HttpFox monitors and analyzes all incoming and outgoing HTTP traffic between the browser and the web servers.

It aims to bring the functionality known from tools like HttpWatch or IEInspector to the Firefox browser.

Information available per request includes:
- Request and response headers
- Sent and received cookies
- Querystring parameters
- POST parameters
- Response body

HttpFox

Categories: Development, Firefox Tags: ,