Masonry in wordpress only showing one column - php

So I know masonry in a single column has been covered a few times on stack but I'm not very familiar with jquery and I'm not sure of the adjustments I need to make. I'm also not extremely proficient in wordpress to know if I am making an obvious mistake here. I'm editing a theme and I'm trying to make the blog use a masonry layout. The theme calls the post loop from it's own php file so the blog is kind of broken up in to several php files. I hope I am including the right info.
The posts are showing up in blocks but it's just one column straight down. It seems the container is going all the way across the page on each post. I'm not sure if it's not stopping the loop or what I need to add so that each post spreads across the container width. Any help or tips on what I am doing wrong would be greatly appreciated. Thanks in advance.
I added this to my functions.
function wdv_enqueue_scripts() {
wp_enqueue_script( 'jquery-masonry' ); // adds masonry to the theme
}
add_action( 'wp_enqueue_scripts', 'wdv_enqueue_scripts' );
This to my footer.php
<script>
jQuery( document ).ready( function( $ ) {
$( '#container2' ).masonry( { columnWidth: 220 } );
} );
</script>
Here is my code for the loop.
<div id="container2">
<?php
global $ae_post_factory;
$ae_post = $ae_post_factory->get('post');
$post = $ae_post->current_post;
?>
<div class="brick">
<div class="brick_header">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" >
<h4 class="media-heading title-blog"><?php the_title(); ?></h4>
</a>
</div>
<div class="brick_featured_image">
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail (); ?>
</a>
<?php endif; ?>
</div>
<?php the_excerpt(); ?>
Read More
</div>
</div><!-- container -->
And this is the CSS
* masonry brick layout */
#container2 {
width: 100%; /* width of the entire container for the wall */
margin-bottom: 10px;
}
.brick {
width: 30%; /* width of each brick less the padding inbetween */
padding: 0px 10px 15px 10px;
background-color: #fff;
margin-top: 5px;
}
.brick_header{
border-bottom: solid 1px #1d1d1d;
padding-bottom: 10px;
padding-top: 10px;
}
.brick_header a{
color: #ffff00;
}
.brick_header a:hover{
color: white;
}
.brick_featured_image{
width: 100%;
margin-top: 10px;
}
.brick_featured_image img{
width: 100%;
height: auto;
}

Here you're providing Column-Width in JS 220px.
And in CSS : 30%.
That might be creating problems.
Make sure your HTML Structure Looks like this.
<div id="container2">
<div class="brick">...</div>
<div class="brick">...</div>
<div class="brick">...</div>
</div>
And CSS :
.container2{
width:100%;
}
.brick{
width:25%;
/*
This should be respective of the columns you want
Like for 4 columns, 100%/4 = 25%
*/
}
And JS.
var $container2 = $('#container2');
$container.masonry({
itemSelector: '.brick'
});
For more detailed explaination : http://masonry.desandro.com/#getting-started
To know more details on the problem you're having, kindly provide the URL so I can have a look at it and can provide exact solution.

I personally use the "js-masonry" class mainly because if you are using a framework such as Bootstrap or Modest Grid, it will keep the gutter settings, etc.
Here is an example:
<div class="js-masonry">
<?php if ( have_posts() ): ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="dt-6 tl-6 tp-6">
<article>
<h2>
<a href="<?php esc_url( the_permalink() ); ?>" title="Permalink to <?php the_title(); ?>" rel="bookmark">
<i class="fa <?php echo strtolower(str_replace(" ", "-", get_field('project_type'))); ?>"></i>
<?php the_title(); ?>
</a>
</h2>
<?php the_excerpt(); ?>
<div class="download">
<a href="<?php esc_url( the_permalink() ); ?>" title="Permalink to <?php the_title(); ?>" rel="bookmark">
View <?php the_title(); ?>
</a>
</div>
</article>
</div>
<?php endwhile; ?>
<?php else: ?>
<h2>No posts to display</h2>
<?php endif; ?>
Notice that the <div class="js-masonry"> is outside of the while.

Related

CSS: remove additional spaces between created by "float" command

I've got a wordpress blog where I want to iterate through posts. Each post on the list has a little photos on the left. And title and subtitle on the right.
But as you can see distance between each post is not equal but rather related to the length of the title and subtitle. The longer text is the bigger distance between each posts. I want to change it to fixed length with the same size every time. How can I do it? Here is my code:
<div style="padding-top: 25px;" id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<p>
//IMAGE
<?php if ( has_post_thumbnail() ): ?>
<a style="float: left; padding-right: 25px;" href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a> <?php endif; ?>
//TITLE
<h2 style="padding-top: -20px;"><?php the_title(); ?>
</h2>
//SUBTITLE
<?php echo get_secondary_title(); ?>
</p>
</div>
You can limit the title and subititle max lenght truncating it.
Try this:
.text-to-truncate {
width: 250px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
Or check this out:
https://software.intel.com/en-us/html5/hub/blogs/ellipse-my-text/

Show posts from a specific category - Wordpress

I am having an issue where by I need to show only specific posts on my home from a certain category otherwise it is showing anything and everything that is posted and I am using posts around the site for other purposes.
<?php query_posts('posts_per_page=3'); while(have_posts()) : the_post(); ?>
<span style="float: left; width: 180px; height: 180px; padding: 0px 60px 0px 0px;"><?php the_post_thumbnail( array(220,200) ); ?> </span>
<h3 class="excerptHeader" style="margin-top: 0px;"><a class="excerptHeader" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<span class="excerpt"><p><?php echo substr(get_the_excerpt(), 0,80); ?> [...]</p></span>
<span class="excerpt"><p><a class="excerptLink" href="<?php the_permalink(); ?>">Read full article</a></p></span>
<?php endwhile; wp_reset_query(); ?>
I have tried adding in:
Change your query arguments as follows:
query_posts('posts_per_page=3&cat=nn')
Where nn is the ID of the category you wish to select posts from.
Check query_posts page for more details.

Can't get text next to toggle to line up properly

I added the text "MENY" next to the toggle (nav trigger) since I thought it would be confusing for desktop visitors when visiting my site. However I can't seem to get the text to line up nicely with the toggle icon. How do I lower or raise the text next to the icon so it looks good?
Here's the .php:
<a href="#" id="nav-trigger">
<span style="font-family: Source Sans Pro; font-size: 16px; line-height: 1; margin-left: 5px; font-weight: 700;">MENY</span> m
Image of issue can be found here: [a link]http://i41.tinypic.com/2jd3l9k.png (not enough rep to add images)
Also, if there's a way to bring them closer together... but that's just a bonus!
Thanks for all help! I'm a beginner trying to learn. :)
Entire header.php >nav-trigger<
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<?php thb_body_start(); ?>
<div id="page">
<?php thb_header_before(); ?>
<header id="header">
<?php thb_header_start(); ?>
<div class="header-container">
<div class="wrapper">
<?php
$logo = thb_get_option('main_logo');
$logo_2x = thb_get_option('main_logo_retina');
if( !empty($logo['id']) && !empty($logo_2x['id']) ) : ?>
<?php $logo_metadata = wp_get_attachment_metadata($logo['id']); ?>
<style>
#media all and (-webkit-min-device-pixel-ratio: 1.5) {
#logo {
background-image: url('<?php echo thb_image_get_size($logo_2x['id'], 'full'); ?>');
background-size: <?php echo $logo_metadata['width']; ?>px, <?php echo $logo_metadata['height']; ?>px;
}
#logo img { visibility: hidden; }
}
</style>
<?php endif;
?>
<h1 id="logo">
<a href="<?php echo home_url(); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>">
<?php if( isset($logo['id']) && $logo['id'] != '' ) : ?>
<img src="<?php echo thb_image_get_size($logo['id'], 'full'); ?>" alt="">
<?php else : ?>
<?php bloginfo( 'name' ); ?>
<?php endif; ?>
</a>
</h1>
<?php thb_nav_before(); ?>
<a href="#" id="nav-trigger">
<span style="font-family: Source Sans Pro; font-size: 16px; line-height: 1; margin-left: 5px; font-weight: 700;">MENY</span> m
<div class="nav-wrapper">
<nav id="main-nav" class="main-navigation primary">
<?php thb_nav_start(); ?>
<?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>
<?php thb_nav_end(); ?>
</nav>
<nav id="mobile-nav" class="main-navigation primary">
<?php thb_nav_start(); ?>
<?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>
<?php thb_nav_end(); ?>
</nav>
</div>
<?php thb_nav_after(); ?>
</div>
</div>
<div class="wrapper">
Create a div with the image in it.
Create a div with the text in it.
<div class='myimage'><img src='yourimg'></div>
<div class='menytext'>meny</div>
.menytext{float:left;margin:0 0 0 -50px} (for example)
Float the text div over the image and then you will be able to position the text however you like.
because inline tag has a space, you can add between them, like
<a href="#" id="nav-trigger"><!--
--><span style="font-family: Source Sans Pro; font-size: 16px; line-height: 1; margin-left: 5px; font-weight: 700;">MENY</span>

Wordpress - issue with the lightbox plugin inside a loop

i'm having problems with the Lightbox Plus plugin. I need to create a bunch of elements in my homepage, and Lightboxes linked to them to show more content. Now, I managed to create all the elements needed, but the Lightboxes generated are all the same, all with contents related to the first of the elements to be specific. If inserted in the loop shouldnt each of them be related to his "starting element"? This is the code i'm using:
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php
$id = get_the_ID();
$big_image = get_field( "big_cocktail" );
$thumb_image = get_field( "thumbnail_cocktail" );;
$titolo_box = get_the_title();
$sottotitolo_box = get_field( "sottotitolo_cocktail" );
$h2_css = "margin-bottom: 5px !important;";
$sottotitolo_css = "width:100% !important; text-align:center !important; padding-top: 5px !important; margin: 0 auto !important; margin-top:20px !important;";
?>
<!--element-->
<div class="element <?php echo $category -> slug; ?>" data-category="<?php echo $category -> slug; ?>">
<a class="lbp-inline-link-1" href="#" style="text-decoration:none;">
<img alt="" class="imgwork" src="<?php echo $thumb_image; ?>" heigth="100px"/>
</a>
<!-- THIS IS THE DIV FOR THE LIGHTBOX -->
<div style="display:none">
<div id="lbp-inline-href-1" style="background: #fff; height:100%; background-image:url('<?php echo $big_image; ?>');">
<h2 style=""><?php echo $titolo_box; ?></h2>
</div>
</div>
<!-- END DIV-->
<div class="worksarrow">
<a class="lbp-inline-link-1" href="#" style="text-decoration:none;">
<img alt="" src="<?php echo get_template_directory_uri(); ?>/img/section-works/arrow.png" />
</a>
</div>
<a class="lbp-inline-link-1" href="#" style="text-decoration:none;">
<h2 style=""><?php echo $titolo_box; ?></h2>
</a>
<div class="sottotitolo_portfolio" style="<?php echo $sottotitolo_css; ?>">
<?php echo $sottotitolo_box; ?> </div>
<div class="worksbottom"></div>
</div>
<!--element-->
<?php endwhile;
}
?>
I've finally solved this. He was creating all the right popups but each of them needed a specific class and ID, so it just became:
< div id="lbp-inline-href-< ?php echo $index; ?>" style="background: #fff; height:100%; background-image:url('< ?php echo $big_image; ?>');">
< ?php $index++; ? >

image permalink PHP problem with Wordpress

the site is http://www.christopherwaller.com/wordpress/
if you take a look on the above site i'm trying to insert a link to a page on each of the images on a carousel, so if you click anywhere on the image it will navigate to a new page. I have created the link i want on the post title text (ie. Look 1, Look 2 etc . . .) by using
<h2 class="postitle"><?php the_title(); ?></h2>
but i can't for the life of me find the right PHP to create the same links on each of the carousel photos?
I'm still trying to get to grips with PHP if anyone could advise that would be great.thanks
this is the PHP
<div class="edit"><?php edit_post_link(); ?></div>
</div>
<div class="postcontent">
<?php
$content = $post->post_content;
$searchimages = '~<img [^>]* />~';
preg_match_all( $searchimages, $content, $pics );
$iNumberOfPics = count($pics[0]);
if ( $iNumberOfPics > 0 ) { ?>
<?php the_thumb('medium'); ?>
<?php } else { ?>
<div class="imgframe"></div>
<?php } ?>
<div class="post_content">
<h2 class="postitle"><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<?php wp_link_pages('<p class="pages"><strong>'.__('Pages:').'</strong> ', '</p>', 'number'); ?>
<div class="post_meta">
<div class="author"><?php the_author(); ?></div>
<div class="date_meta"><?php the_date(); ?></div>
<div class="category_meta"><?php the_category(', '); ?></div>
</div>
</div>
</div>
<div class="postbg_bottom"></div>
<div class="social_links">
<a class="read" title="Read the rest of this post" href="<?php the_permalink(); ?>">read more</a>
</div>
</div>
<?php endwhile ?>
<div class="navigation">
<div class="nxt_page"><?php previous_posts_link('New Entries »', 0); ?></div>
<div class="prv_page"><?php next_posts_link('« Old Entries', '0') ?></div>
</div>
<?php endif ?>
</div>
</div>
<!--CONTENT END-->
and the CSS
/* Easy Slider */
#slider ul, #slider li{margin:0;padding:0;list-style:none;}
#slider li, #slider2 li{ width:1000px;height:1100px;}
#nextBtn{display:block; width:13px; height:14px; position:relative; left:0px; top:0px; z- index:1000; right:120px; top:-718px; float:left; left:840px; margin-right:20px; }
#prevBtn{display:block; width:13px; height:14px; position:relative; left:300px; top:0px; z-index:1000; right:120px; top:-718px; float:left; left:-100px; margin-right:20px; }
#prevBtn{ left:-20px;}
#nextBtn a, #prevBtn a{ display:block;position:relative;width:13px;height:14px;
background:url(images/sl_left.png) no-repeat 0 0;}
#nextBtn a{ background:url(images/sl_right.png) no-repeat 0 0;}
.graphic, #prevBtn, #nextBtn{padding:0; display:block; overflow:hidden; text-indent:-8000px;}
/* Easy Slider END */
/*SLIDER END*/
You could try using the following instead of "the_thumb();"
add the following to your theme's 'functions.php'
// Add post thumbnail theme support
add_theme_support('post-thumbnails');
Then use the following to replace the 'the_thumb();'
if ( has_post_thumbnail() )
the_post_thumbnail();
I actually use this myself and created a plugin that links the post thumbnail to the post. It seems like you're trying to do the same kind of thing so I hope this works for you.
I understand you are using the PostThumb revisited plugin, correct? And if I read correctly, this plugin outputs a single picture with the_excerpt() . If that is the case, couldn't you just do this? :
<a href="<?php the_permalink();?>">
<?php the_excerpt(); ?>
</a>

Categories