Forums

Another question about categories (14 posts)

  1. lindafar
    Member
    Posted 2 years ago #

    When a user clicks on a category link, I'd like to have the posts ordered alphabetically by post title rather than chronologically as seems to be its default.

    (I don't mean the category list, that is already ordered alphabetically just the way I want.)

    Is this possible?

    Many thanks for suggestions!
    (and Happy Mother's Day!!!)

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    You'd need to use something like:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'orderby' => 'title',
    	'paged' => $paged
    );
    query_posts($args);
    ?>

    in your theme's category template.

    http://codex.wordpress.org/Function_Reference/query_posts#Orderby_Parameters

    (And thank you - although Mother's Day was almost 2 months ago for some of us...)

  3. lindafar
    Member
    Posted 2 years ago #

    Thanks for your help, time to go study the codex!

  4. lindafar
    Member
    Posted 2 years ago #

    Another solution, for those who like me have limited coding knowledge, is the plug-in WP Post Sorting.

    http://wordpress.org/extend/plugins/wp-post-sorting/

  5. t-p
    Member
    Posted 2 years ago #

    Hi esmi,

    You'd need to use something like:... in your theme's category template.

    In WP default theme, which file that would be?

    I would like to implement this (i was searching for something like this!).

    Thanks esmi.

  6. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    In the default theme, copy archive.php and name the new file category.php. Then add your new custom query to this new file.

  7. t-p
    Member
    Posted 2 years ago #

    Thanks esmi,

    I copied archive.php and named it category.php

    I do not know where exactly to place this code in the category.php

    I tried placing your code below this line but it did not do the trick
    <?php if (have_posts()) : ?>

    please guide. thanks esmi.

  8. khiangte
    Member
    Posted 2 years ago #

    Hi ESMI

    would be glad if you can help me out,

    <?php
    // Plugin Name: test test test
    ?>
    <?php
    
    function create_table()
       {
    	  global $wpdb;
    	  $table_name = $wpdb->prefix."test";
    	 if($wpdb->get_var("show tables like '$table_name'") != $table_name){
    		  $myquery = "CREATE TABLE ".$table_name." (
    					   ID mediumint(10) NOT NULL AUTO_INCREMENT,
    					   name VARCHAR(20) NOT NULL,
    				       UNIQUE KEY ID (ID)
    					   );";
    		require_once(ABSPATH. '/wp-admin/includes/upgrade.php');
    		dbDelta($myquery);
    	 }
    	}
    register_activation_hook( _FILE_,'create_table');
    
    ?>

    I can activate this plugin, but it does not create a table at all,
    When activate this plugin "register_activation_hook( _FILE_,'create_table');" should call create_table, isn't it?

  9. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    @khiangte: Don't highjack another poster's thread. Please post a new topic.

  10. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    @t-p: Try adding it just before the start of the Loop.

  11. t-p
    Member
    Posted 2 years ago #

    Thanks esmi,

    Try adding it just before the start of the Loop.

    please pardon me for my ignorance of the subject. Where is the start of the loop?

    I tried placing immediately before and after
    <?php if (have_posts()) : ?>

    I still see posts exactly as in their default state.

    Thanks again esmi.

    Edit: regardless if place the code before or after <?php if (have_posts()) : ?>, these are the results:
    1. posts show up with title and all the contents
    2. posts are indexed from Z-A instead of A-Z.

  12. t-p
    Member
    Posted 2 years ago #

    Hi esmi,

    I played around with it little bit more.

    I added 'order'=> 'ASC', to your code.

    And if I place the code before <?php if (have_posts()) : ?>

    I see all post in ascending alphabetic order.

    But i still cannot figure out how to get the post with their title ONLY. The it is now, the entire post is listed along with the title. But I would like to see only the title.

    please guide. Thanks esmi.

  13. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Remove <?php the_content();?> from that template file.

  14. t-p
    Member
    Posted 2 years ago #

    Thanks esmi.
    That worked. Appriciate your help .

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags