WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Issue (2 posts)

  1. welshhuw
    Member
    Posted 3 years ago #

    Hi,

    I cannot get my custom posts to show for some reason, Can some one please help!

    Here is my functions.php code:

    //Custom Post Types
    add_action('init', 'product_register');
    
            function product_register() {
            $args = array(
                    'label' => __('For Sale'),
                    'singular_label' => __('forsale'),
                    'public' => true,
                    'show_ui' => true,
                    'capability_type' => 'post',
                    'hierarchical' => false,
                    'rewrite' => true,
                            'menu_icon' => 'http://example.com/images/for-sale-icon.png',
                    'supports' => array('title', 'editor')
            );
    
            register_post_type( 'forsale' , $args );
            }

    Here is my custom template file:

    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    
                            <h2><?php the_title(); ?></h2>
    
                            <div id="fb"><a href="http://www.facebook.com/pages/pontlottyn-mid-glamorgan/South-Wales-Customs/139115299461925"><img alt="South Wales Customs Facebook Page" src="<?php bloginfo('template_directory'); ?>/images/fb.png" /></a></div>
    
                            <h3><?php the_title(); ?></h3>
                            <?php the_content(); ?>
    
                            <?php $loop = new WP_Query( array( 'post_type' => 'forsale', 'posts_per_page' => 100 ) ); ?>
                                    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
                                            <?php endwhile; ?>
    
                            <div class="clear"></div>
                            <p><a href="contactus.html"><img alt="South Wales Motorcycle Mot Centre" src="<?php bloginfo('template_directory'); ?>/images/mot-banner.png" /></a></p>
    
                    </div><!--content-->
    
    <?php endwhile; ?>

    Please can someone help!!

  2. MichaelH
    Member
    Posted 3 years ago #

    At the least, after this line:

    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

    you would need to display the necessary info such as:

    echo $loop->post->post_title;

Topic Closed

This topic has been closed to new replies.

About this Topic