I am running in to an issue with making my own search loop in Wordpress. What I am trying to achieve is that certain circumstances display only certain information:
<?php while ( have_posts() ) : the_post(); echo '<div>'; ?>
<?php if ( in_category('property') ) { ?>
<h3><?php the_title(); ?></h3>
<?php the_field('main-image-description'); ?>
<span class="launch">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'boilerplate' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<span class="link">click to launch</span>
<span class="launch-icon"></span>
</a>
</span>
<?php } ?>
<?php if ( in_category('all-developments') ) { ?>
<h3><?php the_title(); ?></h3>
<?php the_field('property-description'); ?>
<span class="launch-brochure">
<a href="<?php the_field('pdf-download-all-developments'); ?>" target="_blank">
<span class="link">Download Brochure</span>
<span class="launch-icon"></span>
</a>
</span>
<?php } ?>
<?php if ( is_page() ) { ?>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<span class="launch">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'boilerplate' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<span class="link">click to launch</span>
<span class="launch-icon"></span>
</a>
</span>
<?php } ?>
<?php echo '</div>'; endwhile; ?>
The issue that arises, is that is will always render one or two empty tags at the top and this ruins the style of it, as each div has a dotted border. Is there a way of telling Wordpress that if not of these conditions are met, then don't display the <div>?
Thanks in advance for any help!
JP
Rearrange your code so you compute the conditions before you output the content like so:
<?php
while ( have_posts() ) : the_post();
$propertyCategory = in_category('property');
$allDevelopmentsCategory = in_category('all-developments');
$isPage = is_page();
$output = ($propertyCategory || $allDevelopmentsCategory || $isPage);
if($output){
echo '<div>';
}
?>
<?php if ( $propertyCategory ) { ?>
<h3><?php the_title(); ?></h3>
<?php the_field('main-image-description'); ?>
<span class="launch">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'boilerplate' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<span class="link">click to launch</span>
<span class="launch-icon"></span>
</a>
</span>
<?php } ?>
<?php if ( $allDevelopmentsCategory ) { ?>
<h3><?php the_title(); ?></h3>
<?php the_field('property-description'); ?>
<span class="launch-brochure">
<a href="<?php the_field('pdf-download-all-developments'); ?>" target="_blank">
<span class="link">Download Brochure</span>
<span class="launch-icon"></span>
</a>
</span>
<?php } ?>
<?php if ( $isPage ) { ?>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<span class="launch">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'boilerplate' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<span class="link">click to launch</span>
<span class="launch-icon"></span>
</a>
</span>
<?php } ?>
<?php
if($output){
echo '</div>';
}
endwhile;
?>
This allows you to detect if anything will be output and then uses a div where appropriate.
Can you just move the <div> inside the conditional statements? Like so:
<?php while ( have_posts() ) : the_post(); ?>
<?php if ( in_category('property') ) { ?>
<div> <!-- Open div here !-->
<h3><?php the_title(); ?></h3>
<?php the_field('main-image-description'); ?>
<span class="launch">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'boilerplate' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<span class="link">click to launch</span>
<span class="launch-icon"></span>
</a>
</span>
</div> <!-- Close div here !-->
<?php } ?>
<?php if ( in_category('all-developments') ) { ?>
<div> <!-- Open div here !-->
<h3><?php the_title(); ?></h3>
<?php the_field('property-description'); ?>
<span class="launch-brochure">
<a href="<?php the_field('pdf-download-all-developments'); ?>" target="_blank">
<span class="link">Download Brochure</span>
<span class="launch-icon"></span>
</a>
</span>
</div> <!-- Close div here !-->
<?php } ?>
<?php if ( is_page() ) { ?>
<div> <!-- Open div here !-->
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<span class="launch">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'boilerplate' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<span class="link">click to launch</span>
<span class="launch-icon"></span>
</a>
</span>
</div> <!-- Close div here !-->
<?php } ?>
<?php endwhile; ?>
Related
I want to show tag based post in related post. Here is the complete template code for my related post loop (loop.related.post. php ) What changes do I need to make in this loop? My theme is custom. I want to show 6 posts in related posts.
<?php
global $wpdb, $post, $wp_query;
$URLs_Link_MP3 = get_post_meta( $post->ID, 'URLs_Link_MP3', true );
$durations_MP3 = get_post_meta( $post->ID, 'durations_MP3', true );
if(!$durations_MP3) $durations_MP3 = '0';
global $wpdb, $post, $wp_query;
$durations_MP3 = get_post_meta( $post->ID, 'durations_MP3', true ); if(!$durations_MP3) $durations_MP3 = '0';?>
<div class="col-sm-6 item" data-id="<?php the_ID(); ?>" data-value="<?php echo $URLs_Link_MP3 ; ?>" >
<div class="row">
<div class="button dark player loader" duration="<?php echo $durations_MP3 ; ?>">
<svg class="icon icon-play">
<use xlink:href="#icon-play"/>
</svg>
</div>
<a class="details" href="<?php the_permalink() ?>" title="<?php the_title(); ?> PDF Download">
<h2 class="title"><?php the_title(); ?></h2>
<p><?php echo $durations_MP3 ; ?> <?php global $opt_themes; if($opt_themes['rtones_Sec']) { ?><?php echo $opt_themes['rtones_Sec']; ?><?php } ?> - <?= ex_themes_get_post_view_(); ?> <?php global $opt_themes; if($opt_themes['rtones_Author_Download']) { ?><?php echo $opt_themes['rtones_Author_Download']; ?><?php } ?></p>
</a>
</div>
<?php global $opt_themes; if($opt_themes['ex_themes_tags_all_active_']) { ?>
<div class="row">
<?php
$post_tags = get_the_tags();
if ( ! empty( $post_tags ) ) {
echo '<ul class="tags">';
foreach( $post_tags as $post_tag ) {
echo '<li>' . str_replace('ringtones', ' ', $post_tag->name) . '</li>';
}
echo '</ul>';
} else {
echo '<ul class="tags">';
echo '<li><a>no tags</a></li>';
echo '</ul>';
}
?>
</div>
<?php } ?>
<div class="row">
<div class="actions">
<div class="button light fav">
<?php if ( shortcode_exists( 'favorite_button' ) ): ?><?php echo do_shortcode( '[favorite_button]' ); ?><?php else: ?><?php endif;?>
</div>
<div class="button light share">
<svg class="icon">
<use xlink:href="#icon-share"/>
</svg>
</div>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<div class="button dark download">
<svg class="icon">
<use xlink:href="#icon-download2"/>
</svg>
</div>
</a>
</div>
</div>
</div>
I'm trying to show different text for the buttons on my search.php page, depending on whether the post_class is product or post.
This is what I have so far:
<?php
if(isset($_GET['post_class'])) {
$type = $_GET['post_class'];
if($type == 'product') {?>
<div class="post_more">
<a itemprop="url" href="<?php the_permalink(); ?>" class="qbutton small"><?php esc_html_e('Shop Now','bridge'); ?></a>
</div>
<?php
} elseif($type == 'post') {?>
<div class="post_more">
<a itemprop="url" href="<?php the_permalink(); ?>" class="qbutton small"><?php esc_html_e('Read More','bridge'); ?></a>
</div>
<?php }
}
?>
It's currently showing nothing though.
Addition:
I'm adding the full code of my page, in case it helps you to help me:
<?php
$bridge_qode_options = bridge_qode_return_global_options();
$bridge_qode_blog_hide_comments = "";
if (isset($bridge_qode_options['blog_hide_comments'])) {
$bridge_qode_blog_hide_comments = $bridge_qode_options['blog_hide_comments'];
}
$bridge_qode_blog_hide_author = "";
if (isset($bridge_qode_options['blog_hide_author'])) {
$bridge_qode_blog_hide_author = $bridge_qode_options['blog_hide_author'];
}
$bridge_qode_like = "on";
if (isset($bridge_qode_options['qode_like'])) {
$bridge_qode_like = $bridge_qode_options['qode_like'];
}
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="post_content_holder">
<?php if ( has_post_thumbnail() ) { ?>
<div class="post_image">
<a itemprop="url" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail('full'); ?>
</a>
</div>
<?php } ?>
<div class="post_text">
<div class="post_text_inner">
<h3 itemprop="name" class="entry_title"><span itemprop="dateCreated" class="date entry_date updated"><meta itemprop="interactionCount" content="UserComments: <?php echo get_comments_number(bridge_qode_get_page_id()); ?>"/></span> <a itemprop="url" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
<div class="post_info">
<?php $bridge_qode_category = get_the_category(get_the_ID()); ?>
<?php if(!empty($bridge_qode_category)){ ?>
<?php }
?>
<?php if($bridge_qode_blog_hide_author == "no") { ?>
<span class="post_author">
<?php esc_html_e('by','bridge'); ?>
<a itemprop="author" class="post_author_link" href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"><?php the_author_meta('display_name'); ?></a>
</span>
<?php } ?>
<?php if($bridge_qode_blog_hide_comments != "yes"){ ?>
<span class="dots"><i class="fa fa-square"></i></span><a itemprop="url" class="post_comments" href="<?php comments_link(); ?>" target="_self"><?php comments_number('0 ' . esc_html__('Comments','bridge'), '1 '.esc_html__('Comment','bridge'), '% '.esc_html__('Comments','bridge') ); ?></a>
<?php } ?>
<?php if( $bridge_qode_like == "on" ) { ?>
<span class="dots"><i class="fa fa-square"></i></span><div class="blog_like">
<?php if( function_exists('bridge_core_like') ) bridge_core_like(); ?>
</div>
<?php } ?>
<?php if(isset($bridge_qode_options['enable_social_share']) && $bridge_qode_options['enable_social_share'] == "yes") { ?>
<span class="dots"><i class="fa fa-square"></i></span><?php echo do_shortcode('[social_share]'); ?>
<?php } ?>
</div>
<?php
$bridge_qode_my_excerpt = get_the_excerpt();
if ($bridge_qode_my_excerpt != '') {
echo bridge_qode_get_module_part( $bridge_qode_my_excerpt );
}
?>
<?php if ( ! post_password_required() ) { ?>
<?php
if(isset($_GET['post_class'])) {
$type = $_GET['post_class'];
if($type == 'product') {?>
<div class="post_more">
<a itemprop="url" href="<?php the_permalink(); ?>" class="qbutton small"><?php esc_html_e('Shop Now','bridge'); ?></a>
</div>
<?php
} elseif($type == 'post') {?>
<div class="post_more">
<a itemprop="url" href="<?php the_permalink(); ?>" class="qbutton small"><?php esc_html_e('Read More','bridge'); ?></a>
</div>
<?php }
} ?>
</div>
</div>
</div>
</article>
Updated: This is about post_type in the query search so you can use:
<?php
global $wp_query;
// For testing (uncomment the line below)
// echo '<pre>'. print_r( $wp_query, true ) . '</pre>';
if( isset($wp_query->query['s']) && isset($wp_query->query['post_type'])
&& $wp_query->query['post_type'] === 'product' ) {?>
<div class="post_more">
<a itemprop="url" href="<?php the_permalink(); ?>" class="qbutton small"><?php esc_html_e('Shop Now','bridge'); ?></a>
</div>
<?php
} elseif( isset($wp_query->query['s']) && ! isset($wp_query->query['post_type']) ) {?>
<div class="post_more">
<a itemprop="url" href="<?php the_permalink(); ?>" class="qbutton small"><?php esc_html_e('Read More','bridge'); ?></a>
</div>
<?php } ?>
Tested and works
I need to fetch the featured images of posts in WordPress Currently, I am having the code for listing posts with images and text.
I am having a posts page that lists all posts I need to list the photos of the posts to another page
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( has_post_thumbnail() ) : ?>
<div class="entry-thumb">
<?php the_post_thumbnail( 'oblique-entry-thumb'); ?>
<a class="thumb-link" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><i class="fa fa-link"></i></a>
</div>
<?php else : ?>
<div class="entry-thumb">
<img src="http://placehold.it/500x500" />
<a class="thumb-link" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><i class="fa fa-link"></i></a>
</div>
<?php endif; ?>
<?php //if ( has_post_thumbnail() ) : ?>
<div class="post-inner post-inner-height">
<?php //else : ?>
<!-- <div class="post-inner no-thumb"> -->
<?php //endif; ?>
<header class="entry-header">
<?php the_title( sprintf( '<h1 class="entry-title entry-title-height">', esc_url( get_permalink() ) ), '</h1>' ); ?>
<?php if ( 'post'==g et_post_type() && !get_theme_mod( 'meta_index') ) : ?>
<!-- .entry-meta -->
<?php endif; ?>
</header>
<!-- .entry-header -->
<div class="entry-content entry-con-fixh">
<?php the_excerpt(); ?>
<?php wp_link_pages( array( 'before'=>'
<div class="page-links">' . __( 'Pages:', 'oblique' ), 'after' => '</div>', ) ); ?>
</div>
<!-- .entry-content -->
</div>
<?php if (!get_theme_mod( 'read_more')) : ?>
<div class="read-more">
<a href="<?php the_permalink(); ?>">
<?php echo __( 'Continue reading …', 'oblique'); ?>
</a>
</div>
<?php endif; ?>
</article>
<!-- #post-## -->
This is the code I am having. If I am having 50 posts how can I able to filter the images from that post
I tried using the following code
<?php if ( has_post_thumbnail() ) : ?>
<div class="entry-thumb">
<?php the_post_thumbnail( 'oblique-entry-thumb'); ?>
<a class="thumb-link" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><i class="fa fa-link"></i></a>
</div>
<?php else : ?>
<div class="entry-thumb">
<img src="http://placehold.it/500x500" />
<a class="thumb-link" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><i class="fa fa-link"></i></a>
</div>
<?php endif; ?>
but it wont display all images it shows only the dummy image that I placed
If you want all post then you need to iterate over them and fetch the post thumbnail.
<?php
// define query fields
$query = array(
// define post type to query
'post_type' => 'post',
// define posts count as -1, to fetch all
'posts_per_page' => -1
);
// query the post
$posts = query_posts($query);
// iterate over the posts
foreach ($posts as $post): ?>
<!-- echo the thumbnail -->
<?php echo get_the_post_thumbnail($post->ID); ?>
<!-- rest of the HTML -->
<?php endforeach; ?>
I would like to know what do i need to add in css to make the logo move in the left position before site-title in WordPress?
// Display Site Title
add_action( 'smartline_site_title', 'smartline_display_site_title' );
function smartline_display_site_title() { ?>
<img src="<?php bloginfo('template_directory');?>/images/AA.gif">
<a href="<?php echo esc_url(home_url('/')); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
<h1 class="site-title"><?php bloginfo('name'); ?></h1>
</a>
<?php
}
This should do it :
Add #logo img{float:left;} code to your CSS and then check.
EDITED
#logo img{float:left;margin-top:-3%;}
#logo .site-title{margin-top:2%;}
<!--logo-floater-->
<div id="logo-floater">
<?php if ($logo): ?>
<a href="<?php print check_url($front_page); ?>" title="<?php print t('Home'); ?>">
<img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" />
</a>
<?php endif; ?>
<?php if ($site_name || $site_slogan): ?>
<div class="clearfix">
<?php if ($site_name): ?>
<span id="site-name"><?php print $site_name; ?></span>
<?php endif; ?>
<?php if ($site_slogan): ?>
<span id="slogan"><?php print $site_slogan; ?></span>
<?php endif; ?>
</div>
<?php endif; ?>
</div> <!--EOF:logo-floater-->
This displays the logo first, to switch them try,
<!--logo-floater-->
<div id="logo-floater">
<?php if ($site_name || $site_slogan): ?>
<div class="clearfix">
<?php if ($site_name): ?>
<span id="site-name"><?php print $site_name; ?></span>
<?php endif; ?>
<?php if ($site_slogan): ?>
<span id="slogan"><?php print $site_slogan; ?></span>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ($logo): ?>
<a href="<?php print check_url($front_page); ?>" title="<?php print t('Home'); ?>">
<img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" />
</a>
<?php endif; ?>
</div> <!--EOF:logo-floater-->
Alright, so I have this block of code in my current theme:
<div class="content_block">
<?php the_content(); ?>
<div class="<?php echo $left_block; ?>">
<?php $project_photos = get_post_meta( get_the_ID(), 'project_photo_photo' );
if ( $project_photos ) : ?>
<div class="grid_gallery clearfix">
<?php foreach( $project_photos as $project_photo ) { ?>
<figure class="gallery_item featured-thumbnail thumbnail single-gallery-item">
<a href="/brv2/wp-content/files_mf/<?php echo $project_photo; ?>" class="image-wrap" rel="prettyPhoto[gallery]">
<img class="project_photo_photo" width="260" src="/brv2/wp-content/files_mf/<?php echo $project_photo; ?>" alt="<?php the_title(); ?>" />
<span class="zoom-icon"></span>
</a>
</figure>
<?php } ?>
<!--END .slider -->
</div>
<?php endif; ?>
What I need to do is to add a DIV wrap around "the_content" if and only if the $project_photos selector is active, not being a PHP developer this is what I've come up with but it doesn't work:
<div class="content_block">
<?php if ( $project_photos() ) {
echo '<div class="project_description">';
the_content();
echo '</div>';
} else {
the_content();
} ?>
<div class="<?php echo $left_block; ?>">
<?php $project_photos = get_post_meta( get_the_ID(), 'project_photo_photo' );
if ( $project_photos ) : ?>
<div class="grid_gallery clearfix">
<?php foreach( $project_photos as $project_photo ) { ?>
<figure class="gallery_item featured-thumbnail thumbnail single-gallery-item">
<a href="/brv2/wp-content/files_mf/<?php echo $project_photo; ?>" class="image-wrap" rel="prettyPhoto[gallery]">
<img class="project_photo_photo" width="260" src="/brv2/wp-content/files_mf/<?php echo $project_photo; ?>" alt="<?php the_title(); ?>" />
<span class="zoom-icon"></span>
</a>
</figure>
<?php } ?>
<!--END .slider -->
</div>
<?php endif; ?>
If anyone could provide some guidance on how I might accomplish this I would be very grateful.
Thanks in advance.
Can you give this a try?
<div class="content_block">
<?php
$project_photos = get_post_meta( get_the_ID(), 'project_photo_photo' );
if ( $project_photos ) {
echo '<div class="project_description">';
the_content();
echo '</div>';
} else {
the_content();
} ?>
<div class="<?php echo $left_block; ?>">
<?php
if ( $project_photos ) : ?>
<div class="grid_gallery clearfix">
<?php foreach( $project_photos as $project_photo ) { ?>
<figure class="gallery_item featured-thumbnail thumbnail single-gallery-item">
<a href="/brv2/wp-content/files_mf/<?php echo $project_photo; ?>" class="image-wrap" rel="prettyPhoto[gallery]">
<img class="project_photo_photo" width="260" src="/brv2/wp-content/files_mf/<?php echo $project_photo; ?>" alt="<?php the_title(); ?>" />
<span class="zoom-icon"></span>
</a>
</figure>
<?php } ?>
<!--END .slider -->
</div>
<?php endif; ?>