Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

multiple post sections with seo friendly filtering WordPress

  • SOLVED

Requirements:

Code and template/CPT/taxonomy/rewrite details to enable a Wordpress site with multiple sections containing posts. Posts should be possible to be browsed paginated, and filtered using SEO friendly urls - if possible, and without Multisite.

e.g.
example.com/blog/ - shows all posts in 'blog' section
example.com/blog/<postname> - single post
example.com/blog/date/yyyy/mm - posts by date
example.com/blog/author/<authorname> - posts by author
example.com/blog/category/<categoryname> - posts by category
example.com/blog/tag/<tagname> -posts by tag

example.com/news/<postname> - shows all posts in 'news' section
example.com/news/date/yyyy/mm - fposts by date
etc

example.com/page/subpage/blog3/<postname>
etc

-User should be able to select which blog to post to from the admin area.
-Code to generate links to the date/author/tags with total counts
-RSS feeds generated for posts

Answers (4)

2012-10-04

Arnav Joy answers:

create following files in your theme folder

index.php
archive.php
author.php
tag.php
category.php

and include following


<?php if(have_posts()) :?>
<?php while(have_posts()) : the_post();?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'theme' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h1>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
</article>
<?php endwhile;?>
<?php endif;?>

and in create a file named as single.php and include following

<?php if(have_posts()) :?>
<?php while(have_posts()) : the_post();?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'theme' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h1>
<div class="entry-summary">
<?php the_content(); ?>
</div><!-- .entry-summary -->
</article>
<?php endwhile;?>
<?php endif;?>


in archieve.php you can also include

<header class="page-header">
<h1 class="page-title">
<?php if ( is_day() ) : ?>
<?php printf( __( 'Daily Archives: %s', 'theme' ), '<span>' . get_the_date() . '</span>' ); ?>
<?php elseif ( is_month() ) : ?>
<?php printf( __( 'Monthly Archives: %s', 'theme' ), '<span>' . get_the_date( _x( 'F Y', 'monthly archives date format', 'theme' ) ) . '</span>' ); ?>
<?php elseif ( is_year() ) : ?>
<?php printf( __( 'Yearly Archives: %s', 'theme' ), '<span>' . get_the_date( _x( 'Y', 'yearly archives date format', 'theme' ) ) . '</span>' ); ?>
<?php else : ?>
<?php _e( 'Blog Archives', 'theme' ); ?>
<?php endif; ?>
</h1>
</header>


let me know if this what you want


w0rd comments:

Thank you, however, the key issue is having the posts in urls different from the permalink base, which then drills down by date/author/category/tag.
The code above would simply list posts and display the post date on the archive page, rather than a wp_get_archives functionality:
Author
FirstAuthor (1 posts) <--- links to /blog/author/FirstAuthor
SecondAuthor (5posts)
Date
2012
10 (5 posts) <--- links to /blog/2012/
09 (2 posts)
Category
Sales (1)
Products (4)

2012-10-04

Abdelhadi Touil answers:

Hi.
As I see what you want is already built in wordpress theme if you are using an equivalent theme, but there are something I can't understand in your question, I didn't understand what you mean by "section", I think it's not a category, because you said:
example.com/blog/category/<categoryname> - posts by category
and:
example.com/news/<postname> - shows all posts in 'news' section
So can you explain more please?


w0rd comments:



By 'section', I meant just a logically different part of a website, e.g. news posts, rather than blog posts

The category filter is just an arbitrary term to label that post as belonging to that category - like assigning a hierarchical taxonomy . It doesn't necessarily need to be the built in Wordpress 'category' type, and could be called anything else, like, say 'cat'.

As posts added via Post in admin all appear within the permalink base url structure, this is an issue for when you set permalink to:
/blog/%postname%

but would also like some posts accessible via
/news/%postname%
and
/news/date/2012/10 etc


Abdelhadi Touil comments:

So we can say you mean custom post type by section term? Sorry but I'm trying to understand to see If I can help you. Do you know any website has such sections you are talking about?


w0rd comments:

Thank you for replying. Yes, it's the kind of thing one can use a Custom Post Type for - Blog posts in a 'blog' CPT, News posts in a 'news' CPT. However, CPTs don't provide the built in qualities of a Post, specifically the ability to browse by date/tag/etc posts with a friendly url. Plus, I don't think custom post types are designed to recreate Post functionality, but rather Page content.


Abdelhadi Touil comments:

Have you tried this plugin:
http://wordpress.org/extend/plugins/custom-post-type-permalinks/

2012-10-04

Dbranes answers:

Have you tried the cpt plugins to setup the different sections (news/blog/...) ?

fx:

http://wordpress.org/extend/plugins/custom-post-type-ui/screenshots/

http://wordpress.org/extend/plugins/simple-custom-types/screenshots/

http://wordpress.org/extend/plugins/ultimate-post-type-manager/screenshots/



w0rd comments:

I do use Custom Post Type UI, but custom posts are contained within the permalink base, and don't have the required drilldown drilldown rewrite rules. Thanks.


Dbranes comments:


If you use the "custom post type ui" plugin, you can add "news" and "blog" as custom post types and then add custom taxonomies like "tag" and "category".

Then you can add your own drilldown with the following method

(you just have to save the permalinks when you change/add the rules):

Here is an example for "news":

function my_custom_rewrite_rules( $rules ) {
$newrules = array();

$newrules['news/tag/(.*)$'] = 'index.php?post_type=news&tag=$matches[1]';
$newrules['news/category/(.*)$'] = 'index.php?post_type=news&category=$matches[1]';
$newrules['news/date/([0-9]{4})/?$'] = 'index.php?post_type=news&year=$matches[1]';
$newrules['news/date/([0-9]{4})/?([0-9]{1,2})/?$'] = 'index.php?post_type=news&year=$matches[1]&monthnum=$matches[2]';
$newrules['news/date/([0-9]{4})/?([0-9]{1,2})/?([0-9]{1,2})/?$'] = 'index.php?post_type=news&year=$matches[1]&monthnum=$matches[2]&day=$matches[3]';

//debug
/*
echo "<pre>";
print_r($newrules + $rules);
echo "</pre>";
*/

return $newrules + $rules;
}
add_filter('rewrite_rules_array','my_custom_rewrite_rules');


the above rewrite should give you


http://example.com//news/category/sport/
http://example.com//news/tag/liverpool/
http://example.com//news/date/2011/11/05/
http://example.com//news/date/2011/11/
http://example.com//news/date/2011/



Dbranes comments:

you can uncomment the above debug code, to see all the current rewrite rules Wordpress is using - long but helpful list.

if you want I can add the pagination rules to the above rules?

What other drilldowns are you missing?


w0rd comments:

Hi,
It does seem like these rewrites are the way to go to solve the url issue.

It would be good to have the code to print links to the drilldown types with counts.

-I have paging working with this line:
$newrules['news/date/([0-9]{4})/page/?([0-9]{1,})?$'] = 'index.php?post_type=news&year=$matches[1]&paged=$matches[2]';


-Breaking out of the permalink structure is possible by:
with_front => false (an option left out of Custom Post Type UI)

Thanks

2012-10-04

Manoj Raj answers:

Hi,

From my understanding, you may need have a look at this plugin to control the permalinks

http://wordpress.org/extend/plugins/wp-htaccess-control/