• I’m wanting to list posts by category id and then alphabetically, for example category-4.php would have

    A
    Apples Destroys Microsoft

    B
    Batman Destroys Joker

    WP-Snap! is not what I’m looking for, I need everything on one page instead of letter pages like WP-Snap! does it. Thanks.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Note: I’ve deleted your duplicate forum posts on this topic. In the future, do not post multiple times on the same issue.

    For your request, take a look at the Custom Query String plugin found here:

    https://www.transycan.net/blogtest/download-themes/

    You can set it to sort posts by title, even on just specific categories if you wish.

    Thread Starter invisionblue

    (@invisionblue)

    That doesn’t do what I’m looking for, it just does the samething this does <?php query_posts(‘showposts=-1&orderby=title&order=ASC’); ?>

    That would work if it showed a big bold alphabet letter before it begins each title section. Any other plugins you might know of or custom coding? Thanks for the help so far.

    I know of no plugin that does this. However, some custom coding:

    https://wordpress.pastebin.com/f524c9f4

    Version that only displays letter heading when one or more posts fall under it:

    https://wordpress.pastebin.com/f2302b7cb

    Thread Starter invisionblue

    (@invisionblue)

    Okay I placed the following code in category.php

    <?php
    
    $posts = new WP_Query("cat=$cat&orderby=title&order=ASC&showposts=-1");
    if ($posts->have_posts()) :
    	for($i='A';$i!='AA';$i++) :
    ?>
    <?php
    		while ($posts->have_posts()) :
    			$posts->the_post();
    			if( $i == strtoupper(trim(substr($post->post_title, 0, 1))) ) :
    				if( !$a_z_header ) :
    					$a_z_header = 1;
    ?>
    <h3 id="<?php echo $i; ?>"></a><?php echo $i; ?></h3>
    	<ul>
    <?php
    				endif;
    ?>
    	<li><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
    <?php
    			endif;
    		endwhile;
    ?>
    	</ul>
    <?php
    		$a_z_header = 0;
    	endfor;
    endif;
    ?>

    And got the following errors:

    WordPress database error: [Table ‘vgarchives.wp_categories’ doesn’t exist]
    SELECT cat_ID FROM wp_categories WHERE category_nicename = ‘xbox’

    Warning: Cannot modify header information – headers already sent by (output started at /home/content/s/h/o/shockon/html/vgarchives/wp-includes/wp-db.php:160)

    What version of WordPress are you running?

    Thread Starter invisionblue

    (@invisionblue)

    2.3.1 the latest one.

    Thread Starter invisionblue

    (@invisionblue)

    Okay now it’s sort of working. https://www.vgarchives.com/category/xbox/ gives you one error https://vgarchives.com/category/xbox/ gives you two errors.

    Couple issues:

    1. The categories table *doesn’t* exist in 2.3. It was around in 2.2 and previous, but was replaced with the terms table (more or less). See here:

    https://boren.nu/archives/2007/08/26/wordpress-23-taxonomy-schema/

    2. My code doesn’t do anything more than adopt the query as it already exists in WordPress. Do you have any queries occurring in your template(s) outside what I provided? Any category-related plugins?

    Thread Starter invisionblue

    (@invisionblue)

    Nope I don’t have any other category plugins or queries inside of category.php

    What would have to be done for the code you gave me to work properly? I’m not much of an mysql expert so I don’t really know what to edit in the code but what you gave me is what I’m looking for exactly minus the errors of course.

    Thread Starter invisionblue

    (@invisionblue)

    Ahh it works now! ?? I had the custom query plugin turned on, I turned it off and boom it works perfect now! Thanks for the help on this, things should run smooth even on new upgrades of wordpress correct?

    things should run smooth even on new upgrades of wordpress correct?

    As long as the WP_Query class isn’t greatly overhauled (unlikely for the time being) or the global $cat is removed (again unlikely, but you never know about our WP devs… :} ).

    Thread Starter invisionblue

    (@invisionblue)

    Alright thanks, I now have everything working properly as you can see https://www.vgarchives.com/category/xbox/ when you click on a letter the game will appear. Thanks and have a nice Christmas.

    arstuavitamea

    (@arstuavitamea)

    i need help to make a query to have post listed Alphabetically by a custom field (eg. Surname)

    thiis is the query i use to sort the post normally ORDERBY Surname..

    $querystr = "
    SELECT * FROM $wpdb->posts
    LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
    LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
    LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    WHERE $wpdb->term_taxonomy.term_id = 42
    AND $wpdb->term_taxonomy.taxonomy = 'category'
    AND $wpdb->posts.post_status = 'publish'
    AND $wpdb->postmeta.meta_key = 'surname'
    ORDER BY $wpdb->postmeta.meta_value ASC
    ";
    
     $pageposts = $wpdb->get_results($querystr, OBJECT);

    my dream is to add a line with all letters A-Z where to click and filter by that letter (wp-snap style)

    thanks in advance

    CODE IS POETRY
    SIMPLE CODE IS ART

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Lists Posts Alphabetically’ is closed to new replies.