Archivi categoria: Wordpress

How to bulk publish or bulk delete pending posts in WordPress

Do you have many posts to edit on your WordPress website and you do not know how to do it? Actually, the WordPress editor doesn’t offer much in bulk editing: it only allows you to edit 10 posts at a time. Therefore, when there are a lot of pending posts to publish or delete this can be a problem. There is, anyway, a quick way to bulk edit posts.

Bulk edit from PhpMyAdmin

As you all know WordPress is a CMS that is installed on your server and which put the data in a database. Therefore you just have to go to the control panel (usually Cpanel) of your hosting provider and search PhpMyAdmin in the search bar (PhpMyAdmin is the app controlling databases of your sites, so we are going to bulk delete posts directly from there). So enter in PhpMyAdmin and search the database of your WordPress site (usually there is one database for each one of your WordPress websites). Once found the database containing your website posts you will find there are many tables in it. You should click in the one named “wp_posts” or “wpkn_posts”. In that table you will find the list of your wordpress posts and their current status, if published, pending or draft.

click to enlarge

So let’s do some edit. Click on the button SQL from the menu at the top of the page (see previous image to find it).

So once clicked, run this code in the white table:

UPDATE wpkn_posts (or wp_posts) SET post_status = ‘publish’ WHERE post_status = ‘pending’

in the case you want to bulk publish many posts.

When you want to bulk delete many posts run this other code:

DELETE FROM wpkn_posts (or wp_posts) WHERE post_status = ‘pending’  (or ‘publish’, or ‘draft’)

Come tradurre un tema WordPress manualmente

Quasi tutti i temi WordPress con cui si ha a che fare sono impostati in lingua inglese, e quando si vuol metter su un sito in italiano si ci trova a fare i conti con tutte quelle frasi di navigazione che occorre tradurre (previous, next, by + autore, on + data di pubblicazione, related posts, etc etc etc).

Per cambiarli è necessario andare a prendere i file nella cartella del tema e tradurre i singoli spezzoni dall’inglese in lingua italiana. Per rendere questa operazione più semplice nei temi è solitamente presente un file POT, formato presentazione Power Point, per che elenca tutti i testi del sito e la locazione di quel testo all’interno dei file.

Se per esempio si vuole cambiare il testo “Related Posts”, una volta aperto il file POT troveremo che quel testo si trova nella pagina post.php alla riga numero n. In questo modo potremo subito modificare quella pagina inserendo la traduzione in italiano.

Per trovare il file POT basta andare sulla gestione file del vostro sito web (accessibile da cpanel>gestione file per la maggior parte degli hosting), e selezionare la cartella wp-content.

Da lì cliccare sulla cartella themes e poi fare clic sulla cartella del tema che volete tradurre. Quindi potete trovare il file POT nella cartella languages o alternativamente tra i file del wp-content.

 

Il file POT si presente come nell’immagine in basso. Viene indicata la locazione di riferimento, quindi la pagina (es. functions.php) e la riga dopo i due punti.

La stringa di testo corrispondente è quella che segue a msgid. Per effettuare la traduzione manualmente, cioè senza ricorrere alla creazione di un file PO) non bisognerà però editare questo documento, ma il file interessato, quindi recarci all’interno della pagina functions e modificare la linea di testo interessata.

 

How to store WordPress Post Content in to a PHP variable

If you are developing something with WordPress you may need to create a variable in which to insert the content of a post. Something like:

$content = ..post content..

Classic the_content() function just prints the content of the article but does not allow to save it as a variable, unless you use content buffer. On the other hand  the content can be easily stored into a variable using get_the_content() function, even if if it does not return the content in the same way the_content() does it, since text is unformatted.

You can call get_the_content() function even outside the loop using the global variable $post:

global $post;
$content = $post->post_content;
In so doing post content will be saved within the $content variable and will then be available to you when you want to use it.

Come creare un tema per WordPress in 5 minuti

Creare un tema per WordPress può sembrare difficile, ma in realtà il punto è che la grande parte del lavoro viene compiuta per creare l’aspetto grafico e qualche altro carattere meramente funzionale del tema. La sua creazione nei contenuti essenziali è realmente un procedimento molto veloce che ora vi farò vedere. WordPress, per prima cosa, gira su PHP. Il PHP ne gestisce l’aspetto esecutivo, mentre per gli elementi strutturali si usa l’HTML più il CSS per quelli grafici. HTML+CSS vengono inseriti nelle pagine PHP.

Creazione dei file

Apriamo quindi molto semplicemente 5 nuovi documenti sul blocco note del nostro computer: il primo lo chiamiamo “header.php”, il secondo “sidebar.php”, il terzo “footer.php”, il quarto “style.css” e infine il quinto “index.php”.

Header, Sidebar e Footer sono le parti del layout di una pagina: l’header è l’intestazione, la sidebar la barra laterale, mentre la footer è lo spazio in fondo alla pagina. Nel file index ci va scritto quello che comprarirà nella parte principale o main della pagina, quella dei contenuti.

Il foglio di stile

Il file “style.css” serve a comunicare a WordPress comandi grafici. In questo caso, il nostro tema è molto semplice e non dobbiamo inserirci nessun comando, solamente i dati obbligatori, cioè i dati del tema. Inseriamo quindi nel file “style.css” il seguente codice:

/*
Theme Name: Nome del Tema.
Theme URI: Indirizzo autore del sito
Description: Una breve descrizione
Version: 1.0
Author: Nome Autore
Author URI: Indirizzo del sito internet
*/

La pagina index e il loop degli articoli

I file header,sidebar e footer possono essere lasciati vuoti. In “index.php” inserite il seguente codice:

<?php get_header(); ?>

<?php get_sidebar(); ?>

<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<div id=”post-<?php the_ID(); ?>” <?php post_class(); ?>>
<div class=”post-header”>
<div class=”date”><?php the_time( ‘M j y’ ); ?></div>
<h2><a href=”<?php the_permalink(); ?>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></a></h2>
<div class=”author”><?php the_author(); ?></div>
</div><!–end post header–>
<div class=”entry clear”>
<?php if ( function_exists( ‘add_theme_support’ ) ) the_post_thumbnail(); ?>
<?php the_content(); ?>
<?php edit_post_link(); ?>
<?php wp_link_pages(); ?> </div>
<!–end entry–>
<div class=”post-footer”>
<div class=”comments”><?php comments_popup_link( ‘Leave a Comment’, ‘1 Comment’, ‘% Comments’ ); ?></div>
</div><!–end post footer–>
</div><!–end post–>
<?php endwhile; /* rewind or continue if all posts have been fetched */ ?>
<div class=”navigation index”>
<div class=”alignleft”><?php next_posts_link( ‘Older Entries’ ); ?></div>
<div class=”alignright”><?php previous_posts_link( ‘Newer Entries’ ); ?></div>
</div><!–end navigation–>
<?php else : ?>
<?php endif; ?>

<?php get_footer(); ?>

Questo codice inserito non è altro che l’inserimento dell’header e della sidebar, poi il loop (cioè il comando che dice a WordPress che in quel punto può far vedere gli articoli pubblicati) e infine l’inserimento della footer. In questo caso compariranno solo gli articoli pubblicati perchè in header, sidebar e footer non abbiamo messo nulla.

A questo punto il vostro sito è fatto. Potete quindi inserire questi cinque file in un unico file compresso e caricarlo su WordPress.

 

Best Sitemap WordPress Plugins for 2018

Creating a sitemap for your site is really important because doing this you’re telling Google what’s on your site. Then Google crawlers could scrape all pages in an easier and faster way. A sitemap is a simple file, in .xml or .html format (or even .gz.xml in the case of compressed sitemaps for large sites).

Not many people are familiar with editing this kind of files. Anyway, when you run a site with WordPress, there are plugins that can make the job for you, generating a sitemap for your site automatically, without any manual processing by your part.

What kind of sitemap to choose for your site

Before choosing which WordPress plugin you are going to add, you need to ask yourself what kind of sitemap your site needs. If it’s a site with a very low number of pages (<1000) you can opt for Google Sitemap BestWebSoft, a simple plugin that generates a single sitemap in .xml format (www.sitename.com/ sitemap.xml).

In the case of a site with a higher number of pages, it is advisable to install plugin that creates a sitemap with a tree structure (a single parent xml file that links to other sitemaps). A valid example is Google XML Sitemaps plugin.

A sitemap should not contain more than 50,000 pages. This is why sites with a large number of pages use compressed xml files (.gz.xml format). Best choise for doing this is All in One SEO Pack plugin, a well known SEO management tool for your site. (toghether with Yoast SEO). After All in One SEO Pack is installed, it is necessary to activate the Sitemap section and select “Create compressed sitemap”.

Come creare una sitemap per il nostro sito WordPress: i migliori plugin

Creare una sitemap per il proprio sito è davvero molto importante perchè permette ai crawler di Google di sapere quali pagine sono presenti sul nostro sito e indicizzarle in modo più facile e veloce. Una sitemap è un semplice file, in formato .xml o .html o ancora .gz.xml nel caso di sitemap compresse per siti con molte pagine.

Non tutti, a dire il vero, hanno dimestichezza a creare questo tipo di file.  Quando si gestisce un sito con WordPress però, ci sono dei plugin specializzati che creano una sitemap per il nostro sito automaticamente, senza alcun procedimento manuale da parte nostra.

Quale tipo di plugin scegliere per creare la sitemap del nostro sito

Prima di scegliere quale plugin installare è però necessario chiedersi di quale tipo di sitemap il nostro sito ha bisogno. Se si tratta di un sito con un numero di pagine molto basso, inferiore al migliaio, si può optare per Google Sitemap by BestWebSoft, un semplice plugin che genera una singola sitemap in formato .xml, accessibile all’indirizzo www.nomesito.com/sitemap.xml.

Nel caso di siti più grandi con un numero di pagine superiore al migliaio, è consigliabile optare per plugin che costruiscano sitemap a modo di directory, esempio più valido è Google XML Sitemaps  cioè un singolo file xml genitore che rimandi tramite dei link a sitemap figlie. Questa struttura è molto utile, soprattutto nel caso di siti più complessi.

Una sitemap solitamente non dovrebbe mai elencare più di 50.000 pagine. E’ per questo che siti con un numero di pagine superiori a questa cifra devono utilizzare una diversa soluzione per costruire la propria sitemap e inviarla a Google. Il plugin più idoneo per questo tipo di situazione è All in One SEO Pack, già noto come tool di gestione SEO per il proprio sito (insieme a Yoast SEO), ma capace anche di sviluppare sitemap. E’ necessario però prima attivare la sezione Sitemap, e una volta attivata cliccare alla voce “Sitemap” di All in One SEO Pack e selezionare i quadratini “Abilita indici della sitemap” e “Crea sitemap compressa”.

 

Come recuperare la password di WordPress senza nome utente nè e-mail

A volte può capitare di scordarsi la propria password di WordPress, problema che si può ricevere facilmente attraverso il modulo di recupero della pagina di accesso, ma come accedere se non si ci ricorda nemmeno del proprio nome utente o della password che abbiamo utilizzato quando ci siamo iscritti o quando abbiamo installato WordPress per gestire il nostro sito web?

Per fortuna in questi casi esiste una soluzione molto semplice raggiungibile direttamente dal pannello di controllo del nostro hosting, nella sezione dedicata alle installazioni WordPress, solitamente offerta da Softaculous all’interno dei control panels più comuni come cPanel, Plesk, Direct Admin, InterWorx e H-Sphere.

Accedere a WordPress tramite il pannello di controllo del proprio hosting

Tra le installazioni di WordPress correnti, compare, a destra del dominio, un’icona di profilo. Cliccando su di essa, si viene direttamente reindirizzati nella Bacheca del pannello di controllo, senza dover eseguire l’accesso con nome utente e password, nè dover recuperare la password tramite la pagina di recupero.

Una volta entrati nel pannello di controllo sarà possibile ricreare una nuova password all’interno della seazione “Utenti” alla voce “Il tuo Profilo” cliccando su “Genera Password“.

 

 

Str_replace that En Dash (or minus sign)! How to fix the problem when it’s not working

Building my first theme on WordPress I had been a very long time in to understand how to use str_replace function to change title of a page to remove all the words following another. This was approximately the string to change: i had name and surname of a specific person (John Doe) and what i wanted to do was to remove all the rest of the phrase.

Page Title:  John Doe Contact Page – Sitename

String i wanted to get as result after str_replace:  John Doe

So practically i had to get just “John Doe” from that page title. The easiest way i knew was to use str_replace function in PHP in the following way:

  • Getting the WordPress Title as a variable:

<?php

$string = get_the_title();
$replace = ” Contact Page – Sitename”;
$replacewith   = ” “;

?>

  • Then using str_replace to change the title and print the result:

<?php

$string = str_replace($replace, $replacewith, $string);

?>

Unfortunately first attempts didn’t working and the result i got was just the input string ($string) without any replacement. Then i just cruised on the internet and after failed attempts to understand why i didn’t get my hoped result I decided to try to remove just the last word of the input string to check str_replace function was actually working.

Input:  John Doe Contact Page – Sitename

String i wanted to get as result after str_replace:  John Doe Contact Page –

Well, it worked. So i realized that probably the issue was that dash in the middle of the title. To be honest I did not know it was called “dash”, I just used to call it “minus” and type it very simply using these keyword keys:

But, it was so. And i found there’s not just one dash but as many as 5 different types, two of which very very similar to each other. Wikipedia explain fairly clearly the difference between them.

So, you can figure out that figure dash and en dash are pretty similar each other, and they are also different from the minus sign (-) of the keyboard. Opening page source in the browser I got confirmation that in my case it was a endash, then sign was not show as itself but with HTML/XML numeric character reference &#8211; from which i could understand what it was.

At this point I repeated the str_replace on my string just not using the sign but the appropriate HTML/XML code (previously I was using “minus” sign).

This was the page title as well as it appeared on the browser:
John Doe Contact Page – Sitename

This was my wrong way to write it:
John Doe Contact Page – Sitename

The properly way to str_replace an endash sign:
John Doe Contact Page &#8211; Sitename