Skip to content
WJunction - Webmaster Forum

Wordpress A-Z

Status
Not open for further replies.
Is possible to add A-Z list above posts in categories and to sort posts in every category individually.

example;
browse.jpg
 
Last edited:

7 comments

HERE IS THE SOLUTION
Coded & tested by me

You need to Update your theme category.php file with below code [Read the instruction]


Code:
<[COLOR=#ff0000]ul[/COLOR] class="[COLOR=#0000cd]sort-posts[/COLOR]">
<[COLOR=#ff0000]p[/COLOR] class="[COLOR=#0000cd]title2[/COLOR]">Search post titles by Alpahbet :- 
         <?php 
$arry = array(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z);
            foreach ( $arry as $arrypost ) 
            {
?>
<a href="?sort=<?php echo $arrypost;?>" style="padding:3px"><?php echo $arrypost;?></a>
<?php
}
global $sort;
$sort= $_GET['sort'];
$category = get_category( get_query_var( 'cat' ) );
$cat_id = $category->cat_ID;
wp_set_post_terms();
         global $wpdb; 
         $results = $wpdb->get_results(
                "SELECT * FROM $wpdb->posts LEFT JOIN wp_term_relationships ON $wpdb->posts.ID = wp_term_relationships.object_id WHERE post_title LIKE '$sort%' AND post_type = 'post' AND post_status = 'publish' AND term_taxonomy_id = '$cat_id';"
         ); 
         if (!empty($sort)){
         if ( $results ) 
         {?>
                         <u><h2><?php echo $sort;?></h2></u>
           <?php foreach ( $results as $post ) 
            {
                setup_postdata ( $post ); 
                ?></[COLOR=#ff0000]p[/COLOR]>
                <li style="list-style:none">
<a href="<?php the_permalink();?>"><?php the_title();?></a>
                </li>
                <?php 
            }
         } 
         else 
         {
            ?> 
            <div class="[COLOR=#0000cd]alert[/COLOR]">No title Found with letter: <?php echo $sort;?></div>
            <?php
         }
         }
         else{
         ?>
    </[COLOR=#ff0000]ul[/COLOR]> 
    <[COLOR=#800000]div[/COLOR]>
[COLOR=#008000]    <!-- Default content CODE of your Category Php -->[/COLOR]
    </[COLOR=#800000]div[/COLOR]>
<?php } ?>

PS-
Dont use by default permalink setting of wordpress (ie ?p=123)
Change your Permalink setting some thing like /%category%/%postname%/
 
Thank you :))

I managed put code but im getting No title Found with all letters

you can check here:
Code:
[URL]http://test2013.hostoi.com/category/test/[/URL]

I'm not very good with WP..
 
Last edited:
on your category
Code:
http://test2013.hostoi.com/category/pc/

there is a post with this permalink
Code:
http://test2013.hostoi.com/[COLOR=#0000cd]pc/wj/[/COLOR]

on hovering 'w' letter [from "Search post titles by Alpahbet :-"]
below link appears
Code:
http://test2013.hostoi.com/[COLOR=#0000cd][U]category[/U]/pc/[/COLOR]?sort=w
(there is no need of that 'category' word)


so we can see there is a difference in your permalink; post using sitename/pc whether that sort link using sitename/category/pc

that should be cause of permalink setting ,
change it to /%category%/%postname%/
 
It's now working but when i click on letter it loose style

eh.jpg


site;
Code:
[URL]http://romsarea.com/category/uncategorized/[/URL]
 
Last edited:
Status
Not open for further replies.

About the author

Z
Active Member · Joined
935
Messages
2
Reactions
18
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom