for a project I am working on I have been trying to set up a wordpress post loop on a subpage which woould display all posts as a thumbnail image with the posts title underneath. However I do not get any posts listet but rather just one link referring to the subpage the gallery should be on. Could anyone help me out please?
Here is my code which is saved as page-gallery.php in my childthemes folder:
<?php get_header(); ?>
<div id="main" class="wrapper">
<?php global $query_string; if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="gallery_image_container">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<div class="gallery_image_thumb">
<?php the_post_thumbnail('thumbnail'); ?>
</div>
<h2><?php the_title(); ?></h2>
</a>
</div>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
<?php get_footer(); ?>
The CSS is the following:
.gallery_container {
position: relative;
float: left;
width: 150px;
height: 150px;
border: 10px solid #CCC;
margin: 20px;
}
I have created a jsfiddle to tell you what I want to achieve in the end: http://jsfiddle.net/vdpktLxr/
Your code just echos the content of your page "page-gallery.php" . For displaying POSTS you need to use another loop, for example something like this:
<?php
// The Query
query_posts( $args );
// The Loop
while ( have_posts() ) : the_post();
echo '<li>';
the_title();
echo '</li>';
endwhile;
// Reset Query
wp_reset_query();
?>
You can find more info here
Related
I try to realize a wordpress loop to display the articles on my blog. I'm trying to create a design like this: www.freileben.net
My wordpress loop looks like this:
.thumbnail {
float: left;
margin-right: 50px;
}
#post {
margin-top: 120px;
padding-top: 15px;
}
<article id="post">
<div id="thumbnail">
<?php if ( function_exists( 'has_post_thumbnail') && has_post_thumbnail() ) { the_post_thumbnail(array(350,220), array( "class"=>"thumbnail")); } ?>
</div>
<h2><?php the_title(); ?></h2>
<div class="entry">
<?php the_excerpt(); ?>
</div>
<?php endwhile; ?>
</article>
I don't know how to solve the problem because all of the images I use have got a different size and they are not in the same position.
Try this below code :
<article id="post">
<?php
// the query
$args = array('');
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) { ?>
<!-- the loop -->
<?php while ( $the_query->have_posts() ) {
$the_query->the_post(); ?>
<div id="thumbnail">
<?php
// Must be inside a loop.
if ( has_post_thumbnail() ) {
the_post_thumbnail(array( "class"=>"thumbnail"));
}
?>
</div>
<h2><?php the_title(); ?></h2>
<div class="entry">
<?php the_excerpt(); ?>
</div>
<?php } } else { ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php } ?>
<!-- end of the loop -->
<?php wp_reset_postdata(); ?>
I am working on wordpress ACF, with posts and a single gallery of images. Both display perfectly.
But I am trying to load my ACF's image gallery AFTER the posts... I try many different ways, playing around with 'endif' / 'endwhile' nothing works.
Any idea of how to change the order ?
Thanks !
#gallerie {
width: 100%; z-index: 990; position: relative; margin-top: 700px;
}
div.image-home {
text-align: center;
margin-bottom: 40px;
}
.post{width: 30%; float: left;}
That's it for the important css
(the menu on top is fixed)
<?php if(have_posts()) : ?>
<!-- beginning of the gallery -->
<div id="gallerie">
<?php ;?>
<?php $images = get_field('image_gallery');?>
<?php if( $images ): ?>
<div class="image-home">
<?php foreach( $images as $image ): ?>
<a href="<?php echo $image['url']; ?>">
<img src="<?php echo $image['sizes']['medium']; ?>" alt="<?php echo $image['alt']; ?>" />
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<!-- end of the gallery -->
<?php while(have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>"><br>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="contenu">
<p><?php the_field('description'); ?></p>
<p class="postmetadata"><?php the_time('j F Y') ?> par <?php the_author() ?></p>
</div>
</div>
<?php endwhile; ?>
It appears you've posted the gallery prior to where the post loop exists entirely (ie, not even at the start of the loop, but before it.)
If you take that same gallery snippet and place it right AFTER the final endwhile, you'll get more of an acceptable result.
edit: It's really hard to comment without knowing or seeing more of the desired result, ie that same snippet could be posted right BEFORE the final endwhile if it is repeated for each post.
CSS
only changed one line:
#gallerie {
width: 100%; z-index: 990; position: relative; margin-top: 20px;
}
PHP
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>"><br>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="contenu">
<p><?php the_field('description'); ?></p>
<p class="postmetadata"><?php the_time('j F Y') ?> par <?php the_author() ?></p>
</div>
</div>
<?php endwhile; ?>
<!-- beginning of the gallery -->
<div id="gallerie">
<?php ;?>
<?php $images = get_field('image_gallery');?>
<?php if( $images ): ?>
<div class="image-home">
<?php foreach( $images as $image ): ?>
<a href="<?php echo $image['url']; ?>">
<img src="<?php echo $image['sizes']['medium']; ?>" alt="<?php echo $image['alt']; ?>" />
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<!-- end of the gallery -->
Chrome Dev Tools are Awesome
Also, you're using Chrome which is a great development tool within itself, you're on the Mac, so when you're on your page press Command+Option and i. That will open the Dev Tools.
Expand your code and as you hover over each line (on the code side) you will see in the viewport your margin elements. This will allow you to play with your styling and get it perfected
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.
I've looked this up and have found numerous similar issues - tried troubleshooting but couldn't work it out, I can't for the life of me figure out why the div is dropping below the blog post, pushing everything out. The sidebar should sit next to the blog post, i.e. 3/4 post, 1/4 sidebar. Instead the sidebar is pushed below the post. This happens to all posts regardless of images/text etc.... so it's not an image or text issue from what I gather.
http://pastestudios.com/buying-property-sydney/
<div id="pageHead">
<?php $blog_page_id = of_get_option('ttrust_blog_page'); ?>
<?php $blog_page = get_page($blog_page_id); ?>
<h1><?php echo $blog_page->post_title; ?></h1>
<?php $page_description = get_post_meta($blog_page_id, "_ttrust_page_description_value", true); ?>
<?php if ($page_description) : ?>
<p><?php echo $page_description; ?></p>
<?php endif; ?>
</div>
<div id="content" class="threeFourth clearfix">
<?php while (have_posts()) : the_post(); ?>
<div <?php post_class(); ?>>
<h1><a href="<?php the_permalink() ?>" rel="bookmark" ><?php the_title(); ?></a></h1>
<div class="meta clearfix">
<?php $post_show_author = of_get_option('ttrust_post_show_author'); ?>
<?php $post_show_date = of_get_option('ttrust_post_show_date'); ?>
<?php $post_show_category = of_get_option('ttrust_post_show_category'); ?>
<?php $post_show_comments = of_get_option('ttrust_post_show_comments'); ?>
<?php if($post_show_author || $post_show_date || $post_show_category){ _e('Posted ', 'themetrust'); } ?>
<?php if($post_show_author) { _e('by ', 'themetrust'); the_author_posts_link(); }?>
<?php if($post_show_date) { _e('on', 'themetrust'); ?> <?php the_time( 'M j, Y' ); } ?>
<?php if($post_show_category) { _e('in', 'themetrust'); ?> <?php the_category(', '); } ?>
<?php if(($post_show_author || $post_show_date || $post_show_category) && $post_show_comments){ echo " | "; } ?>
<?php if($post_show_comments) : ?>
<?php comments_number(__('No Comments', 'themetrust'), __('One Comment', 'themetrust'), __('% Comments', 'themetrust')); ?>
<?php endif; ?>
</div>
<?php if(of_get_option('ttrust_post_show_featured_image')) : ?>
<?php if(has_post_thumbnail()) : ?>
<?php if(of_get_option('ttrust_post_featured_img_size')=="large") : ?>
<?php the_post_thumbnail('ttrust_post_thumb_big', array('class' => 'postThumb', 'alt' => ''.get_the_title().'', 'title' => ''.get_the_title().'')); ?>
<?php else: ?>
<?php the_post_thumbnail('ttrust_post_thumb_small', array('class' => 'postThumb alignleft', 'alt' => ''.get_the_title().'', 'title' => ''.get_the_title().'')); ?>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="pagination clearfix">Pages: ', 'after' => '</div>' ) ); ?>
</div>
<?php comments_template('', true); ?>
<?php endwhile; ?>
</div>
<?php get_sidebar(); ?>
First, set box-sizing: border-box
Next, make #content and #sidebar equal to 100% width. Right now you have #content set at 100% and #sidebar set in pixels so, naturally, it will push your sidebar down.
Try something like:
* { box-sizing: border-box; }
#content {
width: 65%;
}
#sidebar {
width: 35%;
}
Your article area is 100% wide. So there is no space for sidebar. Try to adjust width and margins to make total 100. Something like following code.
#content {
width: 70%;
float: left;
margin-left: 3%;
}
#sidebar {
width: 22%;
float: right;
margin-right: 3%;
}
Your image at Blog page does not adjust with browser width. See it in smaller screen size. To make it adjustable and remove horizontal scrollbar at smaller resolutions, use following CSS code.
#content .alignleft,
#content img.alignleft {
max-width: 100%;
}
It looked like you may have been working on it while I had a look at it. At the time I was able to change width: 100%; to width: 720px; in your #content id and it seemed to work in getting the sidebar vertically aligned to top, side by side with your content area.
I also noticed you had multiple ids of the same name, #content in particular. Might want to clean up the css so you can look at it more clearly if you have any more problems. Happens to me all the time when I'm chasing a problem, my css gets out of control and I lose track of the changes I made to try and correct the problems.
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>