• Resolved skjha

    (@skjha)


    I am using twenty twelve “featured posts” for my front page. The front page is here. It looks the way I want, except I only want sticky posts to show. (Currently I only have one sticky post. The second post is in a category “news” and is not sticky.)

    I changed a child version of the style.css and modified a child version of content.php to get the featured post to look and say what I want. But from what I’ve read in the codex about how templates are applied, I think the front page is using index.php to display everything else. (I tried switching to a static front page, but can’t make it look the way I want.)

    Can anyone tell me these things:
    1. Since I think index.php is applied to more than just the front page – is that where I tell it not to display anything but sticky posts on the front page – or do I use a different template?
    2. Can I do something to this code from the child content.php that will only affect the front page?

    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    		<?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
    		<div class="featured-post">
    			<?php _e( 'Call now for your Siesta Key vacation reservations: 941-349-0545.', 'twentytwelve' ); ?>
    		</div>
    		<?php endif; ?>
    		<header class="entry-header">
    			<?php the_post_thumbnail(); ?>
    			<?php if ( is_single() ) : ?>
    			<h1 class="entry-title"><?php the_title(); ?></h1>
    			<?php else : ?>
    			<h1 class="entry-title">
    				<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'twentytwelve' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
    			</h1>

    Thank you so much for any help anyone can offer. I’ve been on this for two days and the more I read, the more confused I am getting.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter skjha

    (@skjha)

    I hope I fixed this by changing the content of my index.php to the following:

    get_header(); ?>
    
    	<div id="primary" class="site-content">
    		<div id="content" role="main">
    <?php
                            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                            $args= array(
                                    'category_name' => 'vacation', // Change this category SLUG to suit your use; or see for query parameters https://codex.www.ads-software.com/Class_Reference/WP_Query#Parameters
                                    'paged' => $paged
    );
                            query_posts($args);
                            if( have_posts() ) :?>
    
                            <?php while ( have_posts() ) : the_post(); ?>
                                    <?php get_template_part( 'content', get_post_format() ); ?>
                                    <?php comments_template( '', true ); ?>
                            <?php endwhile; // end of the loop. ?>
    
                            <?php twentytwelve_content_nav( 'nav-below' ); ?>
    
                            <?php else : ?>
                            <article id="post-0" class="post no-results not-found">
                                    <header class="entry-header">
                                            <h1 class="entry-title"><?php _e( 'Nothing Found', 'twentytwelve' ); ?></h1>
                                    </header>
                                    <div class="entry-content">
                                            <p><?php _e( 'Apologies, but no results were found. Perhaps searching will help find a related post.', 'twentytwelve' ); ?></p>
                                            <?php get_search_form(); ?>
                                    </div><!-- .entry-content -->
                            </article><!-- #post-0 -->
    
                            <?php endif; wp_reset_query(); ?>
    
                    </div><!-- #content -->
            </div><!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    From all appearances, it is working. I don’t know if changing the index.php in twenty twelve will cause other problems. If anyone knows, I would appreciate feedback.
    BTW, is there a way to remove the link to my website (in my original post)? This is the first time I posted for support, and I would like to remove that link when this gets closed as resolved.

    Do not edit the Twenty Twelve theme. First create a child theme for your changes. Or install a custom CSS plugin.

    is there a way to remove the link to my website (in my original post)?

    It is not the general policy to edit or delete forum posts. When a post is made and people contribute answers to an issue, that then becomes part of the community resource for others to benefit from. Editing or deleting posts removes this added value. In extreme circumstances, the moderation team might be persuaded to remove sensitive information but. generally, your best course of action is not to publish anything that you wouldn’t want to be public.
    https://codex.www.ads-software.com/Forum_Welcome#Deleting_.2F_Editing_Posts

    I’m sorry. This is not an extreme case, so the answer is “No”.

    Thread Starter skjha

    (@skjha)

    Thank you for the comment about a child theme. From reading all of the previous support messages, I did know enough to make these changes in a child. My question was if the edit I made was correct…sometimes as I attempt to modify, I am finding that a change I make has unintended consequences that I only discover later. Any thoughts about whether this approach is appropriate would be appreciated.

    Regarding the link: when I posted I noticed that the info about the forum says: Users can edit a post for up to 60 minutes from the time of submission. After about 45 minutes, when I didn’t have any responses, I went back to take the link out and couldn’t find any way to do so.

    The site will be public eventually, I just did not really want a link out there until it is complete.

    Thread Starter skjha

    (@skjha)

    Not resolved…but closed. Starting a new thread with more detail.

    Thread Starter skjha

    (@skjha)

    I was told to restart this post, so here goes.

    I need code to get one category – including sticky post and it’s featured post on my front page. The link to that page is in the beginning of this support request from 20 hours ago. (I don’t think I was clear with my first request, so please start from here.)

    I am using twenty twelve. I have created a child theme.

    I selected “your latest posts” under static page in the theme customize tab as my front page. I want posts from only one category (vacation) to appear on my front page. I want them to include the sticky post in that category along with my custom featured post box. Getting the featured post box is important.

    I changed the style.css – in my child theme – to modify the appearance of the featured post box:

    /*  change Featured Post box appearance */
    article.sticky .featured-post {
    	border-top: 4px double #4275b1;
    	border-bottom: 4px double #4275b1;
    	color: #08b8c3;
    	font-size: 13px;
    	font-size: 1.25rem;
    	line-height: 3.692307692;
    	margin-bottom: 24px;
    	margin-bottom: 1.714285714rem;
    	text-align: center;
    }

    Then I changed the wording of what would appear in the featured post box in my content.php (in the child theme). This is the relevant part of my content.php code in pastebin:
    https://pastebin.com/ykaKRb0c

    The combination of these two files with my “latest posts” selection and the standard index.php makes the front page look the way I want design wise…but I only want one category of posts (vacation) to appear on the front page and I want the sticky post in that category to have the featured post box. I get the sticky post (with the box) plus all other posts (from every category) when I use the standard index.php file.

    So I tested using some modified code (below) for the index.php (yes, in a child theme) and was able to show both posts from the vacation category. The sticky post (from the “vacation” category) shows, but I lost the “featured post box” part. The “vacation” category is the only category where I have a sticky post. This is the code I tried to substitute in my index.php:

    get_header(); ?>
    	<div id="primary" class="site-content">
    		<div id="content" role="main">
    <?php
                            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                            $args= array(
                                    'category_name' => 'vacation', // Change this category SLUG to suit your use; or see for query parameters https://codex.www.ads-software.com/Class_Reference/WP_Query#Parameters
                                    'paged' => $paged
    );
                            query_posts($args);
                            if( have_posts() ) :?>
    
                            <?php while ( have_posts() ) : the_post(); ?>
                                    <?php get_template_part( 'content', get_post_format() ); ?>
                                    <?php comments_template( '', true ); ?>
                            <?php endwhile; // end of the loop. ?>

    With this code, although the sticky post did appear, its featured post box disappeared. It also eliminated posts from other categories. So I think that instead of using just a category, I need to somehow incorporate the “is sticky” part to get the featured post box to show.

    Can anyone help me with 1. what code and 2. in what template I can do this? I have been searching and testing for 3 days. I just put the index code which populates the front page back to the original code again. (Yes, I am using a child theme.)

    Thank you for any assistance or suggestions regarding my questions. I just want one category of post(s)on the front page – including the one I set as sticky which should show up with the featured post box.

    Thread Starter skjha

    (@skjha)

    close this

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘twenty twelve front page how to have one sticky post only’ is closed to new replies.