Sunt cateva coduri php pentru mine indispensabile intr-o tema wordpress. As vrea sa le arat in acest post si cine stie daca nu cumva ajuta pe cineva.
1.Adauga Post thumbnail daca tema nu are.
In functions.php avem acest cod.
Add image size unde se poate seta marimea imagini. Acum codul de afisare in tema care poate fi in loop.php, content.php depinde de tema.
2. Adauga codul pentru stabilirea background-ului. In functions.php avem acest cod.
3. Foloseste o functie pentru a arata doar o parte din continutul articolului restul dupa ce intra in el.
Cautati codul the_content in tema (loop.php, content.php) si inlocuiti cu:
[codesyntax lang=”php” container=”div”]
<?php the_excerpt(); ?>
[/codesyntax]
Si acest cod in functions.php ca sa nu mai arate acele doua acolde patrate la sfarsitul articolului taiat.
[codesyntax lang=”php” container=”div”]
function custom_excerpt_more( $more ) { return '...'; } add_filter( 'excerpt_more', 'custom_excerpt_more' );
[/codesyntax]
Prin urmatorul cod se poate stabili cate cuvinte sa apara in functia the-excerpt. Unde codul indica return 30 se poate pune orice numar.
[codesyntax lang=”php” container=”div”]
function custom_excerpt_length( $length ) { return 30; } add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
[/codesyntax]
Tot legat de acest cod avem si posibilitatea sa apara dupa el un cuvant care transmite mesajul de citire a articolului in intregime.
[codesyntax lang=”php”]
function new_excerpt_more($more) { global $post; return '<a class="moretag" href="'. get_permalink($post->ID) . '"> Citeste tot »</a>'; } add_filter('excerpt_more', 'new_excerpt_more');
[/codesyntax]
4. Stabiliti in functie de o categorie anume ce footer sa incarce. Avem footer.php cel normal pentru tema si cel special pentru categoria respectiva. Faceti un footer-tutoriale.php si complectati cu orice coduri doriti.
[codesyntax lang=”php” container=”div”]
<?php if (is_category('tutoriale')) { get_footer('tutoriale'); } else { get_footer(); } ?>
[/codesyntax]
5. Ascunde diferite chesti nefolositoare din tema cu acest cod in functions.php
[codesyntax lang=”php” container=”div”]
function css_new() { if (is_home()) { ?> <style type="text/css"> AICI PUI DIVUL SAU ORICE CARE VREI SA DISPARE DIN TEMA { display: none; } </style> <?php } } add_action('wp_head', 'css_new');
[/codesyntax]
6. Inlocuieste ‘Howdy’ cu ‘Bine ai venit’ sau orice alt mesaj in bara de wordpress dreapta sus. Codul care se pune in funtions.php
[codesyntax lang=”php” container=”div”]
add_filter('gettext', 'change_howdy', 10, 3); function change_howdy($translated, $text, $domain) { if (!is_admin() || 'default' != $domain) return $translated; if (false !== strpos($translated, 'Howdy')) return str_replace('Howdy', 'Bine ai venit', $translated); return $translated; }
[/codesyntax]
7. Scapa de ‘www’ pentru a scurta in linkuri. Codul se pune in functions.php
[codesyntax lang=”php” container=”div”]
add_filter('get_shortlink','sjc_alter_shortlink'); function sjc_alter_shortlink($shortlink) { $shortlink = str_replace('www.','',$shortlink); return $shortlink; }
[/codesyntax]
8. Adauga next-page in WYSIYG-editor la scrierea unui articol. Codul pentru functions.php
[codesyntax lang=”php” container=”div”]
add_filter('mce_buttons','wysiwyg_editor'); function wysiwyg_editor($mce_buttons) { $pos = array_search('wp_more',$mce_buttons,true); if ($pos !== false) { $tmp_buttons = array_slice($mce_buttons, 0, $pos+1); $tmp_buttons[] = 'wp_page'; $mce_buttons = array_merge($tmp_buttons, array_slice($mce_buttons, $pos+1)); } return $mce_buttons; }
[/codesyntax]
9. Adauga vizibilitatea pozei pentru thumbnail la articole prin acest cod in functions.php
[codesyntax lang=”php” container=”div”]
if ( !function_exists('AddThumbColumn') && function_exists('add_theme_support') ) { // for post and page add_theme_support('post-thumbnails', array( 'post', 'page' ) ); function AddThumbColumn($cols) { $cols['thumbnail'] = __('Thumbnail'); return $cols; } function AddThumbValue($column_name, $post_id) { $width = (int) 60; $height = (int) 60; if ( 'thumbnail' == $column_name ) { // thumbnail of WP 2.9 $thumbnail_id = get_post_meta( $post_id, '_thumbnail_id', true ); // image from gallery $attachments = get_children( array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image') ); if ($thumbnail_id) $thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true ); elseif ($attachments) { foreach ( $attachments as $attachment_id => $attachment ) { $thumb = wp_get_attachment_image( $attachment_id, array($width, $height), true ); } } if ( isset($thumb) && $thumb ) { echo $thumb; } else { echo __('None'); } } } // for posts add_filter( 'manage_posts_columns', 'AddThumbColumn' ); add_action( 'manage_posts_custom_column', 'AddThumbValue', 10, 2 ); // for pages add_filter( 'manage_pages_columns', 'AddThumbColumn' ); add_action( 'manage_pages_custom_column', 'AddThumbValue', 10, 2 ); }
[/codesyntax]
10. Schimba numele ‘Post’ in ‘Articole’ in dashbord doar daca este in limba engleza. Codul pentru functions.php
[codesyntax lang=”php” container=”div”]
//change the menu items label function change_post_menu_label() { global $menu; global $submenu; $menu[5][0] = 'Articole'; $submenu['edit.php'][5][0] = 'Articole'; $submenu['edit.php'][10][0] = 'Adauga Articole'; $submenu['edit.php'][15][0] = 'Articole Category'; // 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 = 'Articole'; $labels->singular_name = 'Articole'; $labels->add_new = 'Adauga Articol'; $labels->add_new_item = 'Adauga Articol'; $labels->edit_item = 'Edit Articole'; $labels->new_item = 'Articol'; $labels->view_item = 'View Articole'; $labels->search_items = 'Search Articole'; $labels->not_found = 'Niciun articol gasit'; $labels->not_found_in_trash = 'Nu sau gasit articole in gunoi'; } add_action( 'init', 'change_post_object_label' ); add_action( 'admin_menu', 'change_post_menu_label' );
[/codesyntax]
Al doilea cod e mai simplu. Din ‘post’ in ‘article’.
[codesyntax lang=”php” container=”div”]
// hook the translation filters add_filter( 'gettext', 'change_post_to_article' ); add_filter( 'ngettext', 'change_post_to_article' ); function change_post_to_article( $translated ) { $translated = str_ireplace( 'Post', 'Article', $translated ); // ireplace is PHP5 only return $translated; }
[/codesyntax]
11. Adauga informatii in footer.php despre tema plus altele.
[codesyntax lang=”php” container=”div”]
add_filter( 'admin_footer_text', 'my_admin_footer_text' ); function my_admin_footer_text( $default_text ) { return '<span id="footer-thankyou">Website managed by <a href="http://www.get10up.com">10up</a><span> | Powered by <a href="http://www.wordpress.org">WordPress</a>'; }
[/codesyntax]
Interesant, daca ma voi apuca de editat teme wordpress voi tine cont de aceste coduri oferite de tine.
bun, bun 🙂
utile
de cand ai comentat tu au mai aparut cateva functii… :))