Automatically list wp posts

You can list automatically wordpress posts in your php webpage, based on its tags.

The following php code allow you to list all wp posts with a given tag:

<?php

// --- 1️⃣ Caricamento WordPress (solo se non già caricato) ---
if (!function_exists('get_posts')) {
    $possible_paths = [
        __DIR__."/../[your-wp-path]/wp-load.php",  // standard
        __DIR__."/../../[your-wp-path]/wp-load.php", // if you inclyde subfolders
    ];
    foreach ($possible_paths as $path) {
        if (file_exists($path)) {
            require_once($path);
            break;
        }
    }
}

// --- 2️⃣ Preparazione query ---
global $post;
$args = [
    'posts_per_page' => 200,
];

if (!empty($whatcategory)) {
    $args['category_name'] = $whatcategory; // category slug 
}
if (!empty($whattag)) {
    // $args['tag'] = $whattag; 
    $args['tag_slug__in'] = array_map('trim', explode(',', $whattag)); // tag slug (not shown names)
}

// --- 3️⃣ Cache opzionale (transient WordPress) ---
$cache_key = 'lista_blog_' . ($whatcategory ?? 'none') . '_' . ($whattag ?? 'none');
$myposts = get_transient($cache_key);

if ($myposts === false) {
    $myposts = get_posts($args);
    set_transient($cache_key, $myposts, 3600); // cache 1 ora
}

// --- 4️⃣ Output ---
if (!empty($myposts)) {
    echo '<h2>
        <span lang="en">Our blog posts about this topic</span>
        <span lang="it">Posts del nostro blog su questo tema</span>
    </h2>
    <ul id="blog-posts">';

    foreach ($myposts as $post) {
        // Non dipendiamo dal loop globale
        echo '<li><a href="'.get_permalink($post).'" rel="bookmark">'.get_the_title($post).'</a></li>';
    }

    echo '</ul>';
    wp_reset_postdata();
}
?>

You can put this code in a separate file, and include it in your php webpage, i.g. in the footer, with a code like the following:

<?php
$listablog = "[the-path-of-your-separate-file/the-name-of-your-separate-file";
  if (file_exists($listablog)) {
    if (
        (isset($whatcategory) && !empty($whatcategory)) ||
        (isset($whattag) && !empty($whattag))
    ) {
        include $listablog;
    }
  }
?>

In the header of a webpage where you want add this list, you have to set the value of the tag you want list:
$whattag="your tag,another tag";

Be careful: you has to set, as value, not the visualized tag name, but the “slug”. You can see it also with mouse hover and status bar.

MTP problems (android – PC cable connection)

If you cannot connect your PC with an android device via usb cable, check first if your mobile device has mtp (media transfert protocol) set, and not charging or other USB possibilities.

In Likebook, for example, you have to set as in the following image:

Of course, you should have also installed all the needed MTP libraries.

copyq problems

In you have linux, flatpack installation of copyq can solve many possible problems, but it has also some disadvantage.

The best choice, then, is to install copyq according to its website:

Ubuntu and Debian users can add the official PPA:

sudo add-apt-repository ppa:hluk/copyq
sudo apt update && sudo apt install copyq

In same cases it could be not enough the above code. Then you can try with something like:

QT_QPA_PLATFORM=xcb copyq

You can set permanently in KDE menu with a config like in the below image