• This my code
    function:

    
    <?php
    /* Special Offer Post */
    
    add_action('init', 'special_offers');
    function special_offers()
    {
      $labels = array(
        'name' => _x('special_offers', 'post type general name'),
        'singular_name' => _x('special_offer', 'post type singular name'),
        'add_new' => _x('Add New', 'special_offers'),
        'add_new_item' => __('Add New special_offers'),
        'edit_item' => __('Edit special_offers'),
        'new_item' => __('New special_offers'),
        'view_item' => __('View special_offers'),
        'search_items' => __('Search special_offers'),
        'not_found' =>  __('No special_offerss found'),
        'not_found_in_trash' => __('No special_offerss found in Trash'),
        'parent_item_colon' => ''
      );
      $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => true,
        'menu_position' => 6,
    	'_builtin' => false,
    	'menu_icon' => get_bloginfo('template_directory') . '/images/special-offer-icon.png',  // Icon Path
        'supports' => array('title','editor','thumbnail','custom-fields','cats' , 'brands')
      );
      register_post_type('special_offers',$args);
    }
    
    register_taxonomy( 'brands', 'special_offers', array( 'hierarchical' => true, 'label' => __('Brands'), 'query_var' => 'brands' ) );
    
    

    code for home page sidebar:

    
    <?php query_posts( array( 'brands' => 'Aspire Grand Café' ) ); ?>
    <?php if( is_tax() ) {
    global $wp_query;
    $term = $wp_query->get_queried_object();
    $title = $term->name;
    }?>	
    
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php the_post_thumbnail();?>
    <?php the_permalink();?>
    <?php the_title();?>
    <?php echo excerpt(25); ?>
    <?php endwhile; else: ?>
    <?php endif; ?>
    
    

    custom posts taxonomy single post page code ?

Viewing 7 replies - 1 through 7 (of 7 total)
  • There is a much easier and simpler way of doing this – just as an alternative. I install the Wordpres Pods plugin: https://podsframework.org/

    Create my custom post types. And then create a single page with a custom loop that calls the custom post types as follows:

    $wp_query = new WP_Query();
    	$wp_query->query(
    		array(
    			'post_type'=>'post_type',
    			'paged' => $paging,
    		)
    );

    And then I begin my page construction:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <h2 class="post-title"> "><?php the_title();?></h2>
    <p><?php $custom_fied = get_post_meta($post->ID, 'custom_field', true);?></p>
    //get all the custom fields
    </div>
    <?php endwhile; else: ?>
    <?php endif; ?>

    An that is it – all in under 3 minutes.

    Thread Starter Shihab Malayil

    (@shihabmalayil)

    Hi, Archie,
    Thank you for your replay.I can’t install external plugins.
    can you please, how can i show the post as single ?.

    I usually keep the post type script separate and simply call it in the functions.php

    Once that part is done, I will create a single-cutompage.php and within the page follow the instructions above:

    <?php
    $wp_querty = new WP_Query( array(
        'post_type'    => 'custompost' //you custom post name
        ,'post_status'  => 'publish'
    ) );
    ?>
    
    //the following section is similar to any single page piece of code
    //contruct your page
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <h2 class="post-title"> "><?php the_title();?></h2>
    <p><?php $custom_fied = get_post_meta($post->ID, 'custom_field', true);?></p>
    //get all the custom fields
    </div>
    <?php endwhile; else: ?>
    <?php endif; ?>
    Thread Starter Shihab Malayil

    (@shihabmalayil)

    Hi Archie,
    “I usually keep the post type script separate and simply call it in the functions.php “

    I also same path. (include)

    I put the code which you give me, in my single-custompage.php

    How can i mention single-custompage.php is dedicated to the post.
    like functions.php page

    -Thank You-

    <?php
    $wp_querty = new WP_Query( array(
        'post_type'    => 'custompost' //you custom post name
        ,'post_status'  => 'publish'
    ) );
    ?>

    That will only call custom post types from “custompost”

    The script above will run from your new template called (in this case: single-custompage.php).

    Thread Starter Shihab Malayil

    (@shihabmalayil)

    hI Archie,

    Still single page not working.
    when i click the link it’s going home page without content.

    This is my single-special_offers.php

    
    <?php
    $wp_querty = new WP_Query( array(
    'post_type'    => 'special_offers' //you custom post name
    ,'post_status'  => 'publish'
    ) );?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php the_title();?>
    <?php endwhile; else: ?>
    <?php endif; ?>
    
    

    is it correct ?.

    -Thank you-

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to make custom posts taxonomy single page ?’ is closed to new replies.