I have some HTML/CSS that I've previously used to display blog post intros on a static website. I'm now building a theme for Wordpress and I would like to use the same layout to display all of my posts within the theme. Based on this accepted answer I think the best option is to create a page template (option 2 from the top answer in the link). The static layout looks like this: Bootstrap layout.
The HTML from the above screenshot is (just the first row of cards):
<div class="row mb-2">
<div class="col-md-6">
<div class="card flex-md-row mb-4 shadow-sm h-md-250 card-left">
<div class="card-body d-flex flex-column align-items-start">
<strong class="d-inline-block mb-2 text-danger">Film</strong>
<h3 class="mb-0">
<a class="text-dark" href="#">The Last Jedi</a>
</h3>
<div class="mb-1 text-muted">Sep 19</div>
<p class="card-text mb-auto">Star Wars Episode VIII proved to be divisive within the fandom. How will it be remembered once the sequel trilogy has concluded?</p>
Continue reading
</div>
<img class="card-img-right flex-auto d-none d-lg-block" data-src="holder.js/200x250?theme=thumb" alt="The Last Jedi" style="width: 200px; height: 250px;" src="Images/Thumbnails/The-Last-Jedi-Thumbnail.jpg" data-holder-rendered="true">
</div>
</div>
<div class="col-md-6">
<div class="card flex-md-row mb-4 shadow-sm h-md-250 card-right">
<div class="card-body d-flex flex-column align-items-start">
<strong class="d-inline-block mb-2 text-danger">Film</strong>
<h3 class="mb-0">
<a class="text-dark" href="#">Episode IX</a>
</h3>
<div class="mb-1 text-muted">Aug 19</div>
<p class="card-text mb-auto">The final chapter of the Skywalker sage is key to the future of the franchise, away from the original protagonists.</p>
Continue reading
</div>
<img class="card-img-right flex-auto d-none d-lg-block" data-src="holder.js/200x250?theme=thumb" alt="The Rise of Skywalker" style="width: 200px; height: 250px;" src="Images/Thumbnails/The-Rise-of-Skywalker-Thumbnail.jpg" data-holder-rendered="true">
</div>
</div>
</div>
With a small amount of CSS:
.card-left {
margin-left: 15%;
margin-right: 2%;
margin-top: 1.5%;
margin-bottom: 1.5%;
}
.card-right {
margin-left: 2%;
margin-right: 15%;
margin-top: 1.5%;
margin-bottom: 1.5%;
}
The information on the cards will need to map to WP. So from the above screenshot the coloured category (e.g. film) would be the WP category, the title the post title, the date the post date, the description a character-capped excerpt and the continue reading a link to the full post. I'd like the image to be a cropped version of the post header image, but for now am happy to exclude this part for the sake of simplicity.
I have a very simple index.php from the Underscores starter theme that I'd like to use to create this blog template:
<?php
/**
* Template Name: Blog Card Layout
*
* The template file for displaying blog posts using a Bootstrap card layout.
*/
get_header();
?>
<main id="primary" class="site-main">
<?php
if ( have_posts() ) :
if ( is_home() && ! is_front_page() ) :
?>
<header>
<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
</header>
<?php
endif;
/* Start the Loop */
while ( have_posts() ) :
the_post();
/*
* Include the Post-Type-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Type name) and that will be used instead.
*/
get_template_part( 'template-parts/content', get_post_type() );
?>
<?php
endwhile;
the_posts_navigation();
else :
get_template_part( 'template-parts/content', 'none' );
endif;
?>
</main><!-- #main -->
<?php
get_sidebar();
get_footer();
For reference, the template-parts/content looks like this:
<?php
/**
* Template part for displaying posts
*
* #link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* #package Suscito
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php
if ( is_singular() ) :
the_title( '<h1 class="entry-title">', '</h1>' );
else :
the_title( '<h2 class="entry-title">', '</h2>' );
endif;
if ( 'post' === get_post_type() ) :
?>
<div class="entry-meta">
<?php
suscito_posted_on();
suscito_posted_by();
?>
</div><!-- .entry-meta -->
<?php endif; ?>
</header><!-- .entry-header -->
<?php suscito_post_thumbnail(); ?>
<div class="entry-content">
<?php
the_content(
sprintf(
wp_kses(
/* translators: %s: Name of current post. Only visible to screen readers */
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'suscito' ),
array(
'span' => array(
'class' => array(),
),
)
),
wp_kses_post( get_the_title() )
)
);
wp_link_pages(
array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'suscito' ),
'after' => '</div>',
)
);
?>
</div><!-- .entry-content -->
<footer class="entry-footer">
<?php suscito_entry_footer(); ?>
</footer><!-- .entry-footer -->
<hr>
</article><!-- #post-<?php the_ID(); ?> -->
So my question is two-fold:
Is it possible to re-create this layout, or something close to it?
If so, where in the new page template would the Bootstrap HTML code go and how would I amend it so that it gets the relevant information from Wordpress? I'm particularly interested in how I could control the post excerpt and 'continue reading' element.
Sorry for such a long post! I've been scratching my head over this one for a while. For reference my site is https://www.davidhazeel.com.
Related
I want to add a picture above the footer as seen picture below, or you can visit the website: http://creativelab.twofour54.com/en/
Example of the photo from TwoFour54
The website I'm testing it on is wordpress. I tried playing with the footer.php however it works nicely but when I stretch the site (zoom out or in) It gets ruined. I tried to make it static with position tag from CSS but that didnt work.
<div class="cfa" style="margin-left: 200px; width: 100%; z-index: 10;">
<div class="container">
<div class="col-sm-12">
<img src="http://localhost:8080/TESTWORDPRESS/wp-content/uploads/2017/01/Sketch-Book-icon.png">
</div>
</div>
</div>
<?php
/*
Template for Footer
*/
?>
<footer id="footer">
<div class="row clearfix">
<?php
if ( ! dynamic_sidebar ( 'footer_widgets' ) ){
thdglkr_emptysidebar('Footer');
}
?>
</div><!-- row -->
<?php if (_option('footer_menu','1')=='1'){ ?>
<div class="footer-last row mtf clearfix">
<span class="copyright"><?php echo _option('footer_text'); ?></span>
<?php
wp_nav_menu(
array(
'theme_location' => 'secondary',
'menu' => 'Footer Menu',
'container' => 'div',
'container_class' => '' ,
'menu_class' => 'foot-menu',
)
);
}else{?>
<div class="footer-last row mtf clearfix center">
<span class="copyright center"><?php echo _option('footer_text'); ?></span>
<?php } ?>
</div><!-- end last footer -->
</footer><!-- end footer -->
</div><!-- end layout -->
</div><!-- end frame -->
<?php if (_option('footer_gototop')==1): ?>
<div id="toTop"><i class="icon-angle-up"></i></div><!-- Back to top -->
<?php endif; ?>
<?php wp_footer(); ?>
</body>
</html>
note: code above is Footer.php from my test local host
Does anyone have any ideas?
Put your .cfa inside your footer in your html. And in your css:
.cfa {
position: absolute;
top: 0;
left: 200px;
margin-top: -100px; //change this to the height of your image
}
EDIT: Actually it's better if you can remove it from your HTML and just add it via css using a :before pseudo-element if you're using it just for design purposes.
I'm not sure why this is, but my wordpress post isn't actually nested inside the div that the PHP code is nested in.
Here is the code on the html side:
<!-- BLOG -->
<div class="blog" id="blog">
<div class="wrap">
<div class="col-sm-12">
<?php
$args = array( 'numberposts' => 1, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$postslist = get_posts( $args );
echo '<section id="latest_posts">';
foreach ($postslist as $post) : setup_postdata($post); ?>
<h2><?php the_date(); ?></h2>
<h2> <?php the_title(); ?></h1>
<?php endforeach; ?>
<p><?php the_content();?></p>
</section>
</div>
</div>
</div>
And here is the only CSS affecting this code:
/* BLOG */
.blog {
background-image: url("../images/pat_1_bg.png");
padding-top: 60px;
padding-bottom: 60px;
height: 100%;
}
Any idea why this would be sitting outside of the div? It's almost like it has a positive z-index, which it doesn't. I can change the height of 'blog' as much as I want, and it will indeed affect the height of the div, but the post content is unaffected.
DISCLAIMER : I did not code the theme. This was made by another developer who left the project and I am making adjustments based on the new requirements. I don't have experience in Wordpress Theming but I can understand codes.
I am making a design in a website and I want to make my logo to be like floating above the Slider layer. I am working on a wordpress theme:
As you can see the Logo 'Red Dela Cruz' is on the top occupying a separate space or div. I want it inside the slider and floating on it like a layer, whenever the slide changes image, logo should still be there. Here is my code:
<div class="slider">
<img src="<?php echo $template_path; ?>images/redlogo_website.png" alt="" class="web-logo"/>
<div id="one-by-one-slider" class="one-by-one-slider">
<ul class="one-by-one-slider-large">
<?php
$args = array(
'post_type' => 'rdc_home',
);
query_posts( $args );
// The Loop
if ( have_posts() ) :
while (have_posts()) :
//the post for declaration
the_post();
?>
<li>
<img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'thumbnail') ); ?>" alt="<?php the_title(); ?>"/>
<div class="slider-content text-center">
<div class="slider-heading shp-12 slides" data-animation="bounceInDown" data-duration=4 data-delay=1>
<div class="container">
<div class="row">
<div class="col-md-12">
<h1><?php the_title(); ?></h1>
</div>
</div>
</div>
</div>
<div class="slider-heading shp-13 slides" data-animation="bounceInDown" data-duration=6 data-delay=2>
<div class=" container">
<div class="row">
<div class="col-md-12">
<h3><?php the_content(); ?></h3>
</div>
</div>
</div>
</div>
<!-- <div class="slider-heading shp-14 slides" data-animation="bounceInUp" data-duration=8 data-delay=4>
<div class=" container">
<div class="row">
<div class="col-md-12">
For Bookings
</div>
</div>
</div>
</div> -->
</div>
</li>
<?php
endwhile;
endif;
wp_reset_query();
?>
</ul>
<div class="one-by-one-slider-nav">
<ul class="one-by-one-slider-thumbs">
<li class="one-by-one-slider-element"></li>
<?php
$args = array(
'post_type' => 'rdc_home',
);
query_posts( $args );
// The Loop
if ( have_posts() ) :
while (have_posts()) :
//the post for declaration
the_post();
?>
<li></li>
<?php
endwhile;
endif;
wp_reset_query();
?>
</ul>
</div><!-- one-by-one-slider-nav -->
</div><!-- one-by-one-slider -->
</div><!-- slider -->
The logo is on the 2nd line and I haven't done any css on class
web-logo
This should work:
.web-logo {
position:absolute;
}
If the logo goes "behind" the slider, you should add a z-index, and make it higher, untill the image is showing:
.web-logo {
position:absolute;
z-index:2;
}
you can try this one:
.web-logo {
position: absolute;
right: 10px;
top: 10px;
z-index:2;
}
I'm trying to remove the featured image at the top of this blog post wordpress template. The author did a great job, but just left the blog pretty bad. I still need the featured images for thumbnails, however on this page it's a real mess. I'd like the video to sit right under the banner up top. I took out a bunch of stuff and messed it up. I researched about using the class functions, another solution talked about editing the single.php file. After looking through the single.php file, I concluded that everything that i wanted to remove appears to be located in a file called content.php.
so, here's the link: http://beautynetworkeffect.com/ground-zero-hong-kong-fashion-extravaganza-2015-fashion-one/
and here's the code:
<?php
/**
* The default template for displaying content
*
* Used for both single and index/archive/search.
*
* #package WordPress
* #subpackage Javo_Directory
* #since Javo Themes 1.0
*/
global $wp_query;
$javo_author = new WP_User( get_the_author_meta( 'ID' ) ); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?> class="row">
<?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
<div class="featured-post">
<?php _e( 'Featured post', 'javo_fr' ); ?>
</div>
<?php endif; ?>
<div class="row">
<div class="col-md-12">
<header class="entry-header text-center">
<?php the_post_thumbnail('full', Array('class' => 'img-responsive')); ?>
<div class="label-ribbon-row {f}">
<div class="label-info-ribbon-row-wrapper">
<div class="label-info-ribbon-row">
<div class="ribbons" id="ribbon-15">
<div class="ribbon-wrap">
<div class="content">
<div class="ribbon">
<span class="ribbon-span">
<?php echo get_the_date( 'M d Y'); ?>
</span>
</div>
</div><!-- /.content -->
</div><!-- /.ribbon-wrap -->
</div><!-- /.ribbons -->
</div><!-- /.label-info-ribbon -->
</div><!-- /.ribbon-wrapper -->
</div><!-- /.label-ribbon -->
</header><!-- .entry-header -->
</div><!-- col-md-4 -->
</div>
<div class="row entry-author-info-wrap">
<div class="col-md-2 col-xs-2 entry-author-image">
<a>
<div class="javo-thb" style="width:80px; height:80px; background-image:url('<?php echo apply_filters( 'javo_load_attach_image', $javo_author->avatar );?>');"></div>
</a>
</div>
<div class="col-md-10 col-xs-10 entry-author-meta-wrap">
<div class="entry-author-name"><?php echo $javo_author->display_name; ?></div>
<div class="entry-author-social">
<div class="entry-author-category">
<i class="fa fa-bookmark-o"></i>
<?php the_category( ', ' ); ?>
</div>
<?php if( comments_open() ) : ?>
<div class="pull-left" style="margin:0 10px;">
<span class="separator">/</span>
</div>
<div class="entry-author-comment">
<i class="fa fa-comments-o"></i>
<?php
comments_popup_link(
__( '0 Comment', 'javo_fr' )
, __( '1 Comment', 'javo_fr' )
, __( '% Comments', 'javo_fr' )
); ?>
</div>
<?php endif; // comments_open() ?>
</div>
</div>
</div><!--row entry-author-info-wrap-->
<div class="row entry-description-wrap">
<div class="col-md-12 entry-description">
<?php if ( is_single() ) : ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="single-post-meta row">
<div class="col-md-10 post-meta-infor">
</div> <!-- col-md-10 -->
<div class="col-md-2 text-right post-social">
<span class="javo-sns-wrap social-wrap">
<i class="sns-facebook" data-title="<?php the_title();?>" data-url="<?php the_permalink();?>">
<a class="facebook javo-tooltip" title="<?php _e('Share Facebook', 'javo_fr');?>"></a>
</i>
<i class="sns-twitter" data-title="<?php the_title();?>" data-url="<?php the_permalink();?>">
<a class="twitter javo-tooltip" title="<?php _e('Share Twitter', 'javo_fr');?>"></a>
</i>
</span>
</div> <!-- col-md-2-->
</div> <!-- single-post-meta -->
<?php else : ?>
<h1 class="entry-title">
<?php the_title(); ?>
</h1>
<?php endif; // is_single() ?>
<?php if ( is_search() ) : // Only display Excerpts for Search ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php else : ?>
<div class="entry-content">
<?php
if( is_category() )
{
printf('%s', get_permalink(), javo_str_cut( get_the_excerpt(), 300));
}else{
the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'javo_fr' ) );
} ?>
<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'javo_fr' ), 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<?php endif; ?>
</div><!-- 12 Columns Close -->
</div><!-- Row Close -->
<footer class="entry-meta">
<div class="inner-footer">
<div class="inner-footer-more">
<a href="<?php the_permalink(); ?>">
<?php _e( "more", 'javo_fr' ); ?>
</a>
</div>
<?php //javo_drt_entry_meta(); ?>
<?php edit_post_link( "<i class=\"fa fa-cog\"></i>" . __( 'Edit', 'javo_fr' ), '<span class="edit-link">', '</span>' ); ?>
<?php if ( is_singular() && get_the_author_meta( 'description' ) && is_multi_author() ) : // If a user has filled out their description and this is a multi-author blog, show a bio on their entries. ?>
<div class="author-info">
<div class="author-avatar">
<?php
/** This filter is documented in author.php */
$author_bio_avatar_size = apply_filters( 'javo_drt_author_bio_avatar_size', 68 );
echo get_avatar( get_the_author_meta( 'user_email' ), $author_bio_avatar_size );
?>
</div><!-- .author-avatar -->
<div class="author-description">
<h2><?php printf( __( 'About %s', 'javo_fr' ), get_the_author() ); ?></h2>
<p><?php the_author_meta( 'description' ); ?></p>
<div class="author-link">
<a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author">
<?php printf( __( 'View all posts by %s <span class="meta-nav">→</span>', 'javo_fr' ), get_the_author() ); ?>
</a>
</div><!-- .author-link -->
</div><!-- .author-description -->
</div><!-- .author-info -->
<?php endif; ?>
</div>
</footer><!-- .entry-meta -->
</article><!-- #post -->
To only remove the featured image you have to remove or comment the "the_post_thumbnail" line:
<?php // the_post_thumbnail('full', Array('class' => 'img-responsive')); ?>
To remove the featured image and the date ribbon remove all those lines:
<div class="row">
<div class="col-md-12">
<header class="entry-header text-center">
<?php the_post_thumbnail('full', Array('class' => 'img-responsive')); ?>
<div class="label-ribbon-row {f}">
<div class="label-info-ribbon-row-wrapper">
<div class="label-info-ribbon-row">
<div class="ribbons" id="ribbon-15">
<div class="ribbon-wrap">
<div class="content">
<div class="ribbon">
<span class="ribbon-span">
<?php echo get_the_date( 'M d Y'); ?>
</span>
</div>
</div><!-- /.content -->
</div><!-- /.ribbon-wrap -->
</div><!-- /.ribbons -->
</div><!-- /.label-info-ribbon -->
</div><!-- /.ribbon-wrapper -->
</div><!-- /.label-ribbon -->
</header><!-- .entry-header -->
</div><!-- col-md-4 -->
</div>
Remember that all changes will be overwritten when you update the theme to a new version. A good option to avoid this is to create a Child Theme, the recommended way of modifying an existing theme. More information can be found at: https://codex.wordpress.org/Child_Themes
Test it and let me know if you have any problem.
Regards.
I am gonna add something here since it can be helpful for those who are willing to learn about Wordpress file Content.php.
This file is how wordpress generates post content on wordpress.
It can easily be understood by this code
if ( is_single() ) {
the_title( '<h1 class="entry-title">', '</h1>' );
} elseif ( is_front_page() && is_home() ) {
the_title( '<h3 class="123123">', '</h3>' );
} else {
the_title( '<h2 class="entry-title">', '</h2>' );
}
?>
It shows different content on the base of the page that is being requested.
I'm running a query that outputs a span4 element in a row-fluid. I added code in my css to remove the margin-left on the third span4 in a row-fluid. This has also worked so far, but suddenly the one of the span4 jumps a line. Any suggestions why this suddenly stopped working?
You can see the page here:
http://dtm-auto.ch/home/
My css:
.row-fluid [class*="span"]:nth-child(3n+1) {
margin-left: 0!important;
}
My code:
<div id="content" class="clearfix row-fluid">
<div id="main" class="span12 clearfix" role="main">
<h2 class="text-left">Neue Fahrzeuge</h2>
<div class="clearfix row-fluid">
<?php
global $wp_query;
query_posts( array(
'post_type' => 'acme_product',
'posts_per_page' => 6
));
while ( $wp_query->have_posts() ) :
$wp_query->the_post();
?><?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );?>
<div id="front-new-video" class="span4">
<h3 id="car-title"><?php the_title(); ?></h3>
<div class="thumbnail wrapper">
<div class="ribbon-wrapper-green"><div class="ribbon-green">Neu</div></div>
<?php the_post_thumbnail('medium');?>
<p>Preis: <span style="color:#FEF158"><?php the_field('preis'); ?> CHF</span></p>
<p>Jahr: <span style="color:#FEF158"><?php the_field('jahr'); ?></span></p>
<p>Farbe: <span style="color:#FEF158"><?php the_field('farbe'); ?></span></p>
<p>KM: <span style="color:#FEF158"><?php the_field('km'); ?> KM</span></p>
<h4> <i class="icon-chevron-sign-right"></i> Zum Fahrzeug </h4>
</div>
</div>
<?php
endwhile;
?>
</div>
</div> <!-- end #main -->
</div> <!-- end #content -->
It's because you're using height: 100% on #front-new-video which doesn't really do anything because the parents height(row-fluid) needs to be defiend for height: 100% to work.
Use a fixed height or min-height instead and your problem will be solved. e.g height: 419px;