• This is a bit complicated and I maybe overthinking it. Please help me if you can. Please read over completely …its kinda complicated. And thank you very much for any help!!!!

    We have category pages where each post is a business listing. I have set up a cross-pagination randomizer that works beautifully. Here is the code for that:

    session_start();
    add_filter( 'posts_orderby', 'randomise_with_pagination' );
    function randomise_with_pagination( $orderby ) {
    	if( is_category( $category )  ) {
    	  	// Reset seed on load of initial archive page
    		if( ! get_query_var( 'paged' ) || get_query_var( 'paged' ) == 0 || get_query_var( 'paged' ) == 1 ) {
    			if( isset( $_SESSION['seed'] ) ) {
    				unset( $_SESSION['seed'] );
    			}
    		}
    	
    		// Get seed from session variable if it exists
    		$seed = false;
    		if( isset( $_SESSION['seed'] ) ) {
    			$seed = $_SESSION['seed'];
    		}
    	
    	    	// Set new seed if none exists
    	    	if ( ! $seed ) {
    	      		$seed = rand();
    	      		$_SESSION['seed'] = $seed;
    	    	}
    	
    	    	// Update ORDER BY clause to use seed
    	    	$orderby = 'RAND(' . $seed . ')';
    	}
    	return $orderby;
    }

    Now what I need is to be able to pin multiple posts to the top of each category. These are paid for listings that need to go first – prefer to have them just on the first page although if all of them show at the top of every page that would be okay too.

    I have tried pinning these posts but they randomize with the rest of the posts.

    I have tried using the plugin Sticky Posts in Category however it will only allow one post to be pinned to the top of the category page.

    I would just code the posts onto the category but we also want these paid for posts to randomize among themselves.

    I thought I could just create a different “premium” category and them display on the top of these pages – and this is what I am posting this here – I cannot find the code to style them with I found this code:

    <?php 
    $args = array ( 'category' => ID, 'posts_per_page' => 10);
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :	setup_postdata($post);
     ?>
    //Style Posts here
    <?php endforeach; ?>

    I need to replace //Style Posts here with the code necessary to display the posts properly. On most themes you can just go to the post index and find this. However this is what is displayed on Customizr post index:

     <?php while ( have_posts() ) : ##all other cases for single and lists: post, custom post type, page, archives, search, 404 ?>
                                    <?php the_post(); ?>
    
                                    <?php do_action ('__before_article') ?>
                                        <article <?php czr_fn__f('__article_selectors') ?>>
                                            <?php do_action( '__loop' ); ?>
                                        </article>
                                    <?php do_action ('__after_article') ?>
    
                                <?php endwhile; ?>

    Or this

     <?php if ( have_posts() && ! is_404() ) : ?>
                                <?php while ( have_posts() ) : ##all other cases for single and lists: post, custom post type, page, archives, search, 404 ?>
                                    <?php the_post(); ?>
    
                                    <?php do_action ('__before_article') ?>
                                        <article <?php czr_fn__f('__article_selectors') ?>>
                                            <?php do_action( '__loop' ); ?>
                                        </article>
                                    <?php do_action ('__after_article') ?>
    
                                <?php endwhile; ?>
    
                            <?php endif; ##end if have posts ?>

    Neither one displays any posts.

    I am having trouble finding where the posts are styled…. help!

    I may work on some randomzir javascript and place the posts code in a list…but I would rather use WordPress’s posts than hard coding it in place…just seems a junky way to do it.

    Any help appreciated. My understanding of HTML, CSS, Javascript is good but much less so for PHP. I usually rely on plugins to do what I want. I wish Sticky Posts in Category worked or could be tweaked to work….

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

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Displaying category posts from another category on a category page’ is closed to new replies.