WordPress.org

Ready to get started?Download WordPress

Forums

Custom Home Page Loop with Featured Content Gallery (3 posts)

  1. D C
    Member
    Posted 3 years ago #

    Was wondering if anyone could direct me how to create a custom loop for just my home page? I am trying to add Featured Content Gallery to my home page using the Graphene theme.

    I have found an answer to the question (sort of) here.

    But the Graphene theme uses an action hook I'm not very familiar with (my knowledge of php is just enough to be dangerous). Here's what the index.php file looks like:

    <?php
    /**
     * The main template file.
     *
     * This is the most generic template file in a WordPress theme
     * and one of the two required files for a theme (the other being style.css).
     * It is used to display a page when nothing more specific matches a query.
     * E.g., it puts together the home page when no home.php file exists.
     * Learn more: http://codex.wordpress.org/Template_Hierarchy
     *
     * @package WordPress
     * @subpackage Graphene
     * @since Graphene 1.0
     */
    
    get_header(); ?>
    
    	<?php
        /* Run the loop to output the posts.
         * If you want to overload this in a child theme then include a file
         * called loop-index.php and that will be used instead.
         */
         get_template_part('loop', 'index');
        ?>
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    Then here's what loop.php looks like:

    <?php if (have_posts()) : ?>
    	<?php while (have_posts()) : the_post(); ?>
                <div id="post-<?php the_ID(); ?>" <?php post_class('clearfix post'); ?>>
    
                	<?php /* Posts navigation for single post pages, but not for Page post */ ?>
                    <?php if (is_single() && !is_page()) : ?>
                	<div class="post-nav clearfix">
                        <p id="previous"><?php previous_post_link(); ?></p>
                        <p id="next-post"><?php next_post_link(); ?></p>
                        <?php do_action('graphene_post_nav'); ?>
                    </div>
                    <?php endif; ?>
    
                    <?php /* Post date is not shown if this is a Page post */ ?>
                    <?php if (!is_page() && (get_option('graphene_hide_post_date') != true)) : ?>
                    <div class="date">
                        <p class="default_date"><?php the_time('M'); ?><br /><span><?php the_time('d') ?></span></p>
                        <?php do_action('graphene_post_date'); ?>
                    </div>
                    <?php endif; ?>
    
                    <div class="entry clearfix<?php if (get_option('graphene_hide_post_date') == true) {echo ' nodate';} ?>">
    
                    	<?php /* Post title */ ?>
                        <h2 class="post-title">
                        	<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(esc_attr__('Permalink to %s', 'graphene'), the_title_attribute('echo=0')); ?>"><?php if (get_the_title() == '') {_e('(No title)','graphene');} else {the_title();} ?></a>
                        <?php do_action('graphene_post_title'); ?>
                        </h2>
    
    					<?php /* Post meta */ ?>
                        <div class="post-meta clearfix">
    
    						<?php /* Post category, not shown if this is a Page post or if admin decides to hide it */ ?>
                            <?php if (!is_page() && (get_option('graphene_hide_post_cat') != true)) : ?>
                            <ul class="meta_categories">
                                <li><?php the_category(",</li>\n<li>") ?></li>
                            </ul>
                            <?php endif; ?>
    
                            <?php /* Post author, not not shown if this is a Page post or if admin decides to hide it */ ?>
                            <?php if (get_option('graphene_hide_post_author') != true) : ?>
                            <p class="post-author">
    							<?php
    								if (!is_page()) {
    									/* translators: this is for the author byline, such as 'by John Doe' */
    									_e('by','graphene'); echo ' '; the_author_posts_link();
    								}
    								edit_post_link(__('Edit post','graphene'), ' (', ')');
    
    								/* Show the post author's gravatar if enabled */
    								if (get_option('graphene_show_post_avatar') && !is_page()) {
    									echo get_avatar(get_the_author_meta('user_email'), 40);
    								}
    							?>
                            </p>
                            <?php endif; ?>
    
                            <?php do_action('graphene_post_meta'); ?>
                        </div>
    
                        <?php /* Post content */ ?>
                        <div class="entry-content clearfix">
                        	<?php do_action('graphene_before_post_content'); ?>
    
                        	<?php if (!is_search() && !is_archive() && (!get_option('graphene_posts_show_excerpt') || is_single() || is_page())) : ?>
                            <?php the_content(__('Read the rest of this entry &raquo;','graphene')); ?>
                            <?php else : ?>
                            	<?php the_excerpt(); ?>
                            <?php endif; ?>
                            <?php wp_link_pages(array('before' => __('<p><strong>Pages:</strong> ','graphene'), 'after' => '</p>', 'next_or_number' => 'number')); ?>
    
                            <?php do_action('graphene_after_post_content'); ?>
    
                        </div>
    
                        <?php /* Post footer */ ?>
                        <div class="entry-footer clearfix">
                        	<?php /* Display the post's tags, if there is any */ ?>
                            <?php if (!is_page() && (get_option('graphene_hide_post_tags') != true)) : ?>
                            <p class="post-tags"><?php if (has_tag()) {_e('Tags:','graphene'); the_tags(' ', ', ', '');} else {_e('This post has no tag','graphene');} ?></p>
                            <?php endif; ?>
    
    						<?php
    							/**
    							 * Display AddThis social sharing button if single post page, comments popup link otherwise.
    							 * See the graphene_addthis() function in functions.php
    							*/
    						?>
                            <?php if (is_single() || is_page()) : ?>
                                <?php graphene_addthis(get_the_ID()); ?>
                            <?php elseif (get_option('graphene_hide_post_commentcount') != true && comments_open()) : ?>
                            	<p class="comment-link"><?php comments_popup_link(__('Leave comment','graphene'), __('1 comment','graphene'), __("% comments",'graphene')); ?></p>
                            <?php endif; ?>
    
                            <?php do_action('graphene_post_footer'); ?>
                        </div>
                    </div>
                </div>
                <?php
    			/**
    			 * Display the post author's bio in single-post page if enabled
    			*/
    			if (is_single() && get_option('graphene_show_post_author')) :
    			?>
                <h4 class="author_h4"><?php _e('About the author', 'graphene'); ?></h4>
                <div class="author clearfix">
                    <?php
                    if (get_the_author_meta('graphene_author_imgurl')) {
                        echo '<img class="avatar" src="'.get_the_author_meta('graphene_author_imgurl').'" alt="" />';
                    } else {
                        echo get_avatar(get_the_author_meta('user_email'), 100);
                    }
    				?>
                    <p class="author_name"><strong><?php the_author_meta('display_name'); ?></strong></p>
                    <p class="author_bio"><?php the_author_meta('description'); ?></p>
    
                </div>
                <?php endif; ?>
    
                <?php
    			/**
    			 * Display Adsense advertising for single post pages
    			 * See graphene_adsense() function in functions.php
    			*/
    			?>
                <?php if (is_single() || is_page() || (is_front_page() && get_option('graphene_adsense_show_frontpage')) || is_archive() || is_search()) {graphene_adsense();} ?>
    
                <?php /* Get the comments template for single post pages */ ?>
                <?php if (is_single() || is_page()) {comments_template();} ?>
    
    	<?php endwhile; ?>
    
        <?php /* Display posts navigation if this is not a single post page */ ?>
        <?php if (!is_single()) : ?>
            <?php /* Posts navigation. See functions.php for the function definition */ ?>
        	<?php graphene_posts_nav(); ?>
        <?php endif; ?>
    
    <?php /* If there is no post, display message and search form */ ?>
    <?php else : ?>
        <div class="post">
            <h2><?php _e('Not found','graphene'); ?></h2>
            <div class="entry-content">
                <p>
    			<?php
    				if (!is_search())
    					_e("Sorry, but you are looking for something that isn't here. Wanna try a search?","graphene");
    				else
    					_e("Sorry, but no results were found for that keyword. Wanna try an alternative keyword search?","graphene");
    			?>
    
                </p>
                <?php get_search_form(); ?>
            </div>
        </div>
    
        <?php do_action('graphene_not_found'); ?>
    <?php endif; ?>
    
    <?php do_action('graphene_bottom_content'); ?>

    If I wanted the Featured Content Gallery Code <?php include (ABSPATH . '/wp-content/plugins/featured-content-gallery/gallery.php'); ?> to show the FCG only on the home page and within the content area (not the header) would I have to create a new home.php file and include that in the loop somehow? Or should I put it in the loop somewhere before the content?

    Thanks in advance

  2. yelenak
    Member
    Posted 3 years ago #

    To show it only on home page use this:

    <?php
    if(is_home() || is_front_page())
    {
      global $post;
    include (ABSPATH . '/wp-content/plugins/featured-content-gallery/gallery.php');
    }
    ?>

    and you can add it to the header.php file before or after this
    <?php do_action('graphene_top_content'); ?>

  3. yelenak
    Member
    Posted 3 years ago #

    in header.php file

Topic Closed

This topic has been closed to new replies.

About this Topic