Wsparcie » Motywy » Wyświetlanie danej kategorii

  • Chciałbym zrobić aktualności, ale chcę by wyświetlały się tylko określone kategorie, np kategoria „luty”

    W pliku index.php mam:

    <a href="<?php the_permalink(); ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'single-post', array('class' => 'entry-thumb') ); } ?>
    </a>
    
    <?php the_content('czytaj dalej'); ?>
    
    <div class="clear"></div>
    </div>
    
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>

    Wynik jest taki że wyświetla wszystkie wpisy, jak to zmianić by wyświetlał tylko kategorię „luty” ?

Viewing 14 replies - 1 through 14 (of 14 total)
  • <?php
    $args = array(
      'cat' => Numer ID kategori
    );
      ?>
    <?php query_posts( $args ); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div class="content">
    <h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'single-post', array('class' => 'content-thumb') ); } ?>
    </a>
    <?php the_excerpt(); ?>
    <div class="clear"></div>
    </div>
    <?php endwhile; else: ?>
    <?php endif; ?>
    Thread Starter golgol4

    (@golgol4)

    Gdzie tu wpisać kategorię „luty”

    jak tworzysz w panelu admina kategorie to jak najedziesz myszką na nazwe pojawi ci się link i tam w linku będzie np ID=3 wiec trzeba napisać nr 3 dla cat w kodzie 🙂

    Thread Starter golgol4

    (@golgol4)

    Tak, teraz działa, nie mogłem załapać gdzie to ID, szkoda że nie można od razu nazwę kategorii. Ale jest ok. Dzięki!

    $args = array (
    'category_name' => 'staff'
     );
    
    <?php
    // the query
    $the_query = new WP_Query( $args ); ?>
    
    <?php if ( $the_query->have_posts() ) : ?>
      <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
        <h2><?php the_title(); ?></h2>
      <?php endwhile; ?>
      <?php wp_reset_postdata(); ?>
    <?php else:  ?>
      <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    <?php endif; ?>
    Thread Starter golgol4

    (@golgol4)

    Tak tylko teraz jak mam stronicowanie to na drugiej stronie wywala mi to co jest na pierwszej

    aktualnosci/ – strona 1 index.php
    aktualnosci/page/2/ – druga strona daje to co na pierwszej

    Thread Starter golgol4

    (@golgol4)

    Mam taki kod:

    <?php
    $args = array(
      'category_name' => 'luty'
    );
      ?>
    <?php query_posts( $args ); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <div class="entry">
    
    <h2><?php the_title(); ?></h2>
    
    <a href="<?php the_permalink(); ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'single-post', array('class' => 'entry-thumb') ); } ?>
    </a>
    
    <?php the_content('czytaj dalej'); ?>

    zapomniałeś o

    <?php endwhile; ?>
      <?php wp_reset_postdata(); ?>
    <?php else:  ?>
      <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    <?php endif; ?>

    zainstaluj sobie plugin wp-pagenavi, a za pętlą loop wstaw shortcode powinno pomóc

    Thread Starter golgol4

    (@golgol4)

    W index.php mam tak ze stronicowaniem :

    <?php
    $args = array(
      'category_name' => 'luty'
    );
      ?>
    <?php query_posts( $args ); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <div class="entry">
    
    <h2><?php the_title(); ?></h2>
    
    <a href="<?php the_permalink(); ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'single-post', array('class' => 'entry-thumb') ); } ?>
    </a>
    
    <?php the_content('czytaj dalej'); ?><br />
    <br />
    
    <div class="clear"></div>
    </div> <!-- end entry -->
    
    <?php endwhile; ?>
      <?php wp_reset_postdata(); ?>
    <?php else:  ?>
      <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    <?php endif; ?>
    
    <!-- STRONICOWANIE -->
    <?php if(function_exists('page_navi_slider')){page_navi_slider();}?>

    I dalej nie wyświetla 2 strony.

    <?php
    $args = array(
      'category_name' => 'luty',
      'posts_per_page' => 5
    );

    5 – ilość wpisów wyświetlanych na pierwszej stronie.

    Thread Starter golgol4

    (@golgol4)

    nadal nie ma drugiej strony.

    Lista jest, ale jak przejdę na stronę 2 to nadal wyświetla to co na pierwszej.

    Thread Starter golgol4

    (@golgol4)

    Jak sobie wejdę przez linka:

    category/luty/

    To jest ok, ale tam (category.php) nie mam tego :

    <?php
    $args = array(
      'category_name' => 'luty'
    );
    ?>

    ja zawsze robiłem page template(szabon strony) i w nim definiowałem loopa-* wraz z stronicowaniem, i u mnie zawsze działało.

    <?php
    /*
    Template Name: Nazwa szablonu
    */
    ?>
    <?php get_header();
    get_template_part('loop','*');
    ?>
    <div class="clear"></div>
    <!-- stronicowanie -->
    <?php get_footer();?>

    * – dodatkowa nazwa (np loop-arch.php)

    najlepiej podaj tez link strony bo na razie brak mi pomysłów.

    ale zawsze używałem funkcji tej pierwszej z cat

    Thread Starter golgol4

    (@golgol4)

    ok, łapie łapie…

    Linka nie mogę podać bo mamy na serwerze dostęp tylko dla naszego IP, więc nikt tego nie zobaczy.

    Ale Wielkie Dzięki za pomoc, dużo poszło do przodu.

Viewing 14 replies - 1 through 14 (of 14 total)
  • Temat ‘Wyświetlanie danej kategorii’ jest zamknięty na nowe odpowiedzi.