Vyladění nové instalace WordPressu

**Nastavení .htaccess**

Zabezpeční souboru wp-config.php

/—code php

order allow,deny
deny from all

\—

Adresa vždy bez www

/—code php
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} ^www.domena.cz
RewriteRule (.*) http://domena.cz/$1 [R=301,QSA,L]
\—

Adresa vždy s www

/—code php
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} ^domena.cz
RewriteRule (.*) http://www.domena.cz/$1 [R=301,QSA,L]
\—

Zákaz výpisu obsahu adresářů

/—code php
Options -Indexes
\—

Odstranění „rubriky“ z url

/—code php
RewriteRule ^category/(.+)$ http://www.domena.cz/$1 [R=301,L]
\—

(ev. použijeme plugin „No category base“:45)

**Robots.txt**

Zákaz přístupu do adresářů WordPressu robotům a uvedení odkazu na sitemap

/—code php
User-agent: *
Disallow: /cgi-bin/
Disallow: /wp-admin/
Disallow: /wp-includes/
Disallow: /wp-content/
Disallow: /trackback/
Disallow: /xmlrpc.php
Disallow: /wp-

Sitemap: http://domena.cz/sitemap.xml
\—

Pro vytvoření sitemapy použijeme plugin „Google XML Sitemaps“:219

**Nastavení „user-friendly“ odkazů**

Nastavení > Trvalé odkazy > Vlastní struktura: /%postname%/

**Vytvoření a odkaz na favicon**

1. Vytvoříme *favicon.ico* (např. „zde“:http://www.chami.com/html-kit/services/favicon/ nebo „zde“:http://tools.dynamicdrive.com/favicon/)
3. Zkopírujeme ho do rootu našeho blogu
2. Umístíme do hlavičky v souboru *header.php*

/—code php

Zobrazení obsahu pouze přihlášeným uživatelům

Do souboru **functions.php** (Vzhled > Upravit soubory) stačí přidat následující:

/—code php
add_shortcode( ‚member‘, ‚member_check_shortcode‘ );

function member_check_shortcode( $atts, $content = null ) {
if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
return $content;
return “;
}
\—

Pak už stačí kdekoli v příspěvku „obalit“ text určený pouze registrovaným uživatelům tagem [member]:

/—code php
[member]
Toto se zobrazí pouze přihlášeným uživatelům
[/member]
\—

Je-li potřeba to nastavit už v šabloně vzhledu, je třeba použít

/—code php

\—

„Více příkladů »“:http://justintadlock.com/archives/2009/05/09/using-shortcodes-to-show-members-only-content

SQL dotazy k nezaplacení

**Náhrada jednoho řetězce za druhý v libovolné tabulce a poli**

/—code php
UPDATE table_name
SET field_name = replace( field_name, ‚tohle_najdi‘, ‚timhle_nahrad‘ );
\—

k nezaplacení např. při přesunu webu na jinou adresu, lze tak nahradit absolutní URL obrázků, siteurl-homeurl nebo guide

/—code php

UPDATE wp_posts SET post_content = REPLACE(post_content, ‚http://stara.cz‘, ‚http://nova.cz‘);
UPDATE wp_posts SET guid = REPLACE(guid, ‚http://stara.cz‘, ‚http://nova.cz‘);
UPDATE wp_options SET option_value = REPLACE(option_value, ‚http://stara.cz‘, ‚http://nova.cz‘);
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, ‚http://stara.cz‘, ‚http://nova.cz‘);
\—

Tento způsob ale bohužel neřeší případ tzv. „serializovaných dat“:http://stackoverflow.com/questions/11817950/what-is-data-serialization. Při migraci WP na jiné url je proto jistější použít nějaký specializovaný nástroj pro náhradu v serializovaných datech, např.:

„http://pixelentity.com/wordpress-search-replace-domain/“:http://pixelentity.com/wordpress-search-replace-domain/,

„https://interconnectit.com/products/search-and-replace-for-wordpress-databases/“:https://interconnectit.com/products/search-and-replace-for-wordpress-databases/

nebo pluginy „WP Migrate DB“:https://wordpress.org/plugins/wp-migrate-db/ či „Better Search Replace“:https://wordpress.org/plugins/better-search-replace/.

WP Migrate DB migrates your database by running find & replace on URLs and file paths, handling serialized data, and saving an SQL file.

Někdy je potřeba jen přidat text na konec obsahového pole

/—code php
UPDATE wp_posts SET post_content =
concat(post_content, ‚ …‘) WHERE post_type = ‚post‘;
\—

nebo hromadně nahradit url uvedené komentátorem

/—code php
UPDATE wp_comments
SET comment_author_url =
REPLACE( comment_author_url, ‚http://www.stara.cz‘, ‚http://www.nova.cz‘);
\—

**Změna hesla**

/—code php
UPDATE ‚wp_users‘
SET ‚user_pass‘ = MD5(‚PASSWORD‘) WHERE ‚user_login‘ =’admin‘ LIMIT 1;
\—

**Přesun příspěvků z jednoho autora na jiného**

/—code php
UPDATE wp_posts
SET post_author=NEW_AUTHOR_ID
WHERE post_author=OLD_AUTHOR_ID;
\—

**Vymazání revizí a souvisejících metainformací**

/—code php
DELETE a,b,c FROM wp_posts a
WHERE a.post_type = ‚revision‘
LEFT JOIN wp_term_relationships b
ON (a.ID = b.object_id)
LEFT JOIN wp_postmeta c ON (a.ID = c.post_id);
\—

**Dávkové vymazání komentářů označených jako spam**

/—code php
DELETE from wp_comments WHERE comment_approved = ‚0‘;
\—

**Nalezení nevyužitých tagů**

/—code php
SELECT * From wp_terms wt
INNER JOIN wp_term_taxonomy wtt ON wt.term_id=wtt.term_id
WHERE wtt.taxonomy=’post_tag‘ AND wtt.count=0;
\—

Výpis e-mailů vašich komentátorů
/—code php
SELECT DISTINCT comment_author_email
FROM wp_comments;
\—

**Vymazání všech tagů u příspěvků najednou**
/—code php
DELETE a,b,c
FROM
database.prefix_terms AS a
LEFT JOIN database.prefix_term_taxonomy AS c ON a.term_id = c.term_id
LEFT JOIN database.prefix_term_relationships AS b
ON b.term_taxonomy_id = c.term_taxonomy_id
WHERE (c.taxonomy = ‚post_tag‘ AND c.count = 0);
\—

**Výpis všech nepotřebných *post meta* záznamů**

/—code php
SELECT * FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_id
WHERE wp.ID IS NULL;
\—

**Hromadné vypnutí komentářů u starších příspěvků**

/—code php
UPDATE wp_posts SET comment_status = ‚closed‘
WHERE post_date < ‚2009-01-01‘ AND post_status = ‚publish‘;
\—

**Deaktivace všech pluginů**

/—code php
UPDATE wp_options SET option_value = “ WHERE option_name = ‚active_plugins‘;
\—

**Zdroj:**

„http://www.catswhocode.com/blog/wordpress-10-life-saving-sql-queries“:http://www.catswhocode.com/blog/wordpress-10-life-saving-sql-queries

„http://www.onextrapixel.com/2010/01/30/13-useful-wordpress-sql-queries-you-wish-you-knew-earlier/“:http://www.onextrapixel.com/2010/01/30/13-useful-wordpress-sql-queries-you-wish-you-knew-earlier/

Automatické publikování na / z Twitteru

**Twitter Tools**
„http://wordpress.org/extend/plugins/twitter-tools/“:http://wordpress.org/extend/plugins/twitter-tools/
„http://www.sutlej.net/downloads/best-related-posts/“:http://www.sutlej.net/downloads/best-related-posts/

Integrates your blog and your Twitter account so you can post links to your latest posts on Twitter, post your most recent tweets on your blog sidebar, or turn your tweets into blog posts without extra effort.

First thing you need to do is download and activate this plugin. Once you have done that follow the steps below:

1. Create a Category where you would like to post all your automated posts. You can name this category Daily Digest, Twitter, or anything you like.
2. Go to the settings of Twitter Tools Plugin in your WP-Admin.
3. Enter Your Twitter Username and Password.
4. Enable the option to post when you tweet. If you do not want to create an individual post for each tweet, your solution is the next option.
5. Enable the option to create daily digest with all your tweets from that day and modify other settings such as title of that post and title. (You can also set this to weekly digests)
6. Select the category that you made in step 1, to post your tweets.

Once you have done the above steps, you have completed the setup and its ready to go.

**Display Tweets in the Sidebar**

But this plugin has a lot more features then just this. You can also display your recent tweets in the sidebar using this plugin. All you have to do is either use the dynamic widget or paste the following code in your sidebar.php or any other place that you want it displayed:

/—code php

\—

If you just want to show your last tweet then use this code:

/—code php

\—

Zdroj: „How to Auto Publish Your Twitter Tweets as WordPress Posts“:http://www.wpbeginner.com/plugins/how-to-auto-publish-your-twitter-tweets-as-wordpress-posts/

**Jak použít ve WordPressu Twitter API bez pluginu**
„http://www.problogdesign.com/wordpress/how-to-use-the-twitter-api-in-wordpress/“:http://www.problogdesign.com/wordpress/how-to-use-the-twitter-api-in-wordpress/

Zobrazení souvisejících příspěvků

This is a great little feature to have in your theme that saves the theme user using yet another plugin! It displays **related posts based on tags**, simply disappearing if there are no tags.

/—code php
ID);
if ($tags) {
echo ‚

Related Posts

‚;
$first_tag = $tags[0]->term_id;
$args=array(
‚tag__in‘ => array($first_tag),
‚post__not_in‘ => array($post->ID),
‚showposts’=>5,
‚caller_get_posts’=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>

Publikování příspěvků e-mailem

**Postie**
„http://wordpress.org/extend/plugins/postie/“:http://wordpress.org/extend/plugins/postie/
„http://blog.robfelty.com/plugins/postie/“:http://blog.robfelty.com/plugins/postie/
„fórum k pluginu“:http://forum.robfelty.com/forum/postie

Postie offers many advanced features for posting to your blog via e-mail, including the ability to **assign categories by name**, **tag**, include pictures and videos, and automatically strip off signatures.

**Category and tag handling**

* If you put a category name or ID in the subject with a : (or in [] or between – -) it will be used as the category for the post
* If you put the first part of a category name it will be posted in the first category that the system finds that matches – so if you put:

/—code php
Subject: Gen: New News
\—

the system will post that in General.

Using [] or — you can also post to multiple categories at once:

/—code php
Subject: [1] [Mo] [Br] bla bla bla
\—

or

/—code php
Subject: -1- -Mo- -Br- bla bla bla
\—

would post to General (Id 1), Moblog, and Brewing all at one time.

* You can add tags by adding a line in the body of the message like:

/—code php
tags: foo, bar
\—

or you can set a default tag to be applied if no tags are included.

„Post to your blog using email“:http://codex.wordpress.org/Post_to_your_blog_using_email (obecná informace z WP Codex).

Používání sessions

WordPress standardně nepodporuje sessions, což může být velmi potřebné např. při vytváření pluginu.

Stačí do functions.php (Vzhled > Upravit soubory) přidat:

/—code php
if (!session_id())
add_action(‚init‘, ‚session_start‘);
\—

*Alternativa*

Na začátek souboru wp-config.php (hned za úvodní

Jak modifikovat vzhled a délku anotace

Zdroj: „Improving WordPress’ the_excerpt() template tag“:http://www.aaronrussell.co.uk/blog/improving-wordpress-the_excerpt/

WordPress’ **the_excerpt()** template tag is used in most themes for browsing the archives and categories of a blog. Rather than displaying the full content of the post, the excerpt displays a short snippet of the content. Unless you manually enter in an excerpt when writing each post, WordPress grabs the first 55 words of the post and uses that as the excerpt.

So far so good, but there are problems with the way WordPress does this. These include:

* Word count – 55 words is a good number, but what if you want more or less?
* Formatting – WordPress strips out all HTML tags. This gets rid of images and links, but can also get rid of paragraph formatting, making the entire excerpt one long paragraph without any line breaks.
* JavaScript – Unfortunately JavaScript isn’t stripped out, which can result in some plugins’ messy script appearing in your excepts. Not only does this look rubbish, it can be a vulnerability too.

Stačí z **wp-includes/formatting.php** zkopírovat funkci **wp_trim_excerpt**, přejmenovat ji třeba na **better_excerpt** a vložit ji do **functions.php** (Vzhled > Upravit soubory)

/—code php
function better_excerpt($text) {
global $post;
if ( “ == $text ) {
$text = get_the_content(“);
$text = apply_filters(‚the_content‘, $text);
$text = str_replace(‚]]>‘, ‚]]>‘, $text);
$text = strip_tags($text); // můžu zakázat
$excerpt_length = 55; // můžu změnit délku
$words = explode(‚ ‚, $text, $excerpt_length + 1);
if (count($words)> $excerpt_length) {
array_pop($words);
array_push($words, ‚[…]‘);
$text = implode(‚ ‚, $words);
}
}
return $text;
}
\—

Na závěr je nutno na konec **functions.php** vložit ještě následující 2 řádky, které způsobí, že WP místo vestavěné funkce **wp_trim_excerpt** použije naši vylepšenou **better_excerpt**.

/—code php
remove_filter(‚get_the_excerpt‘, ‚wp_trim_excerpt‘);
add_filter(‚get_the_excerpt‘, ‚better_excerpt‘);
\—

Implementováno na tomto webu.

**Customizing the Read More**
„http://codex.wordpress.org/Customizing_the_Read_More“:http://codex.wordpress.org/Customizing_the_Read_More

změna textu odkazu:

/—code php

\—

„Useful ways to customize and format the WordPress more tag »“:http://digwp.com/2010/01/wordpress-more-tag-tricks/

**Advanced Excerpt Plugin**
„http://wordpress.org/extend/plugins/advanced-excerpt/“:http://wordpress.org/extend/plugins/advanced-excerpt/

This plugin adds several improvements to WordPress‘ default way of creating excerpts.

– Keeps HTML markup in the excerpt (and you get to choose which tags are included)
– Trims the excerpt to a given length using either character count or word count
– Only the ‚real‘ text is counted (HTML is ignored but kept)
– Customizes the excerpt length and the ellipsis character that are used
– Completes the last word or sentence in an excerpt (no weird cuts)
– Adds a read-more link to the text
– Ignores custom excerpts and use the generated one instead
– Theme developers can use the_advanced_excerpt() for even more control (see the „FAQ“:http://wordpress.org/extend/plugins/advanced-excerpt/faq/)

Jak nakopnout WordPress správným směrem

Tento návod je určen spíše pro začátečníky, kteří si právě nainstalovali WordPress. Je pravděpodobné, že pokročilí uživatelé budou znát většinu informací, které zde uvádím. Nicméně i těm doporučuji přečíst si článek – už jenom kvůli ověření a osvěžení nabytých vědomostí.
Čistě nainstalovaný redakční systém WordPress je prázdný, postrádá celou řadu funkcí a potřebuje změnit […]