• WordPress behind nginx

    if ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] )
    && preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/',
    $_SERVER['HTTP_X_FORWARDED_FOR'] ) )
    $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];


  • WP category as class name

    <?php if (is_single()) {
    global $post;
    $cat='';
    $cats = get_the_category($post->ID);
    foreach ( $cats as $c ) {
    $cat .= $c->category_nicename.' ';
    }
    } ?>

    Add the code above to the header.php file before the tag
    <body <?php body_class($cat); ?>>


  • Category latest posts menu

    Put in functions.php

    // Front end only, don't hack on the settings page
    if ( ! is_admin() ) {
    // Hook in early to modify the menu
    // This is before the CSS "selected" classes are calculated
    add_filter( 'wp_get_nav_menu_items', 'display_lasts_ten_posts_for_categories_menu_item', 10, 3 );
    }

    // Add the ten last posts of af categroy menu item in a sub menu
    function display_lasts_ten_posts_for_categories_menu_item( $items, $menu, $args ) {

    $menu_order = count($items); /* Offset menu order */
    $child_items = array();

    // Loop through the menu items looking category menu object
    foreach ( $items as $item ) {

    // Test if menu item is a categroy and has no sub-category
    if ( 'category' != $item->object || ('category' == $item->object && get_category_children($item->object_id)) )
    continue;

    // Query the lasts ten category posts
    $category_ten_last_posts = array(
    'numberposts' => 10,
    'cat' => $item->object_id,
    'orderby' => 'date',
    'order' => 'DESC'
    );

    foreach ( get_posts( $category_ten_last_posts ) as $post ) {
    // Add sub menu item
    $post->menu_item_parent = $item->ID;
    $post->post_type = 'nav_menu_item';
    $post->object = 'custom';
    $post->type = 'custom';
    $post->menu_order = ++$menu_order;
    $post->title = $post->post_title;
    $post->url = get_permalink( $post->ID );
    /* add children */
    $child_items[]= $post;
    }
    }
    return array_merge( $items, $child_items );
    }


  • Fixed Menu

    var nav = jQuery('.secondary-navigation');
    jQuery(window).scroll(function () {
    if (jQuery(this).scrollTop() > 136) {
    nav.css("position","fixed");
    nav.css({"width":(jQuery('#header').width()+'px')}); //header compensation
    jQuery('#header').css("height","136px");
    } else {
    nav.css("position","");
    jQuery('#header').css("height","");
    }
    });


  • Scrollable background

    CSS
    html, body{
    height:100%;
    min-height:100%;
    margin:0;
    padding:0;
    }
    .bg{
    width:100%;
    height:100%;
    background: #fff url(..) no-repeat fixed 0 0;
    overflow:auto;
    }
    <div class="bg">
    < span >..< /span >
    </div>

    Javascript
    $('.bg').scroll(function() {
    var x = $(this).scrollTop();
    $(this).css('background-position', '0% ' + parseInt(-x / 10) + 'px');
    });

    Check working example at http://jsfiddle.net/Vbtts/
    Click this link for the full screen example: http://jsfiddle.net/Vbtts/embedded/result/


  • kj

    grep -R 'htaccess' *


  • WP shortcode to php output

    functions.php
    function jv($atts){
    $atts = shortcode_atts( array(
    'file' => ''
    ), $atts, 'akcija' );
    ob_start();
    include(ABSPATH.'wp-content/akcija/'.$atts['file'].'.php');
    $content = ob_get_clean();
    return $content;
    }
    add_shortcode('akcija', 'jv');