Un template per WordPress per stampare Articoli da una determinata Categoria in una pagina statica, come Home (Home.php) o Articoli (articoli.php).
/*
Template name: Page of Posts
LICENSE:
GPL
(c) 2010
PMES Consulting
http://pmesconsulting.com
USAGE:
1.Add our two methods to functions.php (*).
2.Create a /langs/ folder in your wp-content/themes/Your-Theme/ in order to lets
Language translation works (you will notice pmesConsultingCom below).
3.Create a new page template like portfolio.php or index.php or my-category.php,
personally I had used it as homepage (home.php) (*2).
4.Create a new Page Page from wp-admin.
5.Add the template to it.
6.Remember to Print the_slug() in wished page templates ( echo the_slug(); ).
(*) ADD these two methods in Functions.php
// <Language files loading>
function langs() {
load_theme_textdomain('pmesConsultingCom', get_template_directory() .'/langs' );
}
add_action ('init', 'langs');
// END langs()
// Remember to echo the_slug(); in page templates
// retrieve post page slug
function the_slug() {
global $post;
$post_data = get_post($post->ID, ARRAY_A);
$slug = $post_data['post_name'];
return $slug;
}
// END the_slug()
// (*3) Create a new page template.
// HOME.PHP:
// Location: /wp-content/themes/My-Theme-In-Use/home.php
Template Name: Home
get_header();
query_posts('pagename=about');
global $more;
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<div title="<?php the_title(); ?>">
<h2><a href="<?php the_permalink(); ?>" tabindex="1" title="<?php printf(__('%s', 'pmesConsultingCom'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></h2>
<?php $more = 0;
the_content(); ?>
</div>
<?php endwhile;
// Another Section: Posts from a different category than above
// posts in cat portfolio
$q = new WP_Query('category_name=portfolio&posts_per_page=4'); ?>
<h2 id="portfolio">Portfolio: </h2>
<?php
// third loop
while ($q->have_posts()) : $q->the_post();
$do_not_duplicate = $post->ID; ?>
<div>
<?php $odd_or_even = ('odd' == $odd_or_even) ? 'even' : 'odd'; ?>
<h3 id="<?php echo the_slug(); ?>"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php printf(__('%s', 'pmesConsultingCom'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
<p><?php comments_popup_link(__('0 Comments »'), __('1 Comment »'), __('% Comments »'), '', __('Sorry, comments are closed for this entry.') ); ?></p>
</div>
<?php
endwhile;
// Another Section: Posts from a different category than above
// posts in cat foo
$qentries = new WP_Query('category_name=foo&posts_per_page=1');
while ($qentries->have_posts()) : $qentries->the_post();
$do_not_duplicate = $post->ID; ?>
<div>
<h3><a href="<?php the_permalink(); ?>" title="<?php printf(__('%s', 'pmesConsultingCom'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
</div>
<ul>
<li><?php the_time('j F Y'); ?></li>
<li><?php the_time('H : i'); ?></li>
<li><?php printf(__('Category: ', 'pmesConsultingCom'));
the_category(' - '); ?></li>
<li><?php comments_popup_link(__('0 Comments »'), __('1 Comment »'), __('% Comments »'), '', __('Sorry, comments are closed for this entry.') ); ?></li>
<li><?php next_posts_link('« prev'); ?></li>
<li><?php previous_posts_link('next »'); ?></li>
</ul>
<?php endwhile;
else :
include("inc/404.txt"); // (*3)
endif;
get_footer();
// Notes:
// include("path/") is a Relative Path
// in this case it is relative to Theme folder Root: wp-content/themes/My-Theme-In-Use/inc/404.txt
// An included 404 error message named 404.txt and
// located in wp-content/themes/My-Theme-In-Use/inc/
// If you dont want to use an inclusion you can just replace
// include("inc/404.txt");
// with
// print '<h2>404 Error - Page not Found</h2>';
// regards
*/