예쁜 영구 링크 목록 및 게시 제목 내보내기
WordPress에서 해당 포스트 제목과 함께 예쁜 영구 링크 목록을 내보낼 방법을 찾고 있습니다.shortlink가 아닌 정의된 실제 permalink 구조를 찾습니다.꼭 해야 한다면 짧은 링크를 사용해야 할 것 같습니다만, 완전한 퍼머링크를 선호합니다.
여기 당신이 웹 사이트의 루트에 저장할 수 있는 독립 실행형 PHP 파일이 있습니다./export.php
브라우저로 호출하면 예쁜 퍼멀링크, 투고 제목, 투고 타입(보너스)이 포함된 탭으로 둘러싸인 일반 텍스트 목록이 전송됩니다.
브라우저에서 URL을 로드한 후 텍스트 파일에 "이름 지어 저장"하면 Excel로 로드할 수 있습니다.
<?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 "\n{$post->post_type}\t{$permalink}\t{$post->post_title}";
}
이게 도움이 됐으면 좋겠다.
마이크
추신: 표준 워드프레스를 사용했습니다.WP_Query()
또한 SQL을 대신 사용하는 것이 더 좋거나 필요할 경우에 대비하여 주석으로 표시한 SQL도 포함되었습니다.
오늘 아침 EE에서 이 질문에 답했습니다.http://wp.daveheavyindustries.com/2011/02/08/wordpress-permalink-via-sql/
이 쿼리로 충분합니다.
SELECT wpp.post_title,
wpp.guid,
wpp.post_date,
CONCAT
(
wpo_su.option_value,
REPLACE
(
REPLACE
(
REPLACE
(
REPLACE
(
wpo.option_value,
'%year%',
date_format(wpp.post_date,'%Y')
),
'%monthnum%',
date_format(wpp.post_date, '%m')
),
'%day%',
date_format(wpp.post_date, '%d')
),
'%postname%',
wpp.post_name
)
) AS permalink
FROM wp_posts wpp
JOIN wp_options wpo
ON wpo.option_name = 'permalink_structure'
AND wpo.blog_id = 0
JOIN wp_options wpo_su
ON wpo_su.option_name = 'siteurl'
AND wpo_su.blog_id = wpo.blog_id
WHERE wpp.post_type = 'post'
AND wpp.post_status = 'publish'
ORDER BY wpp.post_date DESC
저도 이 솔루션을 원했습니다.오리지널 솔루션에 대해 @MikeSchinkle에게 감사드립니다.이 링크를 플레인텍스트로 내보낸 후 리다이렉트목록을 작성하기 위해 사용했습니다.
그러나, 그 후, 액티브한 라이브 링크의 솔루션도 필요하게 되었습니다.
그래서 제가...wp_query
게시물 유형 "any"를 사용하여 다음 쿼리에 포함된 검색 양식이 포함된 페이지 템플리트를 작성했습니다(주제에 맞게 선택).주의: 이 설정은posts_per_page
-1로 설정하면 결과가 무제한으로 반환됩니다."Title - Permalink" (제목 - Permalink) 라는 결과가 반환됩니다.
<?php
$type = 'any';
$args = array (
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => -1,
'order' => 'DESC',
);
$temp = $wp_query; // assign ordinal query to temp variable for later use
$wp_query = null;
$wp_query = new WP_Query($args);
if ( $wp_query->have_posts() ) :
while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>
<?php the_title(); ?> - <a href="<?php the_permalink() ?>" rel="bookmark" title="View The <?php the_title_attribute(); ?>"><?php the_permalink() ?></a><br />
<?php endwhile; ?>
<?php else :
echo '<h2>Sorry, we didnt find any results to match. Please search again below or call us at 800-828-4228 and we will be happy to help!</h2>';
get_search_form();
endif;
$wp_query = null;
$wp_query = $temp; // Reset
?>
그것이 다른 사람들에게 도움이 되길 바랍니다.
언급URL : https://stackoverflow.com/questions/3464701/export-list-of-pretty-permalinks-and-post-title
'source' 카테고리의 다른 글
각진 '='의 의미는 무엇입니까?JS 지시 격리 범위 선언? (0) | 2023.03.20 |
---|---|
Typescript 인터페이스 기본값 (0) | 2023.03.20 |
ng-repeat 내에서 ng-click에 의해 호출되는 할당식 동작 (0) | 2023.03.20 |
리액트 리덕스 접속 컴포넌트를 유닛 테스트하는 방법 (0) | 2023.03.20 |
Gson - 동일한 필드 이름, 다른 유형 (0) | 2023.03.20 |