导出漂亮的永久链接列表和帖子标题

Export list of pretty permalinks and post title(导出漂亮的永久链接列表和帖子标题)
本文介绍了导出漂亮的永久链接列表和帖子标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在寻找一种方法来导出 WordPress 中带有相应帖子标题的漂亮永久链接列表.寻找定义的实际永久链接结构而不是短链接.我想如果必须的话,我会使用一个短链接,但我更喜欢完整的永久链接.

Looking for a way to export a list of pretty permalinks in WordPress with the corresponding post title. Looking for the actual permalink structure defined not the shortlink. I suppose if I have to, I will use a short link, but I prefer the full permalink.

推荐答案

这是一个独立的 PHP 文件,您可以将其保存到您网站的根目录中,名为 /export.php 之类的内容,当您调用它时使用您的浏览器,它会发送一个制表符分隔的纯文本 帖子列表,其中包含漂亮的永久链接、帖子标题和(作为奖励)帖子类型.

Here's a standalone PHP file you can save into the root of your website called something like /export.php and when you call it with your browser it will send a tab-delimited plain text list of posts with the pretty permalink, the post title and (as a bonus) the post type.

只需在您的浏览器中加载 URL,然后另存为"到一个文本文件中,然后您就可以在 Excel 中加载或以其他方式处理它.

Just load the URL in your browser and then "save as" to a text file you can then load in Excel or however else you need to process it.

<?php

include "wp-load.php";

$posts = new WP_Query('post_type=any&posts_per_page=-1&post_status=publish');
$posts = $posts->posts;
/*
global $wpdb;
$posts = $wpdb->get_results("
    SELECT ID,post_type,post_title
    FROM {$wpdb->posts}
    WHERE post_status<>'auto-draft' AND post_type NOT IN ('revision','nav_menu_item')
");
*/

header('Content-type:text/plain');
foreach($posts as $post) {
    switch ($post->post_type) {
        case 'revision':
        case 'nav_menu_item':
            break;
        case 'page':
            $permalink = get_page_link($post->ID);
            break;
        case 'post':
            $permalink = get_permalink($post->ID);
            break;
        case 'attachment':
            $permalink = get_attachment_link($post->ID);
            break;
        default:
            $permalink = get_post_permalink($post->ID);
            break;
    }
    echo "
{$post->post_type}	{$permalink}	{$post->post_title}";
}

希望这会有所帮助.

-迈克

附言我使用了标准的 WordPress WP_Query(),但也包含了一个注释掉的 SQL,以防您更喜欢(或需要)使用它.

P.S. I used the standard WordPress WP_Query() but also included a commented-out SQL in case you prefer (or need) to use it instead.

这篇关于导出漂亮的永久链接列表和帖子标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)