Drobečková navigace bez použití pluginu

Do functions.php vložíme:

/—code php
function the_breadcrumb() {
echo ‚

    ‚;
    if (!is_home()) {
    echo ‚

  • ‚;
    echo ‚Home‘;
    echo „
  • „;
    if (is_category() || is_single()) {
    echo ‚

  • ‚;
    the_category(‚
  • ‚);
    if (is_single()) {
    echo „
  • „;
    the_title();
    echo ‚
  • ‚;
    }
    } elseif (is_page()) {
    echo ‚

  • ‚;
    echo the_title();
    echo ‚
  • ‚;
    }
    }
    elseif (is_tag()) {single_tag_title();}
    elseif (is_day()) {echo“

  • Archive for „; the_time(‚F jS, Y‘); echo‘
  • ‚;}
    elseif (is_month()) {echo“

  • Archive for „; the_time(‚F, Y‘); echo‘
  • ‚;}
    elseif (is_year()) {echo“

  • Archive for „; the_time(‚Y‘); echo‘
  • ‚;}
    elseif (is_author()) {echo“

  • Author Archive“; echo‘
  • ‚;}
    elseif (isset($_GET[‚paged‘]) && !empty($_GET[‚paged‘]))
    {echo „

  • Blog Archives“; echo‘
  • ‚;}
    elseif (is_search()) {echo“

  • Search Results“; echo‘
  • ‚;}
    echo ‚

‚;
}
\—

V šabloně funkci zavoláme:

/—code php
the_breadcrumb();
\—

„Zdroj »“:http://wp-snippets.com/breadcrumbs-without-plugin/

Přidání custom posts do výsledků vyhledávání

Do functions.php přidáme

/—code php
add_filter( ‚pre_get_posts‘, ‚tgm_cpt_search‘ );
/**
* This function modifies the main WordPress query to include an array of post types instead of the default ‚post‘ post type.
*
* @param mixed $query The original query
* @return $query The amended query
*/
function tgm_cpt_search( $query ) {
if ( $query->is_search )
$query->set( ‚post_type‘, array( ‚post‘, ‚movies‘, ‚products‘, ‚portfolio‘ ) );
return $query;
};
\—

Automatický náhledový obrázek

**Auto Post Thumbnail**
„http://wordpress.org/plugins/auto-post-thumbnail/“:http://wordpress.org/plugins/auto-post-thumbnail/

Automatically generate the Post Thumbnail (Featured Thumbnail) from the first image in post or any custom post type only if Post Thumbnail is not set.

If the post thumbnail is already present, the plugin will do nothing. If you don’t want a post thumbnail for some post with images, just add a custom field skip_post_thumb to the post and the plugin will restrain itself from generating post thumbnail. The plugin also provides a Batch Processing capability to generate post thumbnails for already published posts.

**Další pluginy**
„http://beginnersbook.com/2013/09/set-default-thumbnail-featured-fallback-image-wordpress-automatically/“:http://beginnersbook.com/2013/09/set-default-thumbnail-featured-fallback-image-wordpress-automatically/
„http://wpfreesetup.com/fix-featured-image-issues-wordpress-plugins/“:http://wpfreesetup.com/fix-featured-image-issues-wordpress-plugins/

*nebo pomocí funkcí:*

/—code php
ID);
if (!$already_has_thumb) {
$attached_image = get_children( „post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1“ );
if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
set_post_thumbnail($post->ID, $attachment_id);
}
}
}
}
add_action(‚the_post‘, ‚autoset_featured‘);
add_action(‚save_post‘, ‚autoset_featured‘);
add_action(‚draft_to_publish‘, ‚autoset_featured‘);
add_action(‚new_to_publish‘, ‚autoset_featured‘);
add_action(‚pending_to_publish‘, ‚autoset_featured‘);
add_action(‚future_to_publish‘, ‚autoset_featured‘);
?>
\—

*alternativně*

/—code php
function set_first_as_featured($attachment_ID){
$post_ID = get_post($attachment_ID)->post_parent;
if(!has_post_thumbnail($post_ID)){
set_post_thumbnail($post_ID, $attachment_ID);
}
}
add_action(‚add_attachment‘, ‚set_first_as_featured‘);
add_action(‚edit_attachment‘, ‚set_first_as_featured‘);
\—

On every upload / edit attachment, function checks if the post already has featured image. If it has not, image in question is set as featured. Every next picture will be ignored (since post already has featured image).

*případně*

/—code php
wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), ‚thumbnail‘ )[0];
\—

„Get The First Image From a Post »“:http://css-tricks.com/snippets/wordpress/get-the-first-image-from-a-post/

Vytváření vlastních sidebarů a oblastí pro widgety

**Custom Sidebars**
„http://wordpress.org/plugins/custom-sidebars/“:http://wordpress.org/plugins/custom-sidebars/

Allows you to create all the widgetized areas you need, your own custom sidebars, configure them adding widgets, and replace the default sidebars on the posts or pages you want in just few clicks.

*Alternativy*

**Per Page Sidebars**
„http://wordpress.org/plugins/per-page-sidebars/“:http://wordpress.org/plugins/per-page-sidebars/

Allows the creation and display of custom sidebars for any page (or post) on your site. On each page, you can choose which of your current theme’s sidebars will be replaced. The replacement works for all descendants of a replaced page.

**Svépomocí**

V šabloně single.php a/nebo page.php najdeme kód:

/—code php
get_sidebar();
\—

a nahradíme jej tímto:

/—code php
$sidebar = get_post_meta($post->ID, „sidebar“, true);
get_sidebar($sidebar);
\—

V příspěvku nebo stránce, kde chceme zobrazit specifický sidebar pak přidáme uživatelské pole *Sidebar* a vložíme do něj jméno specifického sidebaru, např *xyz*. Soubor *sidebar-xyz.php* musí samozřejmě existovat. Vytvoříme ho zkopírováním originálního souboru *sidebar.php* (a případně podle potřeby upravíme).

Soubor sidebar-xyz upravíme následovně:

/—code php

\—

Pro vytvoření vlastní oblasti pro widgety do functions.php přidáme kód:

/—code php
if ( function_exists(‚register_sidebar‘) ) {
register_sidebar(array(
‚name‘ => ‚xyz‘,
‚id‘ => ‚xyz-sidebar‘,
‚description‘ => ‚Uživatelský sidebar pro stránku xyz“‚,
‚before_widget‘ => ‚

  • ‚,
    ‚after_widget‘ => ‚
  • ‚,
    ‚before_title‘ => ‚

    ‚,
    ‚after_title‘ => ‚

    ‚,
    // udaje v after a before třeba upravit v souladu s použitým tématem
    ));
    }\—

    Vkládání map Seznamu (mapy.cz)

    Pro vkládání „seznamáckých map“:http://www.mapy.cz/ do WordPressu lze využít „bohatě zdokumentované API“:http://api4.mapy.cz/view?page=examples.

    1) v header.php si natáhneme loader
    /—code php



    \—

    2) do kódu stránky (v html editoru) vložíme do stránky kód pro zobrazení mapy
    /—code php



    \—

    3) no a mapa pak vypadá třeba „takhle“:http://metzova.cz/kontakt/.

    Vychytal to „Bigdrobek“:http://wordpress.bigdrobek.com/2013/05/20/vlozeni-interaktivni-mapy-cz-do-wordpressu/.

    Uživatelská úprava standardních WP šablon TwentyXX

    **Styles**
    „http://wordpress.org/plugins/styles/“:http://wordpress.org/plugins/styles/

    Styles gives you creative control in one consistent interface – the WordPress theme customizer.
    Free for default WordPress Themes (TwentyTen, TwentyEleven, TwentyTwelve, TwentyThirteen).

    Download TwentyXX template customizer „here »“:http://stylesplugin.com/

    „Modify Header, footer, font, sitebar, titles using CSS »“:http://allaboutbasic.com/2012/09/05/wordpress-com-theme-twenty-twelve-theme-modification-modify-headerfooterfontsitebartitles-using-css/

    Nastavení automatické aktualizace

    WordPress 3.7 introduced automatic upgrades. Maintenance and security updates are applied in the background when a patch becomes available and someone visits your site. By default, the process only applies when updating minor versions — such as 3.7.0 to 3.7.1 — and takes no longer than 25 seconds.

    Automated updates are especially risky if you:

    – use a large number of dubious plug-ins or complex third-party themes
    – want to control and manage updates yourself, or
    – have an especially nervous disposition!

    How to enable major release updates

    /—code php
    define(‚WP_AUTO_UPDATE_CORE‘, true);
    \—

    To stop the autoupdates of the WordPress core

    /—code php
    define( ‚WP_AUTO_UPDATE_CORE‘, false );
    \—

    How to enable plugins updates

    /—code php
    add_filter( ‚auto_update_plugin‘, ‚__return_true‘ );
    \—

    How to enable themes updates

    /—code php
    add_filter( ‚auto_update_theme‘, ‚__return_true‘ );
    \—

    Then enable the plugins updates

    /—code php
    add_filter( ‚auto_update_plugin‘, ‚__return_true‘ );
    \—

    How to completely disable the WordPress auto updates

    /—code php
    define( ‚AUTOMATIC_UPDATER_DISABLED‘, true );
    \—

    „WordPress Auto Updates How To »“:http://www.siteground.com/tutorials/wordpress/auto-update.htm

    „How to Configure Automatic Updates in WordPress »“:http://www.sitepoint.com/configure-automatic-updates-wordpress/

    „How to exclude plugins from getting automatically updated »“:http://wordpress.stackexchange.com/questions/131394/how-do-i-exclude-plugins-from-getting-automatically-updated

    Jak skrýt vybrané stránky či příspěvky v administraci uživatelům

    /—code php
    function jp_exclude_pages_from_admin($query) {

    if ( ! is_admin() )
    return $query;

    global $pagenow, $post_type;

    if ( !current_user_can( ‚administrator‘ ) && is_admin() && $pagenow == ‚edit.php‘ && $post_type == ‚page‘ ) {
    $query->query_vars[‚post__not_in‘] = array( ’10‘, ‚167‘, ‚205‘ ); // ID stránek, které se mají skrýt „neadminům“
    }
    }

    add_filter( ‚parse_query‘, ‚jp_exclude_pages_from_admin‘ );
    \—

    „Zdroj »“:http://www.johnparris.com/how-to-hide-pages-in-the-wordpress-admin/

    Nastavení defaultní hodnoty pro tagy a uživatelské taxonomie

    Příspěvek se automaticky zařadí do výchozí rubriky, i když ji nepřiřadíme. To ale neplatí pro štítky (tagy) a uživatelské taxonomie.
    Jak to nastavit v tomto případě:

    /—code php
    function mfields_set_default_object_terms( $post_id, $post ) {
    if ( ‚publish‘ === $post->post_status ) {
    $defaults = array(
    ‚post_tag‘ => array( ‚štítek 1‘, ‚štítek 2‘ ),
    ‚moje taxonomue‘ => array( ‚Defaultní hodnota‘ ),
    );
    $taxonomies = get_object_taxonomies( $post->post_type );
    foreach ( (array) $taxonomies as $taxonomy ) {
    $terms = wp_get_post_terms( $post_id, $taxonomy );
    if ( empty( $terms ) && array_key_exists( $taxonomy, $defaults ) ) {
    wp_set_object_terms( $post_id, $defaults[$taxonomy], $taxonomy );
    }
    }
    }
    }
    add_action( ‚save_post‘, ‚mfields_set_default_object_terms‘, 100, 2 );
    \—

    „http://wordpress.mfields.org/2010/set-default-terms-for-your-custom-taxonomies-in-wordpress-3-0/“:http://wordpress.mfields.org/2010/set-default-terms-for-your-custom-taxonomies-in-wordpress-3-0/