Community Forums › Forums › Archived Forums › Design Tips and Tricks › Customizing my first (going-green-pro) Studiopress theme / page templates?
- This topic has 1 reply, 1 voice, and was last updated 9 years, 1 month ago by kevlab.
-
AuthorPosts
-
March 1, 2015 at 11:42 am #142749kevlabMember
Hi!
I'm working on customizing for the first time with a Studiopress theme. I wanted to accomplish three different page layouts. The difference between each one is what code I used directly before_content.
Homepage: has a slider before_content
About Page: has a unique div layout
Other pages: have a div layout.So the way I did it was in my functions.php file I made something like below:.. my question is, is there a better way to do apply custom layout code to different pages than what I've done here? My method feels like a complete hack-job. I remember before using genesis I would just create different page templates and select them, but I'm not sure it works that way here.
Thanks!
add_action( 'genesis_before_content', 'featured_content' );
function featured_content() {
if(is_front_page() ) {
/* here is where the before_content layout goes for the front page */
echo do_shortcode( '[rev_slider frontpage]' );
}elseif(is_page( 'About Us' ) ) {
/* here is where the before_content layout goes for the about us page */} else {
/* here is where the before_content layout goes for the other pages */
?>
<div class="featured-text-wrapper">
<div class="row"><?php
$image = get_field('featured_image_left');
if( !empty($image) ): ?>
<div class="left-image-column col" style="background-image: url(<?php echo $image['url']; ?>)"></div>
<?php endif;
?>
<div class="mid-content-column col">
<?php the_field('featured_text_and_title'); ?></div>
<?php
$image = get_field('featured_image_right');
if( !empty($image) ): ?>
<div class="right-image-column col" style="background-image: url(<?php echo $image['url']; ?>)"></div>
<?php endif;
?>
</div>
<div><?php the_field('bottom_content'); ?></div>
</div>
<?php }
}March 1, 2015 at 3:16 pm #142765kevlabMemberSorry I should have explained what I was doing instead of barfing a bunch of code up for everyone to read.
So, the way I thought I could achieve different "featured content" layouts, was to add this into my functions.php... (simplified for readability)
hook: genesis_before_content
If homepage: show home slider
elseif About page: show about page div stuff
else show "common page" div layouts.I didn't think that going to an if elseif else statement for inserting structural layout content into my pages seemed like the right thing to do. I'm used to template files to specify only the code I want on each template, not looping through an if statement to determine which code to show depending on the pages... this method I'm using for example would be terrible if I had 10 different "featured content" layouts that I wanted to apply over many different pages.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.