Visualizzazione dei risultati da 1 a 8 su 8
  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2001
    Messaggi
    1,742

    Piccola modifica a due script

    Salve a tutti,
    per un mio blog, basato su wordpress, ho installato due plug in che mi permettono di fare una top10 degli articoli più commentati e quelli più letti.
    Adesso nella sidebar del blog ho inserito i due script che mi stampano il titolo dell'articolo (linkato) con sfondo grigio.
    Vorrei che allo script venga apportato una piccola modifica che mi permette di alternare i colori di sfondo, della classifica, ad ogni articolo. (un pò come l'alternanza di colori che si vede quando si lasciano i commenti).

    Il primo script che stampa i 10 articoli più commentati.
    Codice PHP:
    /* 
    Plugin Name: Most Commented 
    Plugin URI: [url]http://mtdewvirus.com/code/wordpress-plugins/[/url] 
    Description: Retrieves a list of the posts with the most comments. 
    Version: 1.02 
    Author: Nick Momrik 
    Author URI: [url]http://mtdewvirus.com/[/url] 
    */ 

    function mdv_most_commented($no_posts 10$before '[*]' $after ''$show_pass_post false) { 
        global 
    $wpdb
            
    $request "SELECT ID, post_title, COUNT($wpdb->comments.comment_post_ID) AS 'comment_count' FROM $wpdb->posts$wpdb->comments"
            
    $request .= " WHERE comment_approved = '1' AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish'"
            if(!
    $show_pass_post$request .= " AND post_password =''"
            
    $request .= " GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_count DESC LIMIT $no_posts"
        
    $posts $wpdb->get_results($request); 
        
    $output ''
            if (
    $posts) { 
                    foreach (
    $posts as $post) { 
                            
    $post_title stripslashes($post->post_title); 
                            
    $comment_count $post->comment_count
                            
    $permalink get_permalink($post->ID); 
                            
    $output .= $before '[url="' $permalink '"]' $post_title '[/url] (' $comment_count.')' $after
                    } 
            } else { 
                    
    $output .= $before "None found" $after
            } 
        echo 
    $output

    Il secondo script che stampa i 10 articoli più letti
    Codice PHP:
    $top10posts get_option('top10posts'); 
    if (
    $top10posts == '') { 
        
    $wpdb->query("create table mostAccessed (accessedid int not null auto_increment, postnumber int not null,cntaccess int not null,primary key(accessedid))");
        
    update_option('top10posts'"top10postsver1");
    }

    if (
    $top10posts == 'top10postsver1') { 
        
    $wpdb->query("delete from mostAccessed where postnumber = 0");
        
    $wpdb->query("alter table mostAccessed add accessedid int not null auto_increment, drop primary key, add primary key (accessedid)");
        
    update_option('top10posts'"top10postsver12");
    }
    add_action('shutdown','add_viewed_count');

    function 
    add_viewed_count() {
        global 
    $id$wpdb$single;
        if (
    $single && isset($id) && $id 0) {    
            
    $results $wpdb->get_results("select postnumber, cntaccess from mostAccessed where postnumber = '$id'");
            
    $test 0;
            if (
    $results) {
                foreach (
    $results as $result) {
                    
    $wpdb->query("update mostAccessed set cntaccess = cntaccess + 1 where postnumber = $result->postnumber");
                    
    $test 1;
                }
            }
            if (
    $test == 0) {
                
    $wpdb->query("insert into mostAccessed(postnumber, cntaccess) values('$id', '1')");
            }
        }
    }

    function 
    show_pop_posts() {
        global 
    $wpdb$siteurl$tableposts$id;
        
    $results $wpdb->get_results("select postnumber, cntaccess from mostAccessed ORDER BY cntaccess DESC LIMIT 10");
        echo 
    "<ul>";
        if (
    $results) {
            foreach (
    $results as $result) {
                echo 
    '[*][url="'.get_permalink($result->postnumber).'"]'.get_the_title($result->postnumber).'[/url] ('.$result->cntaccess.')';
            }
        }
        echo 
    "[/list]";
    }

    function 
    show_post_count($beforecount='(Visited '$aftercount=' times)') {
        global 
    $wpdb$id;
        
    $resultscount $wpdb->get_row("select postnumber, cntaccess from mostAccessed WHERE postnumber = $id");
        echo 
    $beforecount.$resultscount->cntaccess.$aftercount;

    In pratica nel codice dove c'è il tag[*] si deve aggiungere una variabile alla classe di li che cambia i colori alternandoli.
    Ma a me la cosa risulta abbastanza complicated

  2. #2
    Utente di HTML.it
    Registrato dal
    Jan 2001
    Messaggi
    1,742

  3. #3
    Originariamente inviato da kiapparo
    troppo lungo per quello nessuno ti risponde
    inizia con un pezzettino alla volta

  4. #4
    Utente di HTML.it
    Registrato dal
    Jan 2001
    Messaggi
    1,742
    Originariamente inviato da vercinstex
    troppo lungo per quello nessuno ti risponde
    inizia con un pezzettino alla volta
    :master:
    aspetterò.. non insisto più.

  5. #5
    Utente di HTML.it
    Registrato dal
    Jan 2001
    Messaggi
    1,742
    ultimo up

  6. #6
    Utente di HTML.it L'avatar di nicola75ss
    Registrato dal
    Nov 2004
    Messaggi
    12,922
    Ti do l'input. Poi lo integri nel tuo codice.

    <style type="text/css">
    table
    {
    border: 1px;
    }
    .colore1
    {
    background-color:#f7f7ff;
    }
    .colore2
    {
    background-color:#a7bbe3;
    }
    </style>

    Codice PHP:
    <?php
    $query 
    mysql_query('tua_query');
    $class '';
    echo 
    "<table>";
    while (
    $row mysql_fetch_array($query))
    {
    $class $class == 'colore1' 'colore2' 'colore1';
    echo 
    "<tr class=\"$class\">";
        foreach(
    $row as $field)
        echo 
    "<td>$field</td>";
    echo 
    "</tr>";
    }
    echo 
    "</table>";
    ?>

  7. #7
    Utente di HTML.it
    Registrato dal
    Jan 2001
    Messaggi
    1,742
    Grazie mille.

  8. #8
    Utente di HTML.it L'avatar di nicola75ss
    Registrato dal
    Nov 2004
    Messaggi
    12,922
    prego.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.