include wordpress category (or tag) posts in a website

  • You can install wordpress in a subdirectory of your website, in localhost as well.
  • Afterward you can embed the content (or the link) of your wordpress posts in your php pages using a code like the following:
/* the path of your wordpress subfolder with the file, required, "wp-blog-header.php" */
//get_header(); [you can omit this row, if you want embed the wp posts in your page having already header and styles]

// Get the last 200 posts of a given category: 
//in this case the 565 one (=office).
global $post;
$args = array('posts_per_page' => 200,  'category' => 565 );
$myposts = get_posts( $args );

foreach( $myposts as $post ) :	setup_postdata($post); ?>
<h2><?php the_title(); ?></h2>
<p><?php the_content(); ?></p>
// the following code is to put a link: you could choose to don't add it, or, on the contrary, to put only it
<a href="<?php the_permalink() ?>" rel="bookmark" 
title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_title(); ?></a><br />
<?php endforeach; ?>
  • if you want embed in your pages tag posts instead of category posts you can use this code

$args = array('posts_per_page' => 100, 'tag' => 'css' );

Further info here.

Lascia un commento

Il tuo indirizzo email non sarĂ  pubblicato. I campi obbligatori sono contrassegnati *