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

Do functions.php přidáme


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/

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://wpfreesetup.com/fix-featured-image-issues-wordpress-plugins/

*nebo pomocí funkcí:*


<?php
function autoset_featured() {
global $post;
$already_has_thumb = has_post_thumbnail($post->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ě*


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ě*


wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'thumbnail' )[0];

Get The First Image From a Post »

Debug a reset cronu ve WordPressu

Po aktualizaci pluginu Post Indexer mě zřejmě přestal fungovat cron –  indexace byla naplánovaná ale nespustila se. Tak jsem na fóru wpmudev jsem dostal pár rad jak debugovat cron a jak cron resetovat. Zde je stručný návod jak na to. Debugování cronu K tomu jsou zapotřebí nahrát dva pluginy v tomto pořadí: Debug bar Debug […]

Export webu jako statické HTML stránky

WP Static HTML Output
http://wordpress.org/plugins/static-html-output-plugin/

This plugin produces a static HTML version of your wordpress install, incredibly useful for anyone who would like the publishing power of wordpress but whose webhost doesn’t allow dynamic PHP driven sites – such as MobileMe. You can run your development site on a different domain or offline, and the plugin will change all relevant URLs when you publish your site. It’s a simple but powerful plugin, and after hitting the publish button, the plugin will output a ZIP file of your entire site, ready to upload straight to it’s new home.

Flexibilní widget pro zobrazení příspěvků

Flexible Posts Widget
http://wordpress.org/plugins/flexible-posts-widget/

Flexible Posts Widget (FPW) is more than just a simple alternative to the default Recent Posts widget. With many per-instance options it is highly customizable and allows advanced users to display the resulting posts virtually any way imaginable.
Features & options

– Customizable widget title
– Get posts by post type(s) and/or taxonomy & term(s) or directly by a list of post IDs.
– Control the number of posts displayed and the number of posts to offset.
– Option to display the post feature image.
– Select the post feature image size to display from existing image sizes: thumbnail, medium, large, post-thumbnail or any size defined by the current theme.
– Order posts by: date, ID, title, menu order, random, Post ID Order; and sort posts: ascending or descending.
– Each widget’s output can be customized by user-defined templates added to the current theme folder.

Customization »

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

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/

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:


get_sidebar();

a nahradíme jej tímto:


$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ě:


<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("xyz-sidebar") ) : ?><?php endif; ?>

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


if ( function_exists('register_sidebar') ) {
	register_sidebar(array(
	'name' => 'xyz',
	'id' => 'xyz-sidebar',
	'description' => 'Uživatelský sidebar pro stránku xyz"',
	'before_widget' => '<div style="height: 280px"></div><li id="%1$s" class="widget %2$s">',
	'after_widget' => '</li>',
	'before_title' => '<h2 class="widgettitle">',
	'after_title' => '</h2>',
	// udaje v after a before třeba upravit v souladu s použitým tématem
	));
}

WordPress 3.9 „Smith“

Po přibližně 4 měsících dnes vychází nový WordPress 3.9 a přináší mnoho drobných (ale příjemných) změn pro uživatele. Nečeká nás tedy žádná radikální změna jako u minulého WordPressu 3.8, pouze si na některých místech možná všimnete, že něco funguje trochu lépe a snadněji (a je to vlastně docela šikovně navrženo). Podobné aktualizace mají uživatelé obvykle […]