• User Attivo

    Aiuto per codice

    Salve a tutti.
    Vado subito al problema che non riesco a risolvere. Premetto che non conosco il lingaggio php e andare per tentavi mi ha sfinito.
    Ho utilizzato il template gratuito di wordpress di questo indirizzo cssmayo.com/freebies/free-wordpress-themes/creative-by-nature/.
    Quello che vorrei fare è inserire in questa pagina cssmayo.com/preview/creative_by_nature/portfolio/ un numero limitato di item da mostrare e a fondo pagina una navigazione per le pagine seguenti. Questi item non sono post ma sottopagine. Il codice in oggetto di questa pagina è questo
    [PHP]<?php
    $projects = get_pages('child_of=' . $post->ID . '&sort_column=menu_order&sort_order=desc');

                        foreach($projects as $p) : 
                            $link = get_permalink($p->ID); 
                            $project_url = _get_field($p->ID, 'url');
                        ?>
                            <li>
                                <div class="cl">&nbsp;</div>
                                <div class="image"><a href="<?=$link?>"><?=_get_project_info('image', $p->post_content)?></a></div>
                                <div class="in">
                                    <h3><a href="<?=$link?>"><?=$p->post_title?></a></h3>
                                    <div class="entry">
                                        <?php echo apply_filters('the_content', _get_project_info('short_info', $p->post_content))?>
                                    </div>
                                    <p class="more">
                                        <a href="<?=$link?>"><span>Approfondimento</span></a>
                                        <a href="<?=$project_url?>" rel="nofollow"><span>link al sito</span></a>
                                    </p>
                                </div>
                                <div class="cl">&nbsp;</div>
                            </li>
                        <?php endforeach; ?>[/PHP]
    

    La pagina function.php è questa
    [PHP] add_action("init","wp_noversion",1);
    function wp_noversion() {
    global $wp_version;
    $wp_version = "";
    }

    function _generate_navigation() {

    $ps = get_pages('sort_column=menu_order,post_title&sort_order=asc&parent=0');
    $html = '';
    foreach($ps as $p) {
        $active = is_page($p->post_name) ? 'class="active"' : '';
        $active = $p->post_name == 'blog' && !is_page() ? 'class="active"' : $active;
        
        $html .= '<a ' . $active . ' href="' . get_permalink($p->ID) . '"><span>' . $p->post_title . '</span></a>';
    }
    return $html;
    

    }

    function _p() {
    return get_bloginfo('stylesheet_directory');
    }

    function _get_project_info( $what, $info ) {
    $info = explode('<!--more-->', $info);

    if( $what == 'image' )
        return $info[0];
    
    if( $what == 'small_image' ) {
        $image_formats = array('.jpg"', '.png"', '.gif"');
        $small_image = '';
        foreach($image_formats as $image_format) {
            if(strstr($info[0], $image_format)) {
                $small_image = str_replace($image_format, '-150x150' . $image_format, $info[0]);
                break;
            }
        }
        return $small_image;
    }
    
    if( $what == 'short_info' )
        return $info[1];
    
    if( $what == 'long_info' )
        return $info[2];
        
    return '';
    

    }

    function _get_latest_post(){
    $latest = get_posts('numberposts=1&order_by=date&order=DESC');
    return $latest[0];
    }

    function _get_latest_project( $portfolio_id ) {
    $latest = get_pages('child_of=' . $portfolio_id . '&sort_column=menu_order&sort_order=desc&number=2');
    return $latest[0];
    }

    function _list_latest_posts($num=5, $offset=1) {
    $posts = get_posts('numberposts=' . $num . '&order_by=date&order=DESC&offset=' . $offset);

    $html = '';
    foreach($posts as $p) {
        $date = _format_date( $p->post_date );
        $html .= '<li><small>' . $date . '</small><a href="'.get_permalink($p->ID).'">'. $p->post_title .'</a></li>';
    }
    //<li><small>05 April, 2009</small><a href="#">Lorem do asd as consectetur</a></li>
    return $html;
    

    }
    function list_latest_posts($num=15, $offset=0) {
    $posts = get_posts('numberposts=' . $num . '&order_by=date&order=DESC&offset=' . $offset);

    $html = '';
    foreach($posts as $p) {
        $date = _format_date( $p->post_date );
        $html .= '<li><small>' . $date . '</small><a href="'.get_permalink($p->ID).'">'. $p->post_title .'</a></li>';
    }
    //<li><small>05 April, 2009</small><a href="#">Lorem do asd as consectetur</a></li>
    return $html;
    

    }
    function _get_short_info( $text ){
    $t = explode('<!--more-->', $text);
    return $t[0];
    }

    function _format_date( $raw_date ) {
    list($y, $m, $d, $hour, $minute, $second) = preg_split('~[- :]~', $raw_date);
    $timestamp = mktime($hour, $minute, $second, $m, $d, $y);
    $format = get_option('date_format');
    return date( $format, $timestamp );
    }

    function _get_page_by_name($page_name, $output = OBJECT) {
    global $wpdb;
    $page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type='page'", $page_name ));
    if ( $page )
    return get_page($page, $output);

    return null;
    

    }
    function _get_field( $post_id, $field_key ) {
    $fields = get_post_meta($post_id, $field_key);
    if( count($fields) == 0)
    return '';
    if( count($fields) == 1)
    return $fields[0];

    return $fields;
    

    }

    automatic_feed_links();

    if ( function_exists('register_sidebar') ) {
    register_sidebar(array(
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget' => '</li>',
    'before_title' => '<h2 class="widgettitle">',
    'after_title' => '</h2>',
    ));
    }[/PHP]

    Ho trovato un codice in wordpress.org che soddisfa la mia richiesta ma non riesco ad adattarlo a questo template. Il codice in questione è questo
    [PHP] <!-- Start Code -->
    <?php
    $postIDs = array();
    $pageChildren = get_pages('child_of=' . $post->ID . '&exclude=' . $exclude_page );
    if ( $pageChildren ) {
    foreach ( $pageChildren as $pageChild ) {
    $postIDs[] = $pageChild->ID;
    }
    $paged = (intval(get_query_var('paged'))) ? intval(get_query_var('paged')) : 1;
    $args = array(
    'post_type' => 'page',
    'paged' => $paged,
    'post__in' => $postIDs,
    'posts_per_page' => 10
    );
    query_posts($args);

    if (have_posts()) : while (have_posts()) : the_post(); ?>

    <div class="post" id="post-<?php the_ID(); ?>">
    <h2><?php the_title(); ?></h2>
    <div class="entry">
      <?php the_excerpt('<p class="serif">Read the rest of this page »</p>'); ?>
    
      <?php wp_link_pages(array('before' => '<p>Pages: ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    
    </div>
    

    </div>
    <?php endwhile; ?>
    <div class="navigation">
    <div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
    <div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
    </div>

    <?php endif; ?>

    <?php } ?>
    <!-- End Code -->[/PHP]

    Sarei molto felice se qualche esperto riuscisse ad aiutarmi.
    Grazie mille in anticipo e un saluto a tutti
    Giuseppe


  • User Attivo

    Ciao elmanisero e benvenuto nel forum GT.
    Ti consiglio di utilizzare la funzione wp_list_pages che è più semplice e permette di fare le stesse cose...


  • User Attivo

    Grazie cardy per la risposta, oramai disperavo che nessuno lo avrebbe fatto. Ho provato ad utilizzare wp_list_page ma non ho le competenze per creare il codice che faccia le cose che vorrei, nè ho trovato in giro qualcosa che gli assomigli. Ci vorrebbe uno esperto in codici php ma temo che gratuitamente nessuno si prenda la briga di farlo. Pensa che ho scritto anche ad un paio di sviluppatori di wordpress chiedendogli la consulenza a pagamento ma manco mi hanno risposto. Se ci fosse qualcuno disposto a farlo anche a pagamento che mi contatti.
    Comunque grazie ancora
    Giuseppe