Showing posts with label tech tips. Show all posts
Showing posts with label tech tips. Show all posts

April 2, 2013

Wordpress Howto: Add Previous and Next Post Links to Blog Pages

HowTo: add Previous and Next Post buttons to your Wordpress blog.

Here's a tip: Want people to view more than one page of your site?

Give them an easy way to do that.

This might seem blatantly obvious but you'd be surprised how many sites don't have simple "Next" and "Previous" links on all pages that should.

You probably don't even notice, you just leave when you're done reading that article, probably without bookmarking or subscribing either (hint hint). You can literally double your "average time on site" in about 10 minutes with this simple trick.

Why is this key? Well, if more people visit more pages, and spend more time on your site, you will rank better. Even better, they'll be presented multiple opportunities to buy things or sign up or whatever your goal is that visitors should be doing.

Fun fact: time visitors spend on your site is also called "engagement" and Facebook is way out in front as the worldwide leader for this metric. In other words people spend more time on Facebook than they do on Twitter, Google+, etc.

I also show you how to change the links to say whatever you want, including how to add the post title to next / previous links. This is not only good for users, but also great for blog SEO. All bloggers should consider doing it this way, as internal linking is very important for search visibility.

How to add Next / Previous links to Wordpress post pages

We're going to edit your theme's Single Post template which is usually the single.php file.

Note: I recommend making a backup of the site before attempting any changes. If you have cPanel this is as easy as clicking Backup from the main cPanel page (most hosts), or you can use various Wordpress plugins, or simply copy the files somewhere safe on your local computer (like C:\Backup or /backup) before you edit them. 

Let's get started:

In your Wordpress dashboard, click Appearance->Themes->Editor 

In the right sidebar, click single.php 

Find the line:
<?php comments_template ?>

Hint: if your file is large, search for (Ctrl+F) the text comments_template

Go to the line AFTER that line by placing the cursor after ?> and pressing Enter

(I usually press Enter 2 or 3 times to give myself some space)

Add this block of code on the next line:

<div>
<h3>
<span style="text-align: center;">Where next?</span></h3>
<span><?php previous_post_link(); ?></span> <span style="float: right;"><?php next_post_link();
?></span>
</div>

That should get you started - you can use it as is or add custom styles with a bit of CSS.

*Note if you have multiple or custom post types - for example "Recipes" or similar - you will also have to find the .php files that generate those pages and change the Next and Previous links there as well. In most cases they should have the word "single" in the file name, like singlerecipes.php. Add the code above in the same place (new line after comments_template ?>)

Customizing Previous and Next Post link


You can add options by calling next_post_link and previous_post_link with options (add inside of the parentheses):

next_post_link('format', 'link', 'in_same_cat', 'excluded_categories');

So for example, to only pull items from the same category, exclude category number 2, and to always use "Next->" and the post title in bold for the text of the link, you would use:

next_post_link('%link', 'Next-><strong>%link</strong>', TRUE, '2');

in place of next_post_link();

You can even use an image for the Next post link in Wordpress although I generally recommend text links for SEO (if you use images, make sure you generate alt tags).

Save the file (you've backed it up, right?) and refresh your site. You may need to press Ctrl+Shift+Delete in your browser to clear the cache or just press Ctrl+F5 to refresh the page. If you don't like it or you broke the site, don't panic, just restore the backed up file, site, database, or cPanel backup that you made before making the changes.

If you need help, Call a developer

Further Reading -> Wordpress Customization:

"Wordpress Howto: Add Previous and Next Post Links to Blog Pages" continued here...

March 25, 2013

Linux Sed Multiple Lines

Using sed to delete multiple lines from a file in linux

I remember how frustrating it was before I figured out the easy multiline sed command. This example is especially useful to clean up website hacks / injections - a "regular" single-line sed is fine to remove most of the common base64 injections that hit most of the files in the document root... But sometimes you come across JavaScript injections that are clearly "tagged" so there's an easy way to identify it in all injected files (even if there are 100,000+), but substituting part of the "signature" into your usual sed command just doesn't work.


Enter the multiline sed

There are two ways to do this, I'm going to go over the simpler one here, since if you are reading this, you probably need this information now:


Replace or remove multiple lines from a text file (the easy way):


sed '/FIRSTLINETODELETE/,/LASTLINETODELETE/d' /the/file/to/delete/from

*Lines can be regex, but make sure you get the whole line

Note: if you are cleaning script injections with a unique "tag" in the comment before and after the injection, just replace UNIQUETAG below with the random characters in the comment:


user@host [~]# sed '/<!--UNIQUETAG-->/,/<!--UNIQUETAG-->/d' /your/injected/file



This will output what the file will look like, but sed without -i will not modify the file.


If the output of the above looks correct, add -i after sed:


sed -i WILL modify the original file - please be sure your output is correct

sed -i '/<!--UNIQUETAG-->/,/<!--UNIQUETAG-->/d' /your/injected/file

"Regular" sed command, operates on a single line by default:

user@host [~]# sed 's/<!--UNIQUETAG.*UNIQUETAG-->//' /your/injected/file

This version will NOT work across multiple lines

Here's a test example that simulates an actual tag you may see in a javascript injection:

linux sed multi-line example command

*Note: I'm working in Centos but this should all work the same on most Linux distros. Also, for completeness' sake the other and "proper" way to do multi-line sed is the N option, which allows you to do much more complex tasks. This example deletes the last 2 lines of a file:

user@host [~]# sed 'N;$!P;$!D;$d' fileName

More multiline sed examples

In over your head? Call a Developer for help with Linux, servers, code, websites, and more. Let us worry about the tech stuff while you move your business forward.

Links


"Linux Sed Multiple Lines" continued here...

March 22, 2009

Howto: Disable SELinux on Centos

How to Disable SELinux in Centos Linux

Occasionally, you will have trouble with selinux on Centos and need to temporarily disable selinux. Here is how you change selinux settings in centos and other red hat linux distributions:

  • Edit /etc/selinux/config (e.g. $sudo vi /etc/selinux/config)

  • Find the line:

    SELINUX=enforcing

    • a) If you simply want to set selinux to permissive mode - which will still warn you when something would have been denied

      change to

      SELINUX=permissive

    • b) If you are sure you want to completely disable selinux

      change to

      SELINUX=disabled


    and save (in vi type [Esc] :wq)

    centos disable selinux


  • SELinux will be disabled after reboot. To turn selinux off immediately, without rebooting use:

    $ sudo setenforce 0

  • If everything works, edit your /etc/grub.conf and change it from this:

    etcgrubconf


  • To this:

    completely disable selinux


That is how to disable selinux on Centos. Note: there is no way to uninstall selinux from Centos. This is as disabled as selinux gets.

You usually will not need to disable selinux completely. This may be useful for troubleshooting, but I would recommend trying to disable IPv6 and disable your firewall first (service ip6tables stop; service iptables stop) and see if you have another problem. Disabling selinux can come in handy for various testing environments and may solve a few obscure problems with certain software.




"Howto: Disable SELinux on Centos" continued here...

March 10, 2009

Quick Tech Tips - Part 2

When faced with a computer you know nothing about, you will want to at least know the basic system information to avoid headaches. This is not only useful for troubleshooting, and applies to client machines also - can you tell me what processes are running on your system right now? So how should you approach an unfamiliar computer system? How do you get the system specs, logs, and other information you might need to fix a problem, pass on to a technician, or list in your asset log?

This is what I do to gather specs and system information before starting to work on a system that I know nothing about:
    Windows

  • Backup the system: Start->Run...->ntbackup

  • Start->Right Click My Computer->Properties

  • Start->Run...->taskmgr

  • Start->Run...->msinfo32

  • Start->Run...->msconfig

  • Start->Run...->eventvwr

  • Start->Run...->cmd; ipconfig /all

  • Start->Run...->gpedit.msc

  • Start->Run...->regedit

    Linux

  • Backup the system: tar or rsync

  • dmesg

  • uname -a

  • free

  • top

  • lsmod

  • lspci

  • cat /proc/cpuinfo

  • cat /var/log/messages

  • vi /etc/sysctl.conf

  • cd /etc/sysconfig; cat [things that you want info about] (e.g. cd /etc/sysconfig; cat network)

  • ifconfig /all

  • You will find much more information browsing around the /proc virtual filesystem, so e.g. to get the current max threads in the kernel, use: cat /proc/sys/kernel/threads-max

Am I missing a tech tip you use regularly? Add it in the comments below!


"Quick Tech Tips - Part 2" continued here...