I have
<?php while ( have_posts() ) : the_post(); ?>
<div class="boxes-third boxes-first">
<div class="latestthree">
<div class="title">
<?php get_the_title($id); ?> // I am trying to get the post title here but doesn't work
<span class="titlearrow"></span>
</div>
<div class="latestthreeimage">
<a rel="prettyPhoto" title="<?php get_the_title($id); ?>"> /same here
<?php the_post_thumbnail(array(300,133)); ?>
</a></div>
<div class="text">
Here i would like to get the excerpt of the post that is no longer than 25 words
<span class="textarrow"></span>
</div>
</div>
</div>
<?php endwhile; ?>
I am trying to do the above mentioned, but did not worked and on the last one did not find related info. I am using wp 3.7.1. Please help me.
You have used get_the_title() which does not print. To print out the title, add an extra echo:
<?php echo get_the_title(); ?>
Or you can use the_title(), which also prints:
<?php the_title();?>
Try just using,
the_title();
Reference.
Related
I am using the ACF Repeater to create rows of images/content and to show/hide when clicked. Everything looks good on desktop screens, with a row of 3 images, when an image is clicked, the hidden div shows up below and the background color toggles on so you know which image's content you are looking at.
My problem, is I am trying to get the same functionality on mobile, but when an image is clicked, the content shows up under the 3rd div. I want to be below the image that was clicked. Since I am using the ACF repeater, my php script creates the parent div (3 across) first and then the hidden divs below.
I don't mind creating a separate html markup for mobile, I just can't figure out how to make it work with the ACF repeater.
<div class="staff">
<?php if (have_rows('staff_rows')):
while (have_rows('staff_rows')): the_row(); ?>
<div class="staff-wrap">
<div class="staff_images">
<?php if (have_rows('staff_images')):
while (have_rows('staff_images')): the_row(); ?>
<a href="#/" class="<?php the_sub_field('staff_class'); ?> show staff-box">
<img src="<?php the_sub_field('staff_image'); ?>"><div class="image-box"><h3>
<?php the_sub_field('staff_name'); ?></h3>
<h3><?php the_sub_field('staff_position'); ?></h3></div>
</a>
<?php endwhile;
endif; ?>
<?php if (have_rows('staff_bios')):
while (have_rows('staff_bios')): the_row(); ?>
<div class="bios">
<div class="wrap">
<div class="<?php the_sub_field('bio_class'); ?> row"><?php
the_sub_field('bio_text'); ?></div>
</div>
</div>
<?php endwhile;
endif; ?>
</div>
http://toolboxdevmachine.com/TechNiche/about-us
Thanks for your help
I'm guessing you've already figured this out by now, in 2019. It looks like you are missing a few closing <div> tags, as well as ending your while loop and the primary conditional. I broke out the code, indented it and wrote it with the correct closing tags:
<div class="staff">
<?php if (have_rows('staff_rows')):
while (have_rows('staff_rows')): the_row(); ?>
<div class="staff-wrap">
<div class="staff_images">
<?php if (have_rows('staff_images')):
while (have_rows('staff_images')): the_row(); ?>
<a href="#/" class="<?php the_sub_field('staff_class'); ?> show staff-box">
<img src="<?php the_sub_field('staff_image'); ?>">
<div class="image-box">
<h3><?php the_sub_field('staff_name'); ?></h3>
<h3><?php the_sub_field('staff_position'); ?></h3>
</div>
</a>
<?php endwhile;
endif; ?>
<?php if (have_rows('staff_bios')):
while (have_rows('staff_bios')): the_row(); ?>
<div class="bios">
<div class="wrap">
<div class="<?php the_sub_field('bio_class'); ?> row">
<?php the_sub_field('bio_text'); ?>
</div>
</div>
</div>
<?php endwhile;
endif; ?>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
I'm having a major issue with trying to render Wordpress pagination. I'm not that good with PHP and I've tried just about every solution I can Google. Some of the queries "work" in that they display a set of page numbers, but they break when I add more variables.
For example, when I told it to display ALL pages, it did just that, but then I couldn't limit it using mid_size or any of that. So it was kind of "display all" (which I don't want), or nothing at all. I'm not sure what's breaking, so any pushes in the right direction would be excellent.
My objective: Create a list of numbered page links that truncate properly so it looks like:
[ 1 2 3 ... 97 98 99 ]
Thanks to anyone who can help me out. I'm running Wordpress 4.9.7.
My code looks like this:
<!-- post loop -->
<div class="auto cell">
<?php
// the query
$wpb_all_query = new WP_Query(array('post_type'=>'review', 'posts_per_page' => 3, 'orderby'=>'name', 'order'=>'ASC')); ?>
<?php if ( $wpb_all_query->have_posts() ) : ?>
<!-- start of main news loop -->
<?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>
<div class="grid-x grid-margin-x">
<div class="cell large-2 small-2">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="thumbnail">
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
} else { ?>
<img src="<?php bloginfo('template_directory'); ?>/img/default_thumb.png" alt="<?php the_title(); ?>" />
<?php } ?></a>
</div>
<div class="cell large-10 small-10">
<h2><?php the_title(); ?></h2>
<span class="post-meta"> By <?php the_author_posts_link(); ?> · <?php the_time('F jS, Y, g:i A'); ?> <?php edit_post_link(__('Edit This'), ''); ?></span>
<ul class="list-meta">
<li>Developer: <?php echo(types_render_field( 'game-developer' )); ?></li>
<li>Genre: <?php echo(types_render_field( 'game-genre' )); ?></li>
</ul>
</div>
<div class="post-categories cell"><?php the_category(', '); ?></div>
</div>
<?php endwhile; ?>
<!-- start of pagination -->
<div class="row">
<?php if (function_exists("pagination")) {
pagination($custom_query->max_num_pages);
} ?>
</div>
<!-- end of pagination -->
<!-- end of main news loop -->
I use this plugin for my pagination. It gives you a settings screen in the back end where you can set up how it's numbered. Hope it helps!
Good afternoon, I'm trying to display posts using PHP in the template, but I'm using the same template to output different posts depending on the age ID.
I currently have this code which works...
<?php //GET MEMBERS ?>
<?php query_posts('category_name=members&orderby=date'); ?>
<div class="row-fluid">
<ul class="thumbnails">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li class="span4">
<div class="thumbnail">
<?php // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail();
?>
<div class="pad">
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
</div>
</div>
</li>
<?php endwhile; ?>
</ul>
</div>
<?php endif; ?>
But I need to output a different "category" depending on page ID... E.G
if page id is 7 echo "php script"
else page id is 13 echo "different php script"
Thanks, Brad
Wordpress has some built in functions. You can use get_the_ID() to return the ID number to use in your if statements.
Regards
I'm displaying a custom field like this:
<div class="blog_text">
<img src="<?php the_field('imagen_prensa'); ?>" />
</div>
I would like to make the img appear only if the user has uploaded an image, because right now if there is no image then a broken image symbol appears.
I have tried the following, but it did not work:
<?php if (get_field('imagen_prensa') != ''): ?>
<img src="<?php the_field('imagen_prensa'); ?>" />
<?php endif; ?>
Any can this be achieved?
EDIT:
this is the code now using the answers below but now it gives just a blank page:
<div id="blog_interior">
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<article>
<div class="article_date"><?php the_time('d/m/Y'); ?></div>
<h2><?php echo get_the_title(); ?></h2>
<div class="blog_text">
<?php if ( !empty(the_field('imagen_prensa')) ): ?>
<img src="<?php echo the_field('imagen_prensa'); ?>" />
<?php endif; ?>
<div class="video_prensa"><?php the_field('video_prensa'); ?></div>
<?php the_content() ?>
</div>
</article>
<?php endwhile; ?>
<div class="back">
</div>
</div>
empty empty — Determine whether a variable is empty
if (!empty(get_field('imagen_prensa'))) {
// Display image
}
You forgot the echo to actually print the result of the_field('imagen_prensa').
Use this:
<?php if ( !empty(the_field('imagen_prensa')) ): ?>
<img src="<?php echo the_field('imagen_prensa'); ?>" />
<?php endif; ?>
I've edited your code, to something which seems a bit more logical also added echo's where they were missing. I'm not used to these constructions:
<?php while ( have_posts() ) : the_post(); ?>
So I'm not actually sure if it's working properly or not, but you could check what these variables output by surrounding them with a var_dump like var_dump(have_posts());
Your edited code:
<div id="blog_interior">
<?php /* Start the Loop */ ?>
<?php foreach( $posts as $post ): ?>
<div class="article_date"><?php echo the_time('d/m/Y'); ?></div>
<h2><?php echo get_the_title(); ?></h2>
<div class="blog_text">
<?php if ( !empty(the_field('imagen_prensa')) ): ?>
<img src="<?php echo the_field('imagen_prensa'); ?>" />
<?php endif; ?>
<div class="video_prensa"><?php the_field('video_prensa'); ?></div>
<?php echo the_content() ?>
</div>
<?php endforeach; ?>
<div class="back">
</div>
</div>
Try using empty() instead of comparing with an empty string.
<?php if (empty(get_field('imagen_prensa')) === false): ?>
<img src="<?php echo the_field('imagen_prensa'); ?>" />
<?php endif; ?>
empty() also checks for values like null or false which may be returned. You may also trim() the string if the field may contain only whitespaces.
As per your requirement you have set default image as no image in user.
If user have uploaded image then display its own image.
See this link may be help you. PHP: How to display a default Image if the specified one doesn't exists?
<?php query_posts($query_string . '&orderby=rand') ?>
Hey all,
I've tried to implement the above piece of code into my portfolio page template.php.
http://www.some-things.net/category/work/
It's causing the css to break every so often. Reload it until it breaks and you will see what I mean. It pushes 2 of the portfolioitem blocks to the right a touch and forces the third to drop a line?
<div style="clear:both"></div>
<div class="gallery">
<?php query_posts($query_string . '&orderby=rand') ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="portfolioItem">
<a href="<?php the_permalink() ?>" class="desctitle" title="<?php the_title();?>"><?php the_post_thumbnail(); ?>
<span class="desctitle"><?php the_title(); ?></a>
</span>
</div>
<?php endwhile; ?>
</div>
The error isn't in the random layout code. It's caused by an empty "tile" in your page. here's the source of the offending tile:
<div class="portfolioItem">
<span class="desctitle">Love Jungle</span>
</div>
Notice there's no image.