• Resolved Upadesh

    (@upadeshs)


    Hello there. I have created the child theme, registed the CPT named ‘software’ and created the file single-software.php in child theme folder. I copied the code from single.php file available in quicksand theme folder and made few changes referring to the tutorials available in the internet. But I cannot see the post display in my locally hosted site. Please help me how to make it work. I hope I am editing the right file. Thank you in advance.
    Code I am using is:

     <!-- post-list -->
            <?php
                    $args = array( 'post_type' => 'software', 'post_status' => 'publish' );
                    $loop = new WP_Query( $args );
    				if( $loop->have_posts() ) :?>
                   <? while ( $loop->have_posts() ) : $loop->the_post();
        //      get_template_part('template-parts/content', 'single');
                get_template_part('template-parts/content', get_post_format());
                // If comments are open or we have at least one comment, load up the comment template.
                if (comments_open() || get_comments_number()) {
                    comments_template();
                }
            endwhile;
            ?> 
    • This topic was modified 6 years, 8 months ago by Upadesh.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Theme Author cafeserendipity21

    (@cafeserendipity21)

    Hello Upadesh,
    if you wanna create a custom post type, I would recommend to switch first to a WP standard theme, like Twenty Seventeen. If it doesn’t work there, it’s most likely an error in your code.

    Also, for getting started with CPT more easily, you can use a plugin like Custom Post Type UI. Havea look to this small tutorial: How to Create Custom Post Types in WordPress. I’ve just tried it out and it works also on Quicksand.
    If you still want to programm your own CPT, please ask on stackoverflow or another wordpress forum for developers.

    Hope that helps ??

    Thread Starter Upadesh

    (@upadeshs)

    Dear cafeserendipity21,
    Thank you for the help and I am great fan of your theme.

    As you suggested, I was able to make the post display the title and description, but there are still few of the custom fields that I want to display in the post. But, it was only possible by editing the quicksand/inc/template-tags.php of main theme. I don’t want to play with the main theme. So, please guide me how to make it workable by editing quicksand-child/inc/template-tags.php.

    I tried same with the Twenty Seventeen Child theme and it worked.

    Thanks in advance once again.

    Theme Author cafeserendipity21

    (@cafeserendipity21)

    Hello Upadesh,

    frankly speaking, I’m not a specialist in custom post types, but I’ve just tested it with a child-theme and here’s what I’ve done.

    copy single.php inside your child-theme directory and modify the while-loop, so it looks like:

    while ( have_posts() ) : the_post();
      //get_template_part('template-parts/content', get_post_format());
      if ( get_post_type() ):
    	get_template_part( 'template-parts/content', get_post_type() );
      else:
    	get_template_part( 'template-parts/content', get_post_format() );
      endif;
    ...
    endwhile;

    Create a folder named template-parts and copy template-parts/content.php inside. Rename it, to fit your custom post type, i.e. content-software.php

    Now you can modify the content to fit your needs, by renaming the function quicksand_the_entry_content() to quicksand_the_entry_content_software()

    Create this function inside your functions.php.

    if (!function_exists('quicksand_the_entry_content_software')) :
    	function quicksand_the_entry_content_software($class = 'entry-content') {
    		?> 
    		<div class="card-block quicksand-entry-content-software <?php echo esc_attr($class); ?>">
    			<div class="card-text">
    				<?php  the_content();  ?>
    			</div>
    		</div>
    		<?php
    		echo "publisher: : " . get_post_meta( get_the_ID(), 'publisher', TRUE ) . "<br>";
    		echo "created: : " . get_field( 'created');
    		?>
    		<!--displays page links for paginated posts (i.e. includes the 'nextpage')-->
    		<?php
    		quicksand_paginated_posts_paginator();
    	}
    endif;

    Here you can output your custom fields (get_field() is provided by the Advanced Custom Fields Plugin).

    Hope that helps ??

    Thread Starter Upadesh

    (@upadeshs)

    Dear cafeserendipity21,
    You are great. It worked like a charm :).
    I am in love with your theme and waiting for the future update of the theme. I hope we will soon get this theme with Bootstrap v4 final release.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to display custom post type?’ is closed to new replies.