Salta al contenuto
  • CATEGORIES
  • La Community Connect.gt
  • Presentati alla Community
  • News Ufficiali da Connect.gt
  • Internet News
  • A Scuola Di
  • Digital Marketing
  • Intelligenza Artificiale
  • SEO & GEO
  • Web Marketing e Content
  • Google Analytics e Web Analytics
  • Google Ads & Advertising
  • YouTube
  • TikTok, Instagram e altri Social
  • Google Adsense, Affiliazioni e Guadagno
  • E-Commerce
  • Coding e Sistemistica
  • Help Center: consigli per il tuo progetto
  • Hosting e Cloud
  • Coding
  • CMS & Piattaforme Self-Hosted
  • Annunci e Collaborazioni
  • Annunci Vendita e Acquisto: Pubblicità, Domini, Link e altro
  • Collaborazioni WEB e Lavoro: offro e cerco
  • Impresa, Fisco e Leggi
  • Consulenza Legale e Professioni Web
  • Consulenza Fiscale, Imprese, Startup e P.Iva
  • Gli Off Topic
  • PC, Smartphone e altri Hardware
  • Tutti i Software
  • GT Fetish Cafè
  • Discussioni
  • 0 Non letti 0
  • Recenti
  • Hashtag
  • Popolare
  • Utenti
  • Privacy
  • Termini e condizioni
  • © 2026 Search On Media Group S.r.l.
Collassa
Connect.gt
Il network Search On
Connect.gt WMF AI Festival Accademia Advanced SEO Tool AgentCy Social Media Strategies Search Tech
Registrati Accedi
Connect.gt
Stream Interest Categorie Hashtag
  1. La community italiana di SEO, marketing digitale e AI
  2. Categorie
  3. Coding e Sistemistica
  4. CMS & Piattaforme Self-Hosted
  5. Chiamate a categoria per elenco POST

Chiamate a categoria per elenco POST

Pianificato Fissato Bloccato Spostato CMS & Piattaforme Self-Hosted
4 Post 2 Autori 794 Visualizzazioni 1 Seguito
  • Da Vecchi a Nuovi
  • Da Nuovi a Vecchi
  • Più Voti
Rispondi
  • Risposta alla discussione
Effettua l'accesso per rispondere
Questa discussione è stata eliminata. Solo gli utenti con diritti di gestione possono vederla.
  • K
    K
    keggy
    scritto su ultima modifica di
    User 0
    #1
    Chiamate a categoria per elenco POST

    Buonasera a tutti, per la gestione di una parte della home del mio sito c'è questo php qua sotto:

     <!-- INNER content2 -->
        <div id="inner">  
        
        [B]<?php $issuesCategory = get_option('tb_home_issues_category'); ?>[/B]
        
        <h3>News dalla Regione<span></span></h3>
        
        <?php
        $args = array();
        
        $args['post_type'] = 'post';
        $args['post_status'] = 'publish';
        $args['posts_per_page'] = 5;
        [B]if ($issuesCategory) {[/B]
    [B]        $excludeCategory = '-' . $issuesCategory;[/B]
    [B]        $args['cat'] = $excludeCategory;[/B]
    [B]    }[/B]
        
        $tbQuery = new WP_Query($args);
        $latestIndex = 1;
        
        if ($tbQuery->have_posts()) : while ($tbQuery->have_posts()) : $tbQuery->the_post();
        ?>
        
        <?php $postID = get_the_ID(); ?>
        <?php $postTitle = get_the_title($postID); ?>
        <?php $postPermalink = get_permalink($postID); ?>
        
        <?php
        if ($latestIndex == 5) {
            $newsClass = 'news width50 right';
            $dfs = 'small';
            $tSize = 'dfs';
        } 
    elseif ($latestIndex == 4) {
            $newsClass = 'news width50 left';
            $dfs = 'small';
            $tSize = 'dfs';
        }
    elseif ($latestIndex == 3) {
            $newsClass = 'news width50 left';
            $dfs = 'small';
            $tSize = 'dfs';
        }
    
    
    elseif ($latestIndex == 2) {
            $newsClass = 'news width50 left';
            $dfs = 'small';
            $tSize = 'dfs';
        }
    
    
     else {
            $newsClass = 'news';
            $dfs = 'medium';
            $tSize = 'dfm';
        }
        
    
    
    
    
        ?>
    
    
    
    
        
        <div class="<?php echo $newsClass; ?>">
            <div class="doubleFramed <?php echo $dfs; ?> left">
                <a href="<?php echo $postPermalink; ?>" title="<?php $postTitle; ?>">
                    <?php echo tb_get_thumbnail($postID, $tSize); ?>
                </a>
            </div>
            
            <div class="right">
                <?php
                if ($latestIndex > 1) { ?>
                    <div class="newsInfo"><?php echo get_the_date('l j F, Y'); ?></div>
                <?php }    ?>
            
                <h4><a href="<?php echo $postPermalink; ?>" title="<?php $postTitle; ?>"><?php echo $postTitle; ?></a></h4>
                
                <?php
                if ($latestIndex == 1) { ?>
                    <div class="newsInfo"><?php echo get_the_date('l j F, Y'); ?></div>
                <?php }    ?>
                
                <?php if ($latestIndex == 1) {
                    the_excerpt();
                } else {
                    echo '<p>' . tb_max_words(get_the_excerpt(), 18) . '...</p>';
                } ?>
                
                <a href="<?php echo $postPermalink; ?>" title="<?php $postTitle; ?>" class="tinyButton roundButtonX right">Leggi tutto</a>
            </div>
        </div>
                
        <?php
        if ($latestIndex == 1) { ?>
            <div class="horDashed"></div>
        <?php }    ?>
    
    
        
        <?php $latestIndex++; ?>
        
        <?php endwhile; endif; ?>
        
        <?php wp_reset_postdata(); ?>
    
    
        <?php
        if ($issuesCategory) { ?>
        
        <?php
        $args2 = array();
        
        $args2['post_type'] = 'post';
        $args2['post_status'] = 'publish';
        $args2['posts_per_page'] = 3;
        $args2['cat'] = $issuesCategory;
        
        $tbQuery2 = new WP_Query($args2);
        $issuesIndex = 1;
        
        if ($tbQuery2->have_posts()) { ?>
        
        <div class="horDouble"></div>
                    
        <h4><span></span></h4>
    
    
        <?php while ($tbQuery2->have_posts()) : $tbQuery2->the_post();     ?>
        
    
    
        <?php $postID = get_the_ID(); ?>
        <?php $postTitle = get_the_title($postID); ?>
      <?php $postPermalink = get_permalink($postID); ?>
        
        <?php if ($issuesIndex == 1) echo '<div class="news width50 left">'; ?>
        <?php if ($issuesIndex == 2) echo '</div><div class="news width50 right">'; ?>
        
        <div class="newsInfo"><?php echo get_the_date('l j F, Y'); ?></div>
        <h4><a href="<?php echo $postPermalink; ?>" title="<?php echo $postTitle; ?>"><?php echo $postTitle; ?></a></h4>
        
        <?php if ($issuesIndex == 1) {
            the_excerpt(); ?>
            <a href="<?php echo $postPermalink; ?>" title="<?php echo $postTitle; ?>" class="tinyButton roundButtonX right">Leggi tutto</a>
        <?php } ?>
        
        <?php if ($issuesIndex > 1 && $issuesIndex < 3) echo '<div class="horDashed"></div>'; ?>
        
        <?php if ($issuesIndex == 3) echo '</div>'; ?>
        
        <?php $issuesIndex++; ?>
        
        <?php endwhile; } ?>
        
        <?php if ($issuesIndex > 1 && $issuesIndex < 3) echo '</div>'; ?>
        
        <?php wp_reset_postdata(); ?>
            
        <?php    
        }
    
    
        $args3 = array();
        
        $args3['post_type'] = 'tb_video';
        $args3['post_status'] = 'publish';
        $args3['posts_per_page'] = 1;
        
        $args3['meta_query'] = array(
            array(
                'key'        => '_featured',
                'value'        => 1,
                'compare'    => '='
            )
        );
        
        $tbQuery3 = new WP_Query($args3);
        
        ?>
    
    
        <?php if ($tbQuery3->have_posts()) : while ($tbQuery3->have_posts()) : $tbQuery3->the_post(); ?>
        
            <?php $postID = get_the_ID(); $postTitle = get_the_title(); ?>
            <?php $postURL = get_post_meta($postID, '_url', true); ?>
    
    
            <div class="horDouble"></div>
            
            <h4>Featured <span>Videos</span></h4>
            
            <div class="video">
                <div>
                    <a href="<?php echo esc_url($postURL); ?>" title="<?php echo $postTitle; ?>">
                        <?php echo get_the_post_thumbnail($postID, 'videoHome', array('alt' => $postTitle, 'title' => $postTitle)); ?>
                    </a>
                </div>
                
                <div>
                    <h4><a href="<?php the_permalink(); ?>"><?php echo $postTitle; ?></a></h4>
                    <div class="newsInfo"><?php echo get_the_date('l j F, Y'); ?></div>
                    
                    <div class="horDashed"></div>
                    
                    <?php echo '<p>' . tb_max_words(get_the_excerpt(), 40) . '...</p>'; ?>
                </div>
            </div>
    
    
        
        <?php endwhile; endif; ?>
        
        <?php wp_reset_postdata(); ?>
    
    
        </div>
        <!-- .INNER content2 -->
    

    che genera due gruppi di articoli presi da due differenti categorie:

    il primo blocco sono tutti gli articoli che non rientrano nella categoria del secondo blocco di articoli, questo valore viene passato tramite il menù impostazioni del tema.

    La mia richiesta è quella di esplicitare per i due blocchi due differenti categorie direttamente dentro al codice php.

    Dove e come devo inserire le chiamate alle categorie?

    GRAZIE IN ANTICIPO

    1 Risposta Ultima Risposta
    Miglior risposta 0
    0
    • A
      A
      andmore
      scritto su ultima modifica di
      User Attivo 0
      #2

      keggy

       [B]<?php $issuesCategory = get_option('tb_home_issues_category'); ?>[/B]
      

      Per prima cosa puoi notare che la categoria $issuesCategory viene presa all'interno di una opzione salvata dal tuo tema. Cambiando questa variabile potrai indicare la categoria di appartenenza

          $args = array();
      
          $args['post_type'] = 'post';
          $args['post_status'] = 'publish';
          $args['posts_per_page'] = 5;
          [B]if ($issuesCategory) {[/B]
      [B]        $excludeCategory = '-' . $issuesCategory;[/B]
      [B]        $args['cat'] = $excludeCategory;[/B]
      [B]    }[/B]
      

      Ma fossi in te, subito sotto a questo codice andrei ad inserire quanto segue:

      $args['cat'] = 1;
      

      In questo modo, anche se non in maniera pulita, sostituisci il valore della categoria da escludere ed imposta l'ID alla categoria che invece vuoi caricare in questa sezione. Raggiunto il prossimo blocco di codice>

          <?php
          if ($issuesCategory) { ?>
      
          <?php
          $args2 = array();
      
          $args2['post_type'] = 'post';
          $args2['post_status'] = 'publish';
          $args2['posts_per_page'] = 3;
          $args2['cat'] = $issuesCategory;
      

      potresti sostituire il valore collegato alla variabile $args2['cat'], con il valore di un altro ID corrispondente all'altra categoria che vuoi mostrare.

      Facendo in questo modo dovresti essere in grado di mostrare le categorie che desideri, prova e facci sapere 😉

      1 Risposta Ultima Risposta
      Miglior risposta 0
      0
      • K
        K
        keggy
        scritto su ultima modifica di
        User 0
        #3

        Con la riga:

        $args['cat'] = 1;
        vado a prendere la categoria numero 1 che ho tra le mie del sito?

        Nella seconda parte stessa domanda, come passo ad arg2 il riferimento ad una altra categoria?

        grazie mille

        PS: domattina faccio la prova e vi faccio sapere...

        1 Risposta Ultima Risposta
        Miglior risposta 0
        0
        • A
          A
          andmore
          scritto su ultima modifica di
          User Attivo 0
          #4

          per $arg2['cat'] devi utilizzare l'ID della categoria che vuoi utilizare, usa la stessa sintassi che stai usando con $args['cat'], ma mi raccomando vai a selezionare l'ID della categoria, altrimenti non riuscirai a mostrare quello che cerchi.

          1 Risposta Ultima Risposta
          Miglior risposta 0
          0

          Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.

          Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.

          Con il tuo contributo, questo post potrebbe essere ancora migliore 💗

          Registrati Accedi
          Rispondi
          • Risposta alla discussione
          Effettua l'accesso per rispondere
          • Da Vecchi a Nuovi
          • Da Nuovi a Vecchi
          • Più Voti


          • Accedi

          • Non hai un account? Registrati

          • Accedi o registrati per effettuare la ricerca.
          • Primo post
            Ultimo post
          Home Accedi Registrati
          Menu
          • CATEGORIES
          • La Community Connect.gt
          • Presentati alla Community
          • News Ufficiali da Connect.gt
          • Internet News
          • A Scuola Di
          • Digital Marketing
          • Intelligenza Artificiale
          • SEO & GEO
          • Web Marketing e Content
          • Google Analytics e Web Analytics
          • Google Ads & Advertising
          • YouTube
          • TikTok, Instagram e altri Social
          • Google Adsense, Affiliazioni e Guadagno
          • E-Commerce
          • Coding e Sistemistica
          • Help Center: consigli per il tuo progetto
          • Hosting e Cloud
          • Coding
          • CMS & Piattaforme Self-Hosted
          • Annunci e Collaborazioni
          • Annunci Vendita e Acquisto: Pubblicità, Domini, Link e altro
          • Collaborazioni WEB e Lavoro: offro e cerco
          • Impresa, Fisco e Leggi
          • Consulenza Legale e Professioni Web
          • Consulenza Fiscale, Imprese, Startup e P.Iva
          • Gli Off Topic
          • PC, Smartphone e altri Hardware
          • Tutti i Software
          • GT Fetish Cafè
          • Discussioni
          • Non letti 0
          • Recenti
          • Hashtag
          • Popolare
          • Utenti
          • Privacy
          • Termini e condizioni
          • © 2026 Search On Media Group S.r.l.