Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

Loading posts (and custom posts) on homepage

$
0
0

Replies: 0

I want to display 3 posts on the homepage of my website. I don’t think the widget is the best approach though as I want to display them in the same format they’re on the actually post page with image, meta data, heading and excerpt.

I thought I’d be able to duplicate the code and dump it on the homepage but that doesn’t seem to work and I’d still need to limit the amount of posts.

Apologies if this isn’t the right code/the code you need to make a call on this, but I think this is my post list code:


<!-- article -->
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

	<!-- post thumbnail -->
	<?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
		<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
			<?php the_post_thumbnail(array(120,120)); // Declare pixel size you need inside the array ?>
		</a>
	<?php endif; ?>
	<!-- /post thumbnail -->

	<!-- post title -->
	<h2>
		<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
	</h2>
	<!-- /post title -->

	<!-- post details -->
	<span class="date"><?php the_time('F j, Y'); ?> <?php the_time('g:i a'); ?></span>
	<span class="author"><?php _e( 'Published by', 'html5blank' ); ?> <?php the_author_posts_link(); ?></span>
	<span class="comments"><?php if (comments_open( get_the_ID() ) ) comments_popup_link( __( 'Leave your thoughts', 'html5blank' ), __( '1 Comment', 'html5blank' ), __( '% Comments', 'html5blank' )); ?></span>
	<!-- /post details -->

	<?php html5wp_excerpt('html5wp_index'); // Build your custom callback length in functions.php ?>

	<?php edit_post_link(); ?>

</article>
<!-- /article -->

Also, I have a custom post type that I also want to pull into the homepage. Another problem I have this this is setting a parent page for it. If I create a post I can see there is an index page but I don’t know how to set this in the main nav?

In my functions.php I have the follow which looks like it creates the Custom Post Type:


function create_post_type_html5()
{
    register_taxonomy_for_object_type('category', 'html5-blank'); // Register Taxonomies for Category
    register_taxonomy_for_object_type('post_tag', 'html5-blank');
    register_post_type('html5-blank', // Register Custom Post Type
        array(
        'labels' => array(
            'name' => __('HTML5 Blank Custom Post', 'html5blank'), // Rename these to suit
            'singular_name' => __('HTML5 Blank Custom Post', 'html5blank'),
            'add_new' => __('Add New', 'html5blank'),
            'add_new_item' => __('Add New HTML5 Blank Custom Post', 'html5blank'),
            'edit' => __('Edit', 'html5blank'),
            'edit_item' => __('Edit HTML5 Blank Custom Post', 'html5blank'),
            'new_item' => __('New HTML5 Blank Custom Post', 'html5blank'),
            'view' => __('View HTML5 Blank Custom Post', 'html5blank'),
            'view_item' => __('View HTML5 Blank Custom Post', 'html5blank'),
            'search_items' => __('Search HTML5 Blank Custom Post', 'html5blank'),
            'not_found' => __('No HTML5 Blank Custom Posts found', 'html5blank'),
            'not_found_in_trash' => __('No HTML5 Blank Custom Posts found in Trash', 'html5blank')
        ),
        'public' => true,
        'hierarchical' => true, // Allows your posts to behave like Hierarchy Pages
        'has_archive' => true,
        'supports' => array(
            'title',
            'editor',
            'excerpt',
            'thumbnail'
        ), // Go to Dashboard Custom HTML5 Blank post for supports
        'can_export' => true, // Allows export in Tools > Export
        'taxonomies' => array(
            'post_tag',
            'category'
        ) // Add Category and Post Tags support
    ));
}

I hope that helps you, help me 😉 It’s all very new to me.

Will the Custom Post Type also use the same code as the default Post type? I’ll need different classes on it so I was wondering if I’ll need to use a different template.


Viewing all articles
Browse latest Browse all 59525

Trending Articles