I wanted a list of all wordpress posts in a single lists. I used the plugin “List category posts” by Fernando Briano which worked as described but I had to add each category. If new categories were added it involved updating the page.
I posed the problem to ChatGPT and through a number of iterations arrived at this plugin.
Listing of all Wordpress Posts Plugin Code
<?php
/*
Plugin Name: List Posts by Category
Description: A simple plugin to list posts grouped by category using a shortcode.
Version: 1.0
Author: AnythingAccess.com
Author URI: https://AnythingAccess.com
*/
function list_posts_by_category_with_summary() {
$categories = get_categories(array(
'hide_empty' => true, // Only retrieve categories with posts
));
$output = '';
// Generate the summary of categories with post counts and links
$output .= '<h4>Category Summary</h4>';
$output .= '<ul>';
foreach ($categories as $category) {
$output .= '<li><a href="#' . esc_attr($category->slug) . '"><strong>' . esc_html($category->name) . '</strong></a> (' . $category->count . ' posts)</li>';
}
$output .= '</ul>';
// Generate the detailed list of posts by category
foreach ($categories as $category) {
$output .= '<h5 id="' . esc_attr($category->slug) . '">' . esc_html($category->name) . '</h5>';
$posts = get_posts(array(
'category' => $category->term_id,
'numberposts' => -1, // Retrieve all posts in the category
));
if ($posts) {
$output .= '<ul>';
foreach ($posts as $post) {
$output .= '<li><a href="' . get_permalink($post->ID) . '">' . esc_html($post->post_title) . '</a></li>';
}
$output .= '</ul>';
}
}
return $output;
}
add_shortcode('list_posts_by_category', 'list_posts_by_category_with_summary');
By ading the shotcode “list_posts_by_category” on any page it will list the posts summary and hyperlink to the details as shown below.
Category Summary
- Access (11 posts)
- Accounting (3 posts)
- Agresso (1 posts)
- ChatGPT (4 posts)
- Design (2 posts)
- ETL (9 posts)
- Excel (3 posts)
- Outlook (1 posts)
- Ribbon (1 posts)
- Sage (1 posts)
- SAP (3 posts)
- SQL (3 posts)
- VBA (11 posts)
- Wordpress (5 posts)
Access
- Offline Club Lotto Automation
- Dynamic Report Heading in an Access Report
- Access Startup on Distributed Applications
- Access UI Design
- How to Use Oracle's ALL_TAB_COLUMNS to Recreate Tables in Microsoft Access: A Step-by-Step Guide
- Deploying Access Databases
- Application Deployment
- Checking the References in an Access Database
- Nomenclature
- Importing Data into Access
- Working with Ribbons
Accounting
- Auto Unzipping Files and Loading of Excel Files
- SAP โ Changing the format of downloaded files
- Agresso Budget Loading from Excel
- Creating SEPA Files
- SAP BOM Upload
- Sage Invoice Loading
Agresso
ChatGPT
- Track Your Application Usage
- Export a List of Posts from Wordpress
- Listing all Wordpress Posts
- Software Listing
Design
ETL
- Dynamic Report Heading in an Access Report
- Application Deployment
- Preserving Excel Comments Across versions
- Auto Unzipping Files and Loading of Excel Files
- Loading Files from a Folder
- Altova Mapforce
- Importing Data into Access
- Working with CSV Files
- Viewing XML Files
Excel
Outlook
Ribbon
Sage
SAP
- Auto Unzipping Files and Loading of Excel Files
- SAP โ Changing the format of downloaded files
- SAP BOM Upload
SQL
- Access UI Design
- How to Use Oracle's ALL_TAB_COLUMNS to Recreate Tables in Microsoft Access: A Step-by-Step Guide
- Using Passthrough query in Access
VBA
- Track Your Application Usage
- Printing Receipts to a Sewoo from VBA
- Offline Club Lotto Automation
- Access Startup on Distributed Applications
- Clean QR Code Generator
- Deploying Access Databases
- Application Deployment
- Checking the References in an Access Database
- Using Passthrough query in Access
- Preserving Excel Comments Across versions
- Importing Data into Access