Community Forums › Forums › Archived Forums › Design Tips and Tricks › Style first post differently
- This topic has 12 replies, 6 voices, and was last updated 10 years, 7 months ago by Spanka.
-
AuthorPosts
-
August 3, 2013 at 7:00 am #53926JummulMember
I've tried to ask this in the common WordPress forums without succes. There are essentially two things I want to achieve.
1. I want the first post to have a different styling than the other. For instance a slight background change.
2. Secondly, I want the first post to IGNORE the More Tag. Exactly what I want to do, and it's explanation, is right here: http://wordpress.org/support/topic/can-wp-ignore-lt-more-gt-tag-on-most-recent-post I just can't get it to work; and I think it has something to do with the framework.I've got a lot of CSS experience, but practically no PHP experience.
Anyone can help me out?
http://www.acupoflife.nlAugust 3, 2013 at 10:18 am #53951AnitaKeymasterFor #1, you are using the Pretty Young Thing theme which doesn't come with a widgetized home page. You could add a Home Page widget to the top using Brian Gardner's instructions - http://www.briangardner.com/home-widget-area-eleven40/. Although for eleven40, it will work for Pretty Young Thing. Then you could use a Featured Posts for the top - and style that area any way you want using CSS and leave the grid part just as it is.
If you decide you want the Featured area to show FULL CONTENT, you can set that which eliminates then need for the more tag.
Love coffee, chocolate and my Bella!
August 4, 2013 at 3:36 am #54066JummulMemberI might understand your answer wrong, or you might understand the question wrong - I'm not sure. Your answer doesn't the way to go. Let me clarify.
I use Pretty Young Thing, yes. BUT! My home.php doesn't look anything like the original. I wanted to disable the grid-style layout of Pretty, and just return to the standard genesis loop in which you just have the_content from every post. No grid, no excerpts.
In order to keep my homepage clean I use a more tag on posts. But I want the more tag to be ignored on the first post of the first page only!
My home.php now looks like this:
<?php // remove_action( 'genesis_loop', 'genesis_do_loop' ); // add_action( 'genesis_loop', 'pretty_grid_loop_helper' ); /** Remove the post meta function for front page only */ remove_action( 'genesis_after_post_content', 'genesis_post_meta' ); genesis();
Now on the support forums I've found a similar question, http://wordpress.org/support/topic/can-wp-ignore-lt-more-gt-tag-on-most-recent-post,
But when I use their advice, and add
global $more; if($post == $posts[0]) $more = 0; else $more = 1; the_content();
before the loop, nothing happens.
When I change $post[0] to [1], thus having
global $more; if($post == $posts[1]) $more = 0; else $more = 1; the_content();
ALL the posts ignore the More Tag I've given them.
So, the ignoring-of-the-more-tag-part works. Now for the making-sure-it-only-applies-to-the-first-post-of-the-first-page-part.
Any ideas?
August 4, 2013 at 6:55 am #54087angieatcMemberNot sure how to style the first post the way you want it but if you are wanting just posts on the page and not the grid I would remove the home.php file and then you just have posts. Is that what you are wanting?
My design site, Hill Springs Designs
August 4, 2013 at 7:16 am #54089AnitaKeymaster@jummel, I wasn't confused. I based my answer on what you wrote initially. If you had mentioned all of the other stuff, I might have presented a different answer.
The link you provided is 5 years old and given for a non-genesis theme.
@angieatc, they want the first post only to be styled differently than the remainder of the blogs. Based on the initial question, what I provided them will work, but they want something totally different.
Love coffee, chocolate and my Bella!
August 4, 2013 at 8:09 am #54095Debra ScottMemberif you code your homepage as such
<?php remove_action( 'genesis_loop', 'genesis_do_loop' ); add_action( 'genesis_loop', 'pretty_home_loop_helper' ); global $more; if($post == $posts[0]) $more = 0; else $more = 1; the_content(); /** * Add widget support for homepage. If no widgets active, display the default loop. * */ function pretty_home_loop_helper() { if ( is_active_sidebar( 'home' ) ) { echo '<div id="home">'; dynamic_sidebar( 'home' ); echo '</div><!-- end #home-->'; } else { genesis_standard_loop(); } } genesis();
then register it in functions.php
genesis_register_sidebar( array( 'id' => 'home', 'name' => 'HOME', 'description' => 'This is a sidebar that shows on homepage.', ) );
Now pull two featured post widgets into your new sidebar. The first will show 1 post full content
the second will show say 4 posts and offset by 1 post and also show full content.
this will now give you the layout you want.
For the styling go to view source on your page find the widget info for the first full post widget.
mine was #featured-post-6 so in my style.css I would put
#featured-post-6 {
background: #eee;
}and so on..
need help with your business or personal website? Contact me at Fat Cat Designs
August 4, 2013 at 10:49 am #54125JummulMemberThanks Debra for your easy to follow instructions, yes that worked. But not quite.
For whatever reason the first post still has an active More Tag.
if($post == $posts[0]) $more = 0;
just doesn't seem to work..August 4, 2013 at 10:59 am #54126Debra ScottMembertry this one instead
replace all of this
global $more; if($post == $posts[0]) $more = 0; else $more = 1; the_content();
with this
if ($more == -1) { //do not use the more tag on the first one. the_content(); $more = 0; //prevent this from happening again. use the more tag from now on. } else { //use the more tag the_content(__('Read more...')); }
need help with your business or personal website? Contact me at Fat Cat Designs
August 4, 2013 at 11:20 am #54135JummulMemberNo joy. When I change -1 to 1 it ignores the More Tag on the posts. To me this seems like the posts are not correctly numbered - it sees all the posts as the first post. I'm not sure though.
Thanks for your time and help by the way!
August 4, 2013 at 10:05 pm #54182Debra ScottMemberI don't know why none of the codes aren't working. I wonder if there is a plugin or other code interferring?
need help with your business or personal website? Contact me at Fat Cat Designs
August 4, 2013 at 10:11 pm #54184Brad DaltonParticipantI wrote about the answer to the first question a few months ago and the solution works perfectly using PHP code.
You could also use the code to remove the more tag on the latest post by adding the remove action or filter to the function.
August 6, 2013 at 3:25 pm #54452JummulMemberI tried:
global $more; if($post == $posts[0]) $more = 0; else $more = 1; the_content();
and
if($post == $posts[-1]) $more = 0;
and I tried widgitizing the home page and adding a Featured Post
and I tried
if ($more == -1) { //do not use the more tag on the first one. the_content(); $more = 0; //prevent this from happening again. use the more tag from now on. } else { //use the more tag the_content(__('Read more...')); }
And I also tried repeating all of this with all plugins disabled. Still. No. Luck.
I think I'll become a farmer and live a happy life.
August 6, 2013 at 5:33 pm #54467SpankaMemberI don't know about removing the MORE tag, but the styling should be easy enough - use the first-child selector.
I don't know what your HTML looks like, but here's a general idea
<div id=wrap> <div id=post-1 class=genesis-post> ---- some stuff </div> <div id=post-2 class=genesis-post> ---- some stuff </div> <div id=post-3 class=genesis-post> ---- some stuff </div> </div>
Each of your posts will be wrapped in a div that has a common class. To format the first one differently, do this:
.genesis-post:first-child { /* some formatting here */ }
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.