Kdo má dnes svátek?

Prokažte svým návštěvníkům službu a ukažte jim, do jakého vlastně vstupují dne. Na webovém podnose jim naservírujte co je za den v týdnu, jaký je datum a kdo do má právě dnes svátek. Script, který vám poskytnu, neslouží jen wordpressu, ale použít ho můžete prakticky na jakékoliv webové stránky. Já sám ho například využil při […]

Vytvoření a úpravy šablony založené na Twenty Eleven

„Vytvoření odvozené (child) šablony »“:http://wp.tutsplus.com/tutorials/theme-development/creating-a-simple-child-theme-using-twenty-eleven/

Změna stylopisu – barva, písmo, velikost nadpisů, popisky, komentářů, postranní lišty apod.

„[* http://allaboutbasic.files.wordpress.com/2011/06/twenty-eleven1.png?w=630&h=376 *]“:http://allaboutbasic.com/2011/06/15/wordpress-com-theme-twenty-eleven-css-style-sheet-modification-change-site-titledescriptionpost-titlecommentsmenussidebar-and-more/

„Více zde »“:http://allaboutbasic.com/2011/06/15/wordpress-com-theme-twenty-eleven-css-style-sheet-modification-change-site-titledescriptionpost-titlecommentsmenussidebar-and-more/

„Digging Into Twenty Eleven »“:http://theme.fm/2011/07/theme-review-digging-into-twenty-eleven-597/

„Replace/Remove Default Header Image Twenty Eleven Theme »“:http://wpti.ps/functions/replace-remove-header-image-twenty-eleven-theme/

„Sidebar on Single Posts and Pages »“:http://www.transformationpowertools.com/wordpress/twenty-eleven-sidebar-on-single-posts-and-pages

„Adding a Narrow Sidebar on Each Side of TwentyEleven Single Post View »“:http://voodoopress.com/2011/07/adding-a-narrow-sidebar-on-each-side-of-twentyeleven-single-post-view/

„Plugin pro různé změny layoutu a designu Twenty Eleven »“:http://wordpress.org/extend/plugins/twenty-eleven-theme-extensions/
„Twenty Eleven Theme Extensions Plugin »“:http://wordpress.org/extend/plugins/twenty-eleven-theme-extensions/

„Plugin pro 3-sloupcové varianty Twenty Eleven »“:http://zeaks.org/other-stuff/three-column-twenty-eleven-update/

„Jak přidat logo do Twenty Eleven »“:http://zeaks.org/code-snippets/how-to-add-a-logo-to-twenty-eleven-theme/

„Logo a nadpis v Twenty Eleven »“:http://www.transformationpowertools.com/wordpress/logo-and-site-title-twenty-eleven

„How to Override Theme Functions »“:http://venutip.com/content/right-way-override-theme-functions

1. Copy (in full) the function you want to override from the parent theme.
2. Paste it into functions.php in the root of your child theme’s folder. If functions.php doesn’t exist, create it.
3. Rename the function from parent_theme_function to child_theme_function.
4. Deactivate the parent function.
5. Activate the child function.

/—code php
// Removes thematic_blogtitle from the thematic_header phase
function remove_thematic_actions() {
remove_action(‚thematic_header‘,’thematic_blogtitle‘,3);
}
// Call ‚remove_thematic_actions‘ during WP initialization
add_action(‚init‘,’remove_thematic_actions‘);

// Add our custom function to the ‚thematic_header‘ phase
add_action(‚thematic_header‘,’fancy_theme_blogtitle‘, 3);
\—

Modifikace odkazu „více“

**Úprava textu odkazu**

``

**Doplnění obrázku**

/—code php
.moretext {
width: 100px;
height: 45px;
background:url(/images/ilustrace.gif) no-repeat right middle;
padding: 10px 50px 15px 5px}
\—

**Skok na začátek textu**

Standardně odkaz vede na pokračování textu, nacházející se za `` odkazem, toto chování lze změnit umístěním následujícího filtru do *functions.php*

/—code php
function remove_more_jump_link($link) {
$offset = strpos($link, ‚#more-‚);
if ($offset) {
$end = strpos($link, ‚“‚,$offset);
}
if ($end) {
$link = substr_replace($link, “, $offset, $end-$offset);
}
return $link;
}
add_filter(‚the_content_more_link‘, ‚remove_more_jump_link‘);
\—

Lze použít i plugin:

**More Link Modifier**
„http://wordpress.org/extend/plugins/more-link-modifier/“:http://wordpress.org/extend/plugins/more-link-modifier/

A simple plugin that allows you to modify the link that is displayed when you use the Pokračovat ve čtení „Modifikace odkazu „více““

Série pluginů pro spolupráci s Twitterem

**Simple Twitter Connect**
„http://wordpress.org/extend/plugins/simple-twitter-connect/“:http://wordpress.org/extend/plugins/simple-twitter-connect/
„http://ottopress.com/wordpress-plugins/simple-twitter-connect/“:http://ottopress.com/wordpress-plugins/simple-twitter-connect/

Simple Twitter Connect is a series of plugins that let you add any sort of Twitter functionality you like to a WordPress blog. This lets you have an integrated site without a lot of coding, and still letting you customize it exactly the way you’d like.

First, you activate and set up the base plugin, which makes your site have basic Twitter functionality. Then, each of the add-on plugins will let you add small pieces of specific Twitter-related functionality, one by one.

Unlike other Twitter plugins for WordPress, this one helps you create your own Twitter application and identity, so your tweets from here show up as being from Your Blog, not from some plugin system. You’ll never see „posted by Simple Twitter Connect“ in your tweet stream, you’ll see „posted by Your Blog Name“. Great way to drive traffic back to your own site and to see your own Twitter userbase.

Current add-ons

– Login using Twitter
– Comment using Twitter credentials
– Users can auto-tweet their comments
– Tweet button (official one from twitter)
– Tweetmeme button
– Auto-tweet new posts to an account
– Manual Tweetbox after Publish
– Full @anywhere support
– Auto-link all twitter names on the site (with optional hovercards)
– Dashboard Twitter Widget

**Jak přidat automaticky hashtagy**

A standard tweet containing a prefix (such as “New blog post:”), post title and a link to that post is generated automatically by the plugin.To include post categories and tags as hashtags in order to add additional metadata along with the post title add this snippet to your theme’s functions.php:

/—code php
add_filter(‚stc_publish_text‘, ‚add_taxonomies_to_tweets‘, 10, 2);

function add_taxonomies_to_tweets($output, $id) {
if ($cats = get_the_category($id))
foreach ($cats as $c => $cat)
$output = add_taxonomy_hashtag($output, $cat->cat_name);

if ($tags = get_the_tags($id))
foreach ($tags as $t => $tag)
$output = add_taxonomy_hashtag($output, $tag->name);

return $output;
}

function add_taxonomy_hashtag($tweet, $tax) {
if (stripos($tax, ‚ ‚)) // Remove whitespace
$tax = str_replace(‚ ‚, “, $tax);

if (strlen($tweet) + 1 > 140) { // Check if the new tweet is not too long
return $tweet;
} elseif (stripos($tweet, $tax)) { // Replace an existing word with a tag
return str_replace($tax, ‚#‘ . $tax, $tweet);
} elseif (strlen($tweet) + strlen($tax) + 1 < 140) { // or simply append it return $tweet . ' #' . $tax; } return $tweet; } \---

Trvalé odkazy v lokální instalaci XAMP

V lokální instalaci Apache obvykle defaultně nefunguje *mod_rewrite*, tj. obsah *.htaccess* je ignorován, a nastavíte-li si pak user-friendly odkazy např. pomocí /%postname%/, vrací se stránky/příspěvky jako nenalezené s kódem 404.

Napravit to lze změnou v souboru *httpd.conf*, který se nalézá v lokálním adresáři XAMPu *\apache\conf*.

Řádek

/—code php
#LoadModule rewrite_module modules/mod_rewrite.so
\—

stačí odkomentovat (vymazat znak *#*).

Dále je třeba zkonreolovat, zda v části

/—code php
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be „All“, „None“, or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
\—

není zakomentována direktiva *AllowOverride All* (a je v tomto znění).

Po uložení *httpd.conf* a restartu lokálního Apache již WordPress odkazy přepisuje.

Problém s přesměrováním na jinou stránku

Potřebujeme-li v šabloně/pluginu/funkci přesměrovat výstup na jinou stránku, pomocí funkce „wp_redirect“:http://codex.wordpress.org/Function_Reference/wp_redirect nebo přímo přes „header(‚Location: http://www.example.com/‘)“:http://php.net/manual/en/function.header.php, může nastat problém, signalizovaný hláškou **Cannot modify header information – headers already sent by**.

Lze to vyřešit několika způsoby:

1) v php funkcí „ob_start“:http://php.net/manual/en/function.ob-start.php; zde „vysvětlení“:http://brian.moonspot.net/php-ob-start-headers

/—code php
// hned na začátek za úvodní umístíme
ob_end_flush();
?>
\—

2) javascriptem přes „window.location“:http://www.jakpsatweb.cz/javascript/objekt-window.html#location
/—code php



\—

3) pomocí „meta-refresh“:http://www.jakpsatweb.cz/presmerovani.html#meta
/—code php
„; ?>
\—

Menu s ikonami

A simple way to customize our WordPress menu, without losing its wonderful admin options. We will be doing:

– Home link in our wp_nav_menu that always gets current blog url
– Customize each menu item as you want
– Put pretty icons in our menu
– Active item highlight

„http://www.1stwebdesigner.com/wordpress/wordpress-wp-nav-menu-tutorial/“:http://www.1stwebdesigner.com/wordpress/wordpress-wp-nav-menu-tutorial/

[* http://www.1stwebdesigner.com/wp-content/uploads/2011/05/preview_large_wp_nav_tut.jpg *]

Praktické útržky kódu

**Title of the site**
/—code php

\—

**Basic URL of the site**
/—code php

\—
/—code php

\—

**Exact URL for the site (incl. path)**
/—code php

\—

**Name of the site**
/—code php

\—

**Site’s description**
/—code php

\—

**The style.css style’s location**
/—code php

\—

**The style.css style’s directory**
/—code php

\—

**Location for the site’s theme files**
/—code php

\—

**Title of the specific post or page**
/—code php


\—

**Url of a specific post or page**
/—code php

\—

**Category of a specific post or page**
/—code php

\—

**Author of a specific post or page**
/—code php

\—

**ID of a specific post or page**
/—code php

\—

**Link to edit a specific post or page**
/—code php

\—

**RSS2 URL for the site**
/—code php

\—

**Content of the posts**
/—code php

\—

**Header.php file’s content**
/—code php

\—

**Sidebar.php file’s content**
/—code php

\—

**Footer.php file’s content**
/—code php

\—

**The date in ’08-18-07′ format**
/—code php

\—

**Link for the comments on the post**
/—code php

\—

**Links from the blogroll**
/—code php

\—

**Comment.php file’s content**
/—code php

\—

**List of pages **
/—code php

\—

**List of categories**
/—code php

\—

**Url to the next post**
/—code php

\—

**Url to the previous post**
/—code php

\—

**The built-in calendar**
/—code php

\—

**List of archives for the site**
/—code php

\—

**Next and previous post link**
/—code php

\—

**Include any file**
/—code php

\—

**Value for search form**
/—code php

\—

**Prints out message**
/—code php

\—

**Displays the register link**
/—code php

\—

**Displays the login/logout link**
/—code php

\—

**Divides the content into pages**
/—code php

\—

**Cuts off the content and adds a link to the rest of the content**
/—code php
Pokračovat ve čtení „Praktické útržky kódu“

Práce s databází pomocí třídy $wpdb

**Načtení** ID a nadpisů čtyř nejnovějších příspěvků a jejich seřazení podle počtu komentářů (sestupně):

/—code php
get_results(„SELECT ID, post_title FROM $wpdb->posts WHERE post_status = ‚publish‘
AND post_type=’post‘ ORDER BY comment_count DESC LIMIT 0,4“)

// Echo the title of the first scheduled post
echo $posts[0]->post_title;
?>
\—

Objekt $results obsahuje pole s výsledky.

**get_row** načte pouze jediný záznam z tabulky:

/—code php
get_row(„SELECT ID, post_title FROM wp_posts WHERE post_status = ‚publish‘
AND post_type=’post‘ ORDER BY comment_count DESC LIMIT 0,1“)

// Echo the title of the most commented post
echo $posts->post_title;
?>
\—

**get_col** načte celý sloupec:

/—code php
get_col(„SELECT ID FROM wp_posts WHERE post_status = ‚publish‘
AND post_type=’post‘ ORDER BY comment_count DESC LIMIT 0,10“)

// Echo the ID of the 4th most commented post
echo $posts[3]->ID;
?>
\—

**get_var** načte jedinou hodnotu:

/—code php
get_var(„SELECT user_email FROM wp_users WHERE user_login = ‚danielpataki‘ „)

// Echo the user’s email address
echo $email;
?>
\—

**Vkládání do databáze**

/—code php
insert( $table, $data, $format);
$wpdb->insert($wpdb->usermeta, array(„user_id“ => 1, „meta_key“ => „awesome_factor“, „meta_value“ => 10), array(„%d“, %s“, „%d“));

// odpovídá:
// INSERT INTO wp_usermeta (user_id, meta_key, meta_value) VALUES (1, „awesome_factor“, 10);
?>
\—

**Updatování databáze:**

/—code php
// $wpdb->update($table, $data, $where, $format = null, $where_format = null);

// $where parameter – can be an array in the form of column-value pairs:
$wpdb->update( $wpdb->posts, array(„post_title“ => „Modified Post Title“), array(„ID“ => 5), array(„%s“), array(„%d“) );
\—

„Zdroj »“:http://wp.smashingmagazine.com/2011/09/21/interacting-with-the-wordpress-database/