• Resolved su1

    (@su1)


    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.

Viewing 1 replies (of 1 total)
  • Thread Starter su1

    (@su1)

    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.

Viewing 1 replies (of 1 total)
  • The topic ‘How to list urls inside a category’ is closed to new replies.