Skip to content

Instantly share code, notes, and snippets.

View rodica-andronache's full-sized avatar
🦄

Rodica-Elena Irodiu rodica-andronache

🦄
  • themeisle.com
  • Bucharest
View GitHub Profile
@rodica-andronache
rodica-andronache / gist:7101149
Last active January 19, 2017 14:14
More comments.php files.
<?php comments_template();?> -> ia fisierul comments.php
<?php comments_template('/comments-new.php');?> -> ia fisierul comments-new.php
!!! trebuie neaparat pun '/' inaintea numelui
@rodica-andronache
rodica-andronache / gist:7097416
Created October 22, 2013 08:59
display x time ago for posts and comments
For posts: <?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago'; ?>
For comments:<?php echo human_time_diff(get_comment_time('U'), current_time('timestamp')) . ' ago'; ?>
@rodica-andronache
rodica-andronache / gist:7053546
Created October 19, 2013 09:26
Get ID of page that has a certain template
$the_query = new WP_Query(
array(
'post_type' => 'page',
'meta_key' => '_wp_page_template',
'meta_value' => 'page-attorney.php' //aici e pagina templateului
)
);
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
@rodica-andronache
rodica-andronache / gist:7030451
Created October 17, 2013 19:06
WORDPRESS - Popular posts by number of views
In functions.php:
function cwp_set_post_views($postID) {
$count_key = 'cwp_post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
}else{
@rodica-andronache
rodica-andronache / gist:6992225
Created October 15, 2013 14:15
WORDPRESS - Register style
wp_register_style( 'cwp_new-style', get_template_directory_uri() . '/css/new-style.css');
wp_enqueue_style( 'cwp_new-style' );
@rodica-andronache
rodica-andronache / gist:6975706
Created October 14, 2013 13:34
WORDPRESS - Get menu name
In fucntions.php:
function cwp_get_menu_by_location( $location ) {
if( empty($location) ) return false;
$locations = get_nav_menu_locations();
if( ! isset( $locations[$location] ) ) return false;
$menu_obj = get_term( $locations[$location], 'nav_menu' );
return $menu_obj;
@rodica-andronache
rodica-andronache / gist:6975692
Created October 14, 2013 13:33
WORDPRESS - Get submenu of a certain element from menu
In functions.php:
add_filter( 'wp_nav_menu_objects', 'submenu_limit', 10, 2 );
function submenu_limit( $items, $args ) {
if ( empty($args->submenu) )
return $items;
$parent_id = array_pop( wp_filter_object_list( $items, array( 'title' => $args->submenu ), 'and', 'ID' ) );
$children = submenu_get_children_ids( $parent_id, $items );
@rodica-andronache
rodica-andronache / gist:6959386
Created October 13, 2013 07:55
Get only url of featured image
<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'thumbnail') ); ?>
<img src="<?php echo $url ?>" />
@rodica-andronache
rodica-andronache / gist:6941312
Created October 11, 2013 20:15
WORDPRESS - Show children of page if page is parent, and siblings if page is not a parent
<?php
global $post; // if outside the loop
if ( is_page() && $post->post_parent ) {
// This is a subpage
$mypages = get_pages( array( 'child_of' => $post->post_parent, 'sort_column' => 'post_date', 'sort_order' => 'asc', 'hierarchical' => '0', 'parent' => $post->post_parent ) );
echo '<ul id="nav">';
foreach( $mypages as $page ) {
@rodica-andronache
rodica-andronache / gist:6935625
Last active December 25, 2015 06:58
WORDPRESS - Contact form 7 with CAPCHA
!!!!!!!!!
Daca vreau sa adaug un id sau o clasa pt form: [contact-form-7 id="1234" title="Contact form 1" html_id="contact-form-1234" html_class="form contact-form"]
Install Contact Form 7 plugin
Install Really Simple CAPTCHA Plugin