WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to list urls inside a category (2 posts)

  1. su1
    Member
    Posted 1 year ago #

    Hello,

    I'm trying to 301 redirect all of the posts of a category, but for this I need the urls of the posts in that category.

    I haven't found a quick way to do that, I've found solutions to get all the urls of my WordPress install but I can't get to modify them to display only urls from the posts in one category. This is the code to get all of the urls:

    <?php
    /*
    Template Name: List post links
    */
    $postID = $wpdb->get_col("
    	SELECT ID FROM $wpdb->posts
    	WHERE (post_type = 'post')
    	AND (post_status = 'publish')
    	AND (post_password = '')
    ");
    
    foreach($postID as $post_link) {
    	?>
    	<a href="<?php echo get_permalink($post_link); ?>"><?php echo get_the_title($post_link);?></a><br />
    	<?php
    }
    ?>

    Any idea?
    Thanks.

  2. su1
    Member
    Posted 1 year ago #

    Found it, put this in a file:

    <?php
    /*
    Template Name: List post links
    */
    
    // The Query
    query_posts( 'cat=<yourcategory>' );
    
    // The Loop
    while ( have_posts() ) : the_post();
    	echo '<li>';
    	the_permalink();
    	echo '</li>';
    endwhile;
    
    // Reset Query
    wp_reset_query();
    ?>

    upload to your wordpress theme folder, create a new page with this template and view the page. Don't forget to change <yourcategory> with your category.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.