Archive for June, 2012

How to get the wordpress posts parent page information out

In many cases when your working with WordPress you’ll want to assign a specific page template to become the static page. Usually replacing the homepage with a static page as well.

You can do this in WordPress -> settings -> reading.

When you set say ‘Latest News’ to be your posts page you may want to get that out at the top of the loop.

Unfortunately in some cases, you might also just settle with the default template for your Latest News page (index.php) which can make things a little more annoying.

WordPress will fill the loop with your posts rather than information about your page. Making the title of the page unavailable. This little useful snippet of code will help you overwrite that.

<div id="title">
<?php $your_title = get_the_title( get_option('page_for_posts', true) ); ?>
<h1><?= $your_title; ?></h1>
</div>

How to change the default from wordpress email from address

Sometimes you might want to stop WordPress sending emails with the default WordPress email from address.

Usually something like wordpress@domain.com

Often displayed like so: WordPress wordpress@domain.com

There are a few plugins available to achieve this, but personally I don’t relying heavily on WordPress plugins – mainly because dependencies on too many third parties can be annoying.

Particularly when there is not much code needed to achieve the change.

Add the following code to your functions.php file.

add_filter('wp_mail_from', 'replacement_mail_from');
add_filter('wp_mail_from_name', 'replacement_mail_from_name');
function replacement_mail_from($old) {
 return 'your email address';
}
function replacement_mail_from_name($old) {
 return 'your name or your website';
}

How to go to line number in vim – terminal / server

In addition to my last post which was how to show line numbers in Vim I soon after wanted to find a way to jump to the line number I knew I needed to edit.

Using a combination of grep -n “blah blah” file.txt which will return the string if found and the line numbers that it was found on.

Armed with the line number from grep I soon found a way to jump to line number in vim.

Simply do the following.

:956 + enter (obviously replacing 956 with whatever your line number is)

And that’s all there is to it.

You can jump to the beginning and end of files as well by simply Hitting G.

How to show line numbers in Vim for use with terminal and servers

Why it’s taken me quite this long to decide I actually really want to just see line numbers in VIM on one or all of my live servers I have no idea.

I think it’s mainly because out of lazyness when an apps in development I have got into the habit of using “mate” (Textmate’s CLI) instead.

Needless to say to enable line numbers in vim, for use with any installation of vim be it server or local machine is really easy.

Open up a terminal (connect to your server if your doing it to remote) once ready type:-

vim ~/.vimrc

Hit “i” for insert mode and enter “set number”.

Now esc – :wq to save and quit and that’s it.

Line numbers will now show in your next document opened by vim.