WordPress Basic Kit
WordPress is one of the best blog applications which can be also used as CMS. It has lots of useful plugins and widgets. The documentation (codex) explains very well the application flow. An it is far more simple than its competitors.
WordPress managements consists of two main parts:
- WP files: where structure and styles reside
- WP db: where content (including links reside)
Moving a WP installation from two servers involves copying the files and the db (but the content of the db must be updated: domain). It is important to remember that even if you share de files in different computers (e.g., Dropbox) the db is particular for each computer (each apache+php+mysql installation).
Good practices:
- Have exactly only two copies of the site (local and online, no more).
- Update the files/db in local installation and if all works update the online version
- For commodity, if you have multiple local copies you can have a main one with its local db and secondary ones pointing to the online db. This is good not to maintain too much copies of the db, you always have to remember which is the main local copy. Another option if you share multiple local copies is to create a secondary online db to which all the local copies point but you can’t work without internet access.
Install WP (with permlinks)
- NOTE: Many servers offer one-click installations (check it first)
- Create a folder wherever in your HD or in a server.
- sudo a2enmod rewrite
- DEPRECATED: Create a file (sitename) in /etc/apache/available-sites/
NameVirtualHost *
<VirtualHost *>
ServerName example.local
DocumentRoot /home/example/
<Directory /home/example/>
Options FollowSymLinks
AllowOverride All
</Directory>
ErrorLog /var/log/apache2/error.log
#Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
</VirtualHost> - DEPRECATED: sudo a2ensite nom (activate the new site)
- DEPRECADED: sudo /etc/init.d/apache2 reload (reload)
- DEPRECATED: sudo vim /etc/hosts (edit domain and add the blue part) (127.0.0.1 localhost example.local) (only one allowed…)
- DEPRECATED: sudo /etc/init.d/networking restart
- sudo mkdir /var/www/mysite; symlink from the user folder (permalinks won’t work) so better add an alias into /etc/apache2/sites-available/default configuration file.
- sudo chown -R user:user mysite (to give the permissions and owning in /var/www/) (the command is recursive). NOTE: for WP set user to www-data (apache2 default user). Required for automatic update otherwise update error. Check also
wp-config.php:define('FS_METHOD','direct');define('FS_CHMOD_DIR', 0777 );define('FS_CHMOD_FILE', 0777 ); - sudo /etc/init.d/apache2 restart
- WordPress default language is English. I recommend to install it in English. If you need Spanish translations download only the es_ES.mo from the Spanish version, copy it to /wp-content/languages/, and in wp-config.php change: define (‘WPLANG’, ‘es_ES’);
- The installation is very easy see 5-min-installation. It is just a matter of download, uncompress, add an empty MySQL DB, and configure.
- PARA Q SE PUEDA ACTUALIZAR EN LOCALHOST ver paso 13.
- Enabling permlinks is done automatically in the default installation .htaccess (provided that you have modrewrite module enabled. However, the apache2 default site configuration /etc/apache2/sites-enabled/default… may have for the /var/www/ directory the AllowOverride None and you must update it to AllowOverride All.
WordPress basic configuration
Things that you probably want to do in settings:
- General: Write down the site name, description, etc.
- Reading: Front page displays a static page (you have to create “home” page first). You may want to remove comments from pages by modifying “page.php” template. You just have to comment the comments line.
- Permlinks (activate and set to postname)
Afterwards you will need a theme:
- There is plenty of choice. It is the easiest way. All the themes come with configurable parts.
- If you have specific requirements you can partially overwrite any theme doing a child theme (easily).
- If you have very special requirements you can build a completely new theme.
Finally, you might want to install some widgets (sidebar) or plugins (special needs).
Widgets
With widgets you can easity tune a sidebar. You can add the standard meta, you can add some links (using the wordpress link standard post_type), you can create a tag cloud, show categories, show Archive, Calendars, and so on and so forth.
An interesting standard widget is “Text” which allows you to insert a title and a random HTML/JS code in which you can add whatever you want. It is useful for example to insert a Google Ads (AdSense) space.
Tricks
Upload and memory limits: find your php.ini, or if you don’t have access use your .htaccess file.
php.ini (find and update)
upload_max_filesize 100M
max_execution_time 360
memory_limit = 128M
.htaccess (add or update if present)
php_value upload_max_filesize 100M
php_value max_execution_time 360
php_value memory_limit = 128M
you might also consider these
php_value post_max_size 20M php_value max_input_time 200
Useful plugins
- Custom Post Type UI: Add post types apart from posts and pages (e.g., books) and taxonomies (e.g., book-author, …).
- Advanced custom fields: If you need more fields (not taxonomies) for your new types (alt: magic fields, more fields)
- Post to twitter: Automatically post your posts on your twitter.
- Add links to facebook: Same for facebook but twitter can post in your facebook and you don’t need a this plugin.
- Linkedin: You can find a specific plugin or install one-for-all social plugin.
- Multilang-Internationalization: WPML (payment), qTranslate (translate same post…), … (http://codex.wordpress.org/Multilingual_WordPress)
- Sliders: smooth slider??
- Role administration: Capability manager
- Limit post text without excerpt: Word Limit
- Paginators: wp-pagenavi
- Cache: wp super cache (complete), quick cache (fast and easy, and does the job)
- Forms: Contact forms 7, Custom Contact Forms (to handle php you need to use hooks in functions.php), if the form is very complex you probably want to make it in a template…
PLUGINS PARA HACER GALERIA EASY: Use the WP integrated gallery (uploading images).
To separate the blog from cms create a empty blog page and put permalinks as /blog/%year%/…
Per a pagines especials crear templates(plantilles) nous, es pot incloure header i tot igual i usar bd…
codex.wordpress.org
Copy WordPress to other servers:
1. Export MySQL DB (important rename server e.g. localhost/web to the target server)
2. Copy web folder files, update the wp-confing.php with the new db user/pass/address.
2a. IMPORTANT NOTE: check that .htaccess is copied because hidden files sometimes are not incluced when we copy the files.
3. Import DB in target MySQ
4. Create user in target MySQL
7. (Permalinks) Activate in httpd.conf (Apache config file) the rewrite module.
* LoadModule rewrite_module modules/mod_rewrite.so *If errors -> switch to ?p=xx
In .htaccess
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
8. (if not so) Change in httpd.conf: AllowOverride All.
Get it social: Tweeter, Facebook, LinkedIn plugins
- Twitter: WP to Twitter (very popular, tweet posts), Tweeteable (tweet posts), Tweet This (allow users to tweet your posts)
- Facebook: Add Link to Facebook
Change Admin labels
For example “Posts” by “Noticias”. Just add the following code in your theme functions.php.
function change_post_menu_label() {
global $menu;
global $submenu;
$menu[5][0] = ‘Noticias’;
$submenu['edit.php'][5][0] = ‘Noticias’;
$submenu['edit.php'][10][0] = ‘Nueva Noticia’;
/*$submenu['edit.php'][15][0] = ‘Status’; // Change name for categories
$submenu['edit.php'][16][0] = ‘Labels’; // Change name for tags
*/
echo ”;
}
function change_post_object_label() {
global $wp_post_types;
$labels = &$wp_post_types['post']->labels;
$labels->name = ‘Noticias’;
$labels->singular_name = ‘Noticia’;
$labels->add_new = ‘Nueva Noticia’;
$labels->add_new_item = ‘Nueva Noticia’;
$labels->edit_item = ‘Editar Noticias’;
$labels->new_item = ‘Noticia’;
$labels->view_item = ‘Ver Noticia’;
$labels->search_items = ‘Buscar’;
$labels->not_found = ‘No se ha encontrado ninguna’;
$labels->not_found_in_trash = ‘No se ha encontrado ninguna en la papelera’;
}
add_action( ‘init’, ‘change_post_object_label’ );
add_action( ‘admin_menu’, ‘change_post_menu_label’ );
That’s it.
Configure pagination (see wp-pagenavi example)
add custom post types in the loop
http://wpengineer.com/2249/wordpress-custom-post-types-get-into-the-loop/
http://sixrevisions.com/wordpress/how-to-customize-the-wordpress-admin-area/
Handling multilinguality
http://codex.wordpress.org/Multilingual_WordPress
Including javascript libraries
Some come by default (jquery, jquery.ui, prototype, scriptacolous, thickbox…) you just have to enable them with wp_enqueue_script( ‘jquery’ );
Other scripts you better add them manually in the header or body of the desired page of the desired theme or child-theme:
<script src=”<?php echo get_stylesheet_directory_uri(); ?>/js/jquery.dataTables.min.js” type=”text/javascript”></script>
WordPress automatically loads the dependencies (array).
Useful Functions for functions.php
Limit words of any content and put …[+] whith this function.
function limit_w($content, $link, $limit, $more_link_text = ‘[+]‘) {
$content = strip_tags($content);
$contentar = explode(” “, $content, $limit);
array_pop($contentar);
$content = implode(” “,$contentar);
$content.=”… <a href=’”.$link.”‘>”.$more_link_text.”</a>”;
return $content;
}
Have a beautiful pagination system:
function wpapi_pagination($pages = ”, $range = 4)
{
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == ”)
{
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages)
{
$pages = 1;
}
}
if(1 != $pages)
{
echo “<div class=\”wpapi_pagination\”><span>Page “.$paged.” of “.$pages.”</span>”;
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo “<a href=’”.get_pagenum_link(1).”‘>« First</a>”;
if($paged > 1 && $showitems < $pages) echo “<a href=’”.get_pagenum_link($paged – 1).”‘>‹ Previous</a>”;
for ($i=1; $i <= $pages; $i++)
{
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
{
echo ($paged == $i)? “<span class=\”current\”>”.$i.”</span>”:”<a href=’”.get_pagenum_link($i).”‘ class=\”inactive\”>”.$i.”</a>”;
}
}
if ($paged < $pages && $showitems < $pages) echo “<a href=\”".get_pagenum_link($paged + 1).”\”>Next ›</a>”;
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo “<a href=’”.get_pagenum_link($pages).”‘>Last »</a>”;
echo “</div>\n”;
}
}
Theme edition, child themes, configuring and tunning wordpress
http://yoast.com/wordpress-theme-anatomy/ this is a great tutorial to start.
