In prima parte am scris despre cum sa afisezi titlurile posturilor cu linkuri catre posturi. Recomand citirea primii parti celor care nu au facut-o deja, inainte de a incepe citirea partii a doua.
Primul lucru pe care il vom face in partea a doua este sa folosim single.php pentru a afisa posturile. In single.php adaugam codul :
<? if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2><? the_title(); ?></h2>
<? the_content(); ?>
<? edit_post_link(__(’Edit’), ‘<p>’, ‘</p>’); ?>
<? endwhile; endif; ?>
Si acum posturile vor fi afisate folosind single.php, vom vedea mai tarziu cu ce ne ajuta asta. Pana acum am afisat doar titlurile posturilor, acum sa afisam si o parte din post. Modificam codul din index.php :
<?if (have_posts()):?>
<? while(have_posts()):?>
<? the_post()?>
<a href=’<?=the_permalink()?>’><?=the_title()?></a>
<?the_content(”citeste mai mult”);?>
<br/>
<?endwhile;?>
<?endif;?>
Functia the_content afiseaza o portiune din post si apoi linkul “citeste mai mult”. Daca vrem sa afisam categoria postului atunci folosind functia the_category modificam codul si index.php va arata asa :
<?if (have_posts()):?>
<? while(have_posts()):?>
<? the_post()?>
<a href=’<?=the_permalink()?>’><?=the_title()?></a>
in <strong><?the_category(”,”);?></strong>
<?the_content(”citeste mai mult”);?>
<br/>
<?endwhile;?>
<?endif;?>
Acum vrem sa afisam data cand a fost postat si autorul fiecarui post in single.php. Folosim functiile the_author si the_time :
<?if (have_posts()):?>
<? while(have_posts()):?>
<? the_post()?>
<h1><a href=’<?=the_permalink()?>’><?=the_title()?></a></h1>
<?php _e(”Posted “); ?> by <?php the_author() ?> at
<?php the_time(’F jS, Y’)?><hr/>
<?the_content(”more”);?>
<br/>
<?endwhile;?>
<?endif;?>
Asta e tot. Acum avem si data si numele autorului. Toate informatiile despre orice functie Wordpress se pot gasi pe Wordpress Codex.
Cam atat pentru partea a doua.
Vezi toate articolele scrise de: 





