Horizontal div layout within a foreachloop - php

I am trying to integrate a small section on an existing website, my problem seems simple, but I can't seem to get my head around it. Here is how I want it to look like:
alt text http://img691.imageshack.us/img691/329/layouth.jpg
Blue = #pagecontainer
Red = #sectioncontainer
Yellow = .post
pagecontainer { height: 100%; width: 900px;}
post container {width: 900px;}
.post {width: 210px;}
Four posts are getting pulled in from WordPress using:
<?php if (have_posts()) : ?>
<?php query_posts('category_name=Category&posts_per_page=4'); ?>
<?php while (have_posts()) : the_post(); update_post_caches($posts); ?>
<div class="post">
<?php the_content() ?>
</div>
<?php endwhile; ?>
The posts will be a fixed width, but a varied height. The problem is, I cannot put spacers in-between, without the last post pushing a div underneath, and I cannot use margins because the first and last div are bumped up against the page container.
I could probably use something like
.post {margin-right: 20px;}
.post:last-child {margin: 0 !important;}
...but this just seems messy and I would rather avoid using the child pseudo selectors.
Any ideas on a tidier solution?

You can use a $count
Something like:
<?php $count = 0; ?>
<?php while (have_posts()) : the_post(); update_post_caches($posts); ?>
<?php $count++; ?>
<?php if ($count < 5) {
$class = 'post';
} else {
$class = 'post-last';
} ?>
<div class="<?php echo $class; ?>">
<?php the_content() ?>
</div>
<?php endwhile; ?>
Then just set your 'post' class in the CSS to have the margin of 20px and 'post-last' to not have a margin

Try to use margin-based solution, but instead of :last-child trick that is unfortunately isn't cross-browser, set parent's margin at right side to equivalent negative value:
.post {margin-right: 20px;}
.secioncontainer {margin-right: -20px;}
Also make sure that there will be no spaces in-between of the .posts. You could modify the markup so that it is written in one line without spaces:
<?php while (have_posts()) : the_post(); update_post_caches($posts); ?><div class="post"><?php the_content() ?></div><?php endwhile; ?>
Or use CSS technique like:
.secioncontainer {font-size: 0px;}
.post {font-size: /*your normal value*/;}

Related

How to delete HTML from excerpts in posts on homepage?

How Can I delete html tags in excerpts posts on homepage https://ptbo.edu.pl/ ?
I mean only HOMEPAGE (not in categories) because I'm changing this manually in posts editor.
My code looks now:
<?php if ( allium_has_excerpt() ) : ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php endif; ?>
I want to make changes only on the home page
My solution would be to leave the HTML tags but add this CSS to make them unnoticeable:
.home .entry-summary a {
pointer-events: none;
color: #3d3d3d;
}
.home .entry-summary strong {
font-weight: normal;
}

WordPress: CSS property getting cancelled out?

In my page.php I am trying to output the featured image in .page-wrapper div and display using style="background-image: url('<?php echo $thumb['0'];?>') !important;" on top of the page (Inline css)
The problem is it keeps on being crossed out by the browser. It may be because there is a 3rd party plugin and that could be overriding it - so I've tried adding !important tag to my property. Not working. And I'm disabled the plugin, no luck. IDEAS??
Link to page: http://radian3.com/events/
Here is the page.php
<div class="about-container">
<!-- The POST LOOP -->
<?php if(have_posts()) :
while (have_posts()) : the_post(); ?>
<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );?>
<div class="page-wrapper" style="background-image: url('<?php echo $thumb['0'];?>') !important;">
<b class="about-title"><?php the_title(); ?></b>
<!-- <div class="about-icon-wrapper" style="background-image: url('<?php echo $thumb['0'];?>')"></div> -->
</div>
<div class="contact-body-wrapper">
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<?php else :
echo '<p>No content found..</p>';
endif;
?>
CSS
/* single.php page */
.page-wrapper {
text-align: center;
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
/* background-image: url('../img/about-our-team.jpg') !important;
*/ height: 30rem;
background-repeat: no-repeat;
background-size: cover;
}
Actually, its your code in page.php that's doing the overriding.
The image you see crossed out id included in your css file, the one with the emply url the one generated by your code.
Your code isn't returning any image, so you need to fix that. Unless you have $post explicitly defined, it wont have a value here, so $post->ID will be empty.
You should use get_the_ID() inside the loop, i.e.
<?php
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'full' );
if ($thumb){
?>
<div class="page-wrapper" style="background-image: url('<?php echo $thumb['0'];?>')">
<?php
// rest of your code....
}
FYI, you should also check to make sure $thumb has a value - if it doesn't, you could use a default placeholder instead
You need to remove inline style attribute which sets no image to it but it is overriding css for background image url for page-wrapper
You need to remove the following attribute from page-wrapper div.
style="background-image: url('') !important;"
Please give like this
background-image: url("<?php bloginfo('template_directory'); ?>/images/parallax_image.jpg ");

Adding a div Read More wordpress

Ok so I am trying to add a div read more button but it's not working, and I'm not sure how to go about this.
here is the code I am trying to use.
<?php the_content('<div class="readmore"></div>') ?>
here is the css
.readmore{
width:136px;
height:34px;
background: url('http://ericavain.com/wp-content/uploads/2013/04/READ1.png') no-repeat;
}
.readmore:hover{
width:136px;
height:34px;
background: url('http://ericavain.com/wp-content/uploads/2013/04/read2.png') no-repeat;
}
How do i get this accomplished
Maybe you are trying to use "read more" on Pages? If that is the case try adding something like this to your page:
<?php // let's enable more link on pages...
global $more;
$more = 0;
?>
<?php the_content(); ?>

Scroll bar not working

I'm trying to produce list of recently added item in cart and the code goes like this
<ol style = "overflow: -moz-scrollbars-vertical; overflow-y: scroll;">
<?php foreach($_items as $_item): ?>
<?php echo $this->getItemHtml($_item) ?>
<?php endforeach; ?>
</ol>
I'm getting the items but the scroll not working. Please help me. I'm a budding developer.
If you want to have vertical scroll after certain height of ol container use below listed code
<ol style = "overflow-y: scroll;">
use overflow:auto property of css instead of scroll, and give some height for your list.
Specify a height there like this
<ol style = "overflow: -moz-scrollbars-vertical; overflow-y: scroll;height:50px;">
<?php foreach($_items as $_item): ?>
<?php echo $this->getItemHtml($_item) ?>
<?php endforeach; ?>
</ol>

Wondering where the image is being pulled

I am new to css and coding, but I am wondering in the below code where it is pulling the imiage from the post. I dont want this page pulling images...it is pulling imiage from blog post and pages...is there a code I can place to make sure it does not pull the image?
thanks
<style>
#para1{ text-align:center;}
.bdr_blb{
border:#000000 solid 4px;
height:70px;
background:#cccccc;
text-align:center;
font-size:14px; font-weight:700;}
.light32{ font-size:32px;}
.bggrey{ background:#cccccc;}
.light18{ font-size:18px;}
#bedroom4{
background:#cccccc;
}
.heading_div{float:left;}
.entry-content{float:left;}
.thumnail_col ul li {
float: left;
list-style: none outside none;
margin-right: 15px;
}
.thumnail_col ul li img{background:none; border:none;}
</style>
?>
<div id="container">
<div id="" role="main">
<?php $args = array( 'category_name' => 'lease', 'orderby' => 'title' ,'order' => 'ASC' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
if ($count==1)
{
echo "<tr>";
}
?>
<td><div class="lease">
<div class="heading_div"><h2 class="entry-title"><strong><u>
<?php
echo ''.$loop->post->post_title.'';
?>
</u></strong></div></h2>
<div class="entry-content">
<div class="desc">
<?php
the_content();
?>
</div>
</div></div></td>
<?php
if($count==$number_of_columns)
{
echo "</tr>";
$count=0;
}
$count++;
endwhile;
?>
</div><!-- #content -->
</div><!-- #container -->
You need to find where the function the_content(); is defined. Somewhere, look for:
function the_content()
Inside of that function definition is possibly code that echo's out an <img> tag. Delete or comment out that portion of the code. Until we see the definition of that function though, we cannot be sure of other consequences of modifying it.
UPDATE
This won't prevent the image from being loaded by the browser, but will prevent it from being actually displayed by the browser. It's easier than tracking down the function definition to modify PHP.
Inside the <style> tag at the top of your posted code above, add this (it can go anywhere in there):
.entry-content img {display: none;}
This simply tells the CSS no to show the image even though the browser has downloaded it.

Categories