• Resolved HaneD

    (@haned)


    I’m going insane. I’m busy writing my first plugin and using custom post types. I have basically gotten everything to work except for the page navigation. I have read everything that I could find but I still haven’t gotten it to work.

    I use a shortcode to display the post content and I got paging to work on that but when I set the page as the landing page navigation doesn’t word. The page only refreshes with the same info.

    Here is how the custom post type is registered:

    /* Set up the post types */
    add_action( 'init', 'exc_agriq_equipment_register_post_types' );
    
    /* Registers the post type */
    function exc_agriq_equipment_register_post_types() {
    	register_post_type( 'exc_agriq_equipment',
    		array(
    			'labels' => array(
    				'name' => __( 'Equipment' ),
    				'singular_name' => __( 'Equipment' ),
    				'add_new' => __( 'Add New Equipment' ),
    				'add_new_item' => __( 'Add New Equipment' ),
    				'edit' => __( 'Edit' ),
    				'edit_item' => __( 'Edit Equipment' ),
    				'new_item' => __( 'New Equipment' ),
    				'view' => __( 'View Equipment' ),
    				'view_item' => __( 'View Equipment' ),
    				'search_items' => __( 'Search Equipment' ),
    				'not_found' => __( 'No Equipment found' ),
    				'not_found_in_trash' => __( 'No Equipment found in Trash' ),
    			),
    			'public' => true,
    			'show_in_nav_menus' => false,
    			'show_ui' => true,
    			'publicly_queryable' => true,
    			'exclude_from_search' => false,
    			'hierarchical' => false,
    			'capability_type' => 'post',
    			'query_var' => true,
    			//'rewrite' => false,
    			'has_archive' => true,
    			'supports' => array('title', 'editor'),
    			'rewrite' => array( 'slug' => 'exc', 'with_front' => true),
    		)
    	);
    }

    This is the shortcode

    <?php
    //Add thickbox files
    function add_themescript(){
    		$agriquip_plugin_url = plugins_url('agriquip', '__FILE__');
        wp_enqueue_script('jquery');
        wp_enqueue_script('thickbox',null,array('jquery'));
        wp_enqueue_style('thickbox.css', '/'.WPINC.'/js/thickbox/thickbox.css', null, '1.0');
    	wp_enqueue_script('exc-equal-heights', $agriquip_plugin_url. '/js/equal-heights.js',array('jquery'));
    }
    
    add_action('init','add_themescript');
    
    //Add css files
    add_action('wp_head', 'agriquip_style' );
    
    function agriquip_style()
      {
      $agriquip_plugin_url = plugins_url('agriquip', '__FILE__');
      echo '<link rel="stylesheet" href="'.$agriquip_plugin_url.'/css/agriquip.css" type="text/css" />';
      }
    
    //Register equipment shortcode
    add_shortcode( 'equipment', 'exc_agriq_equipment_shortcode' );
    
    //The callback function that will replace [equipment]
    function exc_agriq_equipment_shortcode() {
    ?>
    <script type="text/javascript">
    jQuery(document).ready(
    
    	function() {
    		//Equal columns
        jQuery(".equalHeights").equalHeights();
        }
    );
    
    </script>
    <?php
     echo "<ul class='equalHeights'>";
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $loop = new WP_Query( array(
          'post_type' => 'exc_agriq_equipment',
          'posts_per_page' => 16,
          'paged'=>$paged,
        )
    		);
    	//$loop = new WP_Query( array( 'post_type' => 'exc_agriq_equipment', 'posts_per_page' => 16, 'paged' => $paged ) );
    
            while ( $loop->have_posts() ) : $loop->the_post(); 
    
    				$exc_agriq_year = get_post_meta( get_the_ID(), 'exc_agriq_equipment_year', true );
    				$exc_agriq_hours = get_post_meta( get_the_ID(), 'exc_agriq_equipment_hours', true );
    				$exc_agriq_price = get_post_meta( get_the_ID(), 'exc_agriq_equipment_price', true );
    				$exc_agriq_kw = get_the_term_list( get_the_ID(), 'exc_equipment_kw', '', ', ', '');
    
    				?>
    				<li class="agriq-equipment-container">
    					<div class="agriq-equipment-detail">
    						<?php
    						$images = get_post_meta(get_the_ID(), 'exc_agriq_equipment_images', false);
    						$excagriqID = get_the_ID();
    
    						echo "<div class='agrig-equipment-images'>";
                foreach ($images as $att) {
                  // get image's source based on size, can be 'thumbnail', 'medium', 'large', 'full' or registed post thumbnails sizes
                  $srcthumb = wp_get_attachment_image_src($att, 'thumbnail');
                  $srcthumb = $srcthumb[0];
    							$src = wp_get_attachment_image_src($att, 'full');
                  $src = $src[0];
    
                  // show image
                  echo "<div class='agriq-equipment-image'><a href='$src' class='thickbox' rel='". $excagriqID ."'><img src='$srcthumb' width='150px' height='150px'/></a></div>";
    						}
    						?>
    						</div>
    						<div class="agriq-equipment-title"><h4><?php echo the_title(); ?></h4></div>
    						<div class="agriq-equipment-description"><?php echo the_content(); ?></div>
    						<div class="agriq-equipment-kw"><span>Kw:</span> <?php echo $exc_agriq_kw; ?></div>
    						<div class="agriq-equipment-year"><span>Jaar:</span> <?php echo $exc_agriq_year; ?></div>
    						<div class="agriq-equipment-hours"><span>Ure:</span> <?php echo $exc_agriq_hours; ?></div>
    						<div class="agriq-equipment-price"><span>Prys:</span> R<?php echo $exc_agriq_price; ?> BTW Ingesluit</div>
    					</div>
    				</li>
    
    				<?php
            endwhile;
    				echo "</ul>";
    				if (function_exists("pagination")) {
        pagination($loop->max_num_pages);
    		}
    }
    
    ?>

    As soon I get this sorted I can start with the paging for the taxonomies.

    Help would be greatly appreciated

Viewing 1 replies (of 1 total)
  • Thread Starter HaneD

    (@haned)

    I got this sorted

    Here is the new shortcode’s code

    //Register equipment shortcode
    add_shortcode( 'equipment', 'exc_agriq_equipment_shortcode' );
    
    //The callback function that will replace [equipment]
    function exc_agriq_equipment_shortcode() {
    ?>
    <script type="text/javascript">
    jQuery(document).ready(
    
    	function() {
    		//Equal columns
        jQuery(".equalHeights").equalHeights();
        }
    );
    
    </script>
    <?php
     echo "<ul class='equalHeights'>";
    
    		$paged = 1;
       	if ( get_query_var('paged') ) $paged = get_query_var('paged');
        if ( get_query_var('page') ) $paged = get_query_var('page');
        $i = 0;
        $wp_query = new WP_Query( array(
          'post_type' => 'exc_agriq_equipment',
          'posts_per_page' => 16,
          'paged'=>$paged,
        )
    		);
    
            while ( $wp_query->have_posts() ) : $wp_query->the_post(); 
    
    				$exc_agriq_year = get_post_meta( get_the_ID(), 'exc_agriq_equipment_year', true );
    				$exc_agriq_hours = get_post_meta( get_the_ID(), 'exc_agriq_equipment_hours', true );
    				$exc_agriq_price = get_post_meta( get_the_ID(), 'exc_agriq_equipment_price', true );
    				$exc_agriq_kw = get_the_term_list( get_the_ID(), 'exc_equipment_kw', '', ', ', '');
    
    				?>
    
    				<li class="agriq-equipment-container">
    					<div class="agriq-equipment-detail">
    						<?php
    						$images = get_post_meta(get_the_ID(), 'exc_agriq_equipment_images', false);
    						$excagriqID = get_the_ID();
    
    						echo "<div class='agrig-equipment-images'>";
                foreach ($images as $att) {
                  // get image's source based on size, can be 'thumbnail', 'medium', 'large', 'full' or registed post thumbnails sizes
                  $srcthumb = wp_get_attachment_image_src($att, 'thumbnail');
                  $srcthumb = $srcthumb[0];
    							$src = wp_get_attachment_image_src($att, 'full');
                  $src = $src[0];
    
                  // show image
                  echo "<div class='agriq-equipment-image'><a href='$src' class='thickbox' rel='". $excagriqID ."'><img src='$srcthumb' width='150px' height='150px'/></a></div>";
    						}
    						?>
    						</div>
    						<div class="agriq-equipment-title"><h4><?php echo the_title(); ?></h4></div>
    						<div class="agriq-equipment-description"><?php echo the_content(); ?></div>
    						<div class="agriq-equipment-kw"><span>Kw:</span> <?php echo $exc_agriq_kw; ?></div>
    						<div class="agriq-equipment-year"><span>Jaar:</span> <?php echo $exc_agriq_year; ?></div>
    						<div class="agriq-equipment-hours"><span>Ure:</span> <?php echo $exc_agriq_hours; ?></div>
    						<div class="agriq-equipment-price"><span>Prys:</span> R<?php echo $exc_agriq_price; ?> BTW Ingesluit</div>
    					</div>
    				</li>
    
    				<?php
    				$i++; endwhile;
    				echo "</ul>";
    
    				if ( function_exists( 'wp_pagenavi' ) ) {
            	wp_pagenavi( array( 'query' => $wp_query ) );
            	wp_reset_postdata();
        		}
    
    }
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Custom Post Paging (Page Navigation)’ is closed to new replies.