• Resolved jjon

    (@jjon)


    I’ve been trying to get the “ReOrder Posts within Categories” plugin to work in custom category pages. My efforts were complicated by bug #11 which I duly reported, and @aurovrata has now fixed in v. 2.4.2. Well and good, but my problem, it turns out, did not stem from that issue. I found that I had some code in my child-theme functions.php file that was intended to make Modern Tribe’s “Events Calendar” plugin make use of the regular posts categories. That code:

    function wpa_categories_for_events(){
        register_taxonomy_for_object_type( 'category', 'tribe_events' );
        //register_taxonomy_for_object_type( 'category', 'page' );
    }
    add_action( 'init', 'wpa_categories_for_events' );
    
    function wpa_events_on_category_pages( $query ) {
        if ( $query->is_category() && $query->is_main_query() ) {
            $query->set( 'post_type', array( 'post', 'tribe_events' ) );
        }
    }
    add_action( 'pre_get_posts', 'wpa_events_on_category_pages' );

    was interfering with the operations of the “ReOrder Posts” plugin. Once I removed the offending code, the “ReOrder Posts” plugin functioned fine (hooray!); however, it functions only on stock category pages generated by WP.

    I have made several custom category pages. I started with the archive.php file in the twentyseventeen theme. I added a header image and some fixed text at the top, and then the loop populates the page with the relevant posts (an example is linked). I named these files category-category-slug.php as recommended, and now requests for (for example) https://williamcoulterguitar.com/category/bill-brian/ will invoke my custom page. (the php for that modified archive page is appended below) This is very much “monkey see, monkey do” programming. My acquaintance with the WP codebase and PHP is pretty shallow. I’m just fumbling around, learning as I go.

    Unfortunately, the order of posts on these modified archive pages is not affected by the operation of the ReOrder plugin. My question (for the unlikely few who are still reading this tldr ramble) is this: is there any way to modify these custom archive pages such that they will respect the ordering of posts as imposed by the ReOrder plugin?

    <?php
    /**
     * The template for displaying archive pages
     *
     * @link https://developer.www.ads-software.com/themes/basics/template-hierarchy/
     *
     * @package WordPress
     * @subpackage Twenty_Seventeen
     * @since 1.0
     * @version 1.0
     */
    
     add_filter( 'posts_orderby' , 'custom_cpt_order' );
     function custom_cpt_order( $orderby ) {
     	global $wpdb;
    
     	// Check if the query is for an archive
     	if ( is_archive() && get_query_var("post_type") == "my_custom_post_type" ) {
     		// Query was for archive, then set order
     		return "$wpdb->posts.post_title ASC";
     	}
    
     	return $orderby;
     }
    
    get_header(); ?>
    
    <div class="single-featured-image-header">
    	<!--<img image parameters, src etc. >-->
    </div>
    <div class="wrap">
    
    	<?php if ( have_posts() ) : ?>
    		<header class="page-header">
    			<?php
    				the_archive_title( '<h1 class="page-title">', '</h1>' );
    				the_archive_description( '<div class="taxonomy-description">', '</div>' );
    			?>
    		</header><!-- .page-header -->
    	<?php endif; ?>
    
    	<div id="primary" class="content-area">
    		<main id="main" class="site-main" role="main">
    			<div class="category-top-matter">
    				<!-- descriptive text -->
    			</div>
    		<?php
    		if ( have_posts() ) :
    		?>
    			<?php
    			/* Start the Loop */
    			while ( have_posts() ) : the_post();
    
    				/*
    				 * Include the Post-Format-specific template for the content.
    				 * If you want to override this in a child theme, then include a file
    				 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
    				 */
    				get_template_part( 'template-parts/post/content', get_post_format() );
    
    			endwhile;
    
    			the_posts_pagination(
    				array(
    					'prev_text'          => twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '<span class="screen-reader-text">' . __( 'Previous page', 'twentyseventeen' ) . '</span>',
    					'next_text'          => '<span class="screen-reader-text">' . __( 'Next page', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ),
    					'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyseventeen' ) . ' </span>',
    				)
    			);
    
    		else :
    
    			get_template_part( 'template-parts/post/content', 'none' );
    
    		endif;
    		?>
    
    		</main><!-- #main -->
    	</div><!-- #primary -->
    	<?php get_sidebar(); ?>
    </div><!-- .wrap -->
    
    <?php
    get_footer();
    • This topic was modified 4 years, 12 months ago by jjon. Reason: code formatting?

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Aurovrata Venet

    (@aurovrata)

    in your page code you have at the top of the page,

    add_filter( 'posts_orderby' , 'custom_cpt_order' );

    This will interfere with the ordering of your posts. The ReOrder plugin uses the posts_where/posts_join/posts_orderby filters to modify your queries and returns your posts in the right order.

    Thread Starter jjon

    (@jjon)

    Thanks @aurovrata, without that code (that’s the trouble with monkeying around when you don’t know what you’re doing) the posts on my category pages now do respond to the ordering set by the plugin; however, I’m getting weirdly inconsistent results. With one category the posts are ordered as I set them in the plugin. The posts are presented top to bottom in the front-end as they are ordered left to right in the plugin’s admin page. But in another category page, the order is reversed: the posts are displayed top to bottom in the front end as they appear right to left in the plugin’s admin page.

    As I say, weird! Except for the header image and the introductory text, the templates for these two pages is identical.

    I’m at a loss.

    Plugin Author Aurovrata Venet

    (@aurovrata)

    In your admin reorder page the first question asked if whether to sort this term manually on the front end. Make you select ‘yes’ (see screenshot #2), else your admin ranked posts will not be applied to your front end

    Thread Starter jjon

    (@jjon)

    Yes, thanks, that much is clear. But I still see some odd behavior:

    1. I went in today to make further changes and found that the reorder grid was not responsive to the mouse at all. Inspector showed there were no drag events attached to draggable-objects except for the first one, and I could not select or drag any of them. Nothing was reported in debug.log. Logged out, and back in: no change. Nothing seemed to work, so I killed the browser, and everything else, and rebooted. Returning to the site, I found it working, so I suspect there’s some sort of js/dom, or caching problem somewhere.
    2. When the site was working again, I found the same peculiar ordering problem: posts for a category on the front end were ordered as defined in the admin page. I reordered the posts on the admin page in the reverse of the desired order, ie. with the topmost post rightmost in the grid. Then I checked the front end, and posts were in the desired order. I returned to the admin page and found that the posts are now ordered as expected with the top post leftmost in the grid.
    Thread Starter jjon

    (@jjon)

    A pity. This plugin represents useful functionality, but I simply cannot get consistent results from it. Even the results I’ve described above cannot be made regular. Sometimes it works, mostly it doesn’t. I guess I’ll have to go back to editing the publish dates for my posts to get the order I want in the category pages. *alas*

    Plugin Author Aurovrata Venet

    (@aurovrata)

    went in today to make further changes and found that the reorder grid was not responsive to the mouse at all. Inspector showed there were no drag events attached to draggable-objects except for the first one.

    this could be caused by a javascript conflict, inspect the console to see if any errors are showing.

    I reordered the posts on the admin page in the reverse of the desired order, ie. with the topmost post rightmost in the grid. Then I checked the front end, and posts were in the desired order. I returned to the admin page and found that the posts are now ordered as expected with the top post leftmost in the grid.

    not sure what the 2nd issue is, posts in the admin are odered left to right down if you have multiple rows.

    Thread Starter jjon

    (@jjon)

    I did inspect the console carefully, and no relevant errors are recorded. Likewise the php debug.log: no relevant errors. The plugin simply doesn’t work most of the time, until, seemingly at random, it does work but gets the order wrong anyway.

    After no end of aggravation with the newest version, I followed advice to downgrade to an older version of the plugin. I installed v1.8.1, and this worked flawlessly in my use case. I think I rather like the draggable list items better than the draggable tiles anyway. Thanks @aurovrata for a very useful plugin.

    Plugin Author Aurovrata Venet

    (@aurovrata)

    I did inspect the console carefully, and no relevant errors are recorded.

    very strange. Drop me a note on vrata at syllogic dot in if you want to get to the bottom of this.

    Plugin Author Aurovrata Venet

    (@aurovrata)

    with several bugs fixes in recent releases and having not heard back from you, I am assuming this issue now resolved.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘custom category page does not respect ReOrder of posts’ is closed to new replies.