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:
<?php 
/* the path of your wordpress subfolder with the file, required, "wp-blog-header.php" */
require("$root/wordpress/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]
?>


<?php
// 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.

How avoid https problems in localhost

Since a solution to force browsers toward a secured connection (with https and not http) is using an .htaccess file in the root folder, you can avoid many problems with https in localhost with this code, which you can put into the .htaccess, before the last row:

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]{3}$

So your .htacces file should contain these rows

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^[^.]+.[^.]{3}$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

This way you will have, with the same file, in local an http connection, and in remore an https connection.

w3c validation UTF-8 encoding error

With w3c validator you could get this error:
«Sorry, I am unable to validate this document because on line 3400 it contained one or more bytes that I cannot interpret as utf-8 (in other words, the bytes found are not valid values in the specified Character Encoding). Please check both the content of the file and the character encoding indication.» 
That could be because you have some files included in the php file checked by w3c validator, like an .inc one, not encodeed as UTF-8.
To fix this oproblem you have to encode all the components of a php file as UTF-8.

batch change encoding to UTF-8 for several text (php) files

You can use recode
recode UTF-8 *.php -v

provided that all the files have the same encoding.
Otherwise you can try with something like
iconv -f US-ASCII -t UTF-8 *.php

a minor problem

It could be an apparent problem if there aren’t non-ascii characters in a file: then these files are yet recognized, with
file -i --mime-encoding *
as us-ascii.
So you can add a non ascii character, like è:
sed -i -e “$aè” *.php

and afterwards redo the command “recode” as above and replace some ascii expression, like agrave; with UFT-8 à character.
Eventually you will delete the “è” from the end of the files.

css: applicare o rimuovere una classe all’elemento “parent”

Si può ricorrere a jquery.
Mettiamo che io voglia applicare la class “noquote” (che toglie le virgolette all’inizio del paragrafo) a un p al cui interno si trova uno span. La sintassi è questa:
    $( “p:has(> span)” ).addClass( “noquote” );
Se invece io voglio che p abbia le virgolette all’inizio se lo span ha una certa classe (mettiamo “evid”), la sintassi è la seguente:
    $(“.evid”).parent().removeClass(“noquote”);

formattazione condizionale css

Parliamo di tag html e di css. Voglio che se un p comincia con uno span non venga applicata una certa regola (nella fattispecie “aperte virgolette”). In effetti creo una pagina php con citazioni di autori e capita che un certo item cominci non con le parole dell’autore, ma con una mia introduzione.
Non è possibile agire a livello di puro css, col selettore :not (nella fattispecie :not(p > span): non viene riconosciuto.
Allora bisogna usare jquery

  • collegare la pagina php a jquery su web (<script type=”text/javascript” src=”http://code.jquery.com/jquery-latest.min.js”></script>)
  • creare una classe css, nel mio caso: .noquote (metto l’intero codice: “blockquote p.noquote:first-child:before {content:none;}”
  • inserire lo script: “<script type=”text/javascript”>
    $( “p:has(> span)” ).addClass( “noquote” );
    </script>”

E il gioco è fatto!