Edit search results template in Wordpress - css

I have created a page template with a nice layout using the lovely custom fields plugin so my client can easily update the content.
I created a loop on that page template that displays the relevant information nicely;
Here is the loop I made:
<?php
$args = array( 'post_type' => 'cripps_staff', 'posts_per_page' => 300 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo '<div class="col-md-3 spacetop">';
echo '<a href="'.get_permalink().'">';
echo get_post_meta($post->ID,'image',true);
echo '</a>';
echo '<h2 class="staffname">';
echo get_post_meta($post->ID,'staff_name',true);
echo '</h2>';
echo '<h2 class="staffrole">';
echo get_post_meta($post->ID,'staff_role',true);
echo '</h2>';
echo '<h2 class="staffnumber">';
echo get_post_meta($post->ID,'staff_telephone_number',true);
echo '</h2>';
echo '<h2 class="staffemail">';
echo get_post_meta($post->ID,'staff_email_address',true);
echo '</h2>';
echo '</div>';
endwhile;
?>
I created taxonomies so the staff members are split into categories.
I am then using a plugin called Taxonomies filter to create those dropdown options you will see. When you select an element in the dropdowns, Wordpress goes to/changes the page to a custom search results page I created. I want my search results to be displayed exactly like my loop on the People's template. Currently it just spits it out the title in a h1 tag.
Here is the code I got from the Twenty Fourteen theme:
<?php
// Start the Loop.
while ( have_posts() ) : the_post();
/*
* Include the post format-specific template for the content. If you want to
* use this in a child theme, then include a file called called content-___.php
* (where ___ is the post format) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
endwhile;
// Previous/next post navigation.
CrippsTheme_paging_nav();
else :
// If no content, include the "No posts found" template.
get_template_part( 'content', 'none' );
endif;
?>
How can I get the search results to look exactly like my Post loop?

I managed to resolve this completely with the help of Pieter Goosen, who provided me with an awesomely detailed response, see the full answer on Wordpress development forum:
https://wordpress.stackexchange.com/questions/143023/edit-wordpress-loop-taxonomies-filter

Related

Wordpress with Genesis framework, how do I change the output of an archive page for a custom content type?

I have an archive page for a custom content type, and I want to display one of the custom fields in the archive listing. Im not sure what hook to use or how to access the variables in the custom content type to display in -archive.php. Can anyone help me out with the relevant hooks, or how to access those field variables?
First create archive file with your custom post type, the file name should be like this archive-{post_type}.php
Go through the below code this may help you
<?php
remove_action ('genesis_loop', 'genesis_do_loop'); // Remove the standard loop
add_action( 'genesis_loop', 'custom_do_grid_loop' ); // Add custom loop
function custom_do_grid_loop() {
// Intro Text (from page content)
echo '<div class="page hentry entry">';
echo '<h1 class="entry-title">'. get_the_title() .'</h1>';
echo '<div class="entry-content">' . get_the_content() ;
$args = array(
'post_type' => 'custom post type', // enter your custom post type
'orderby' => 'menu_order',
'order' => 'ASC',
'posts_per_page'=> '12', // overrides posts per page in theme settings
);
$loop = new WP_Query( $args );
if( $loop->have_posts() ):
while( $loop->have_posts() ): $loop->the_post(); global $post;
echo '<div id="testimonials">';
echo '<div class="one-fourth first">';
echo '<div class="quote-obtuse"><div class="pic">'. get_the_post_thumbnail( $id, array(150,150) ).'</div></div>';
echo '<div style="margin-top:20px;line-height:20px;text-align:right;"><cite>'.genesis_get_custom_field( '_cd_client_name' ).'</cite><br />'.genesis_get_custom_field( '_cd_client_title' ).'</div>';
echo '</div>';
echo '<div class="three-fourths" style="border-bottom:1px solid #DDD;">';
echo '<h3>' . get_the_title() . '</h3>';
echo '<blockquote><p>' . get_the_content() . '</p></blockquote>';
echo '</div>';
echo '</div>';
endwhile;
endif;
echo '</div><!-- end .entry-content -->';
echo '</div><!-- end .page .hentry .entry -->';
}
/** Remove Post Info */
remove_action('genesis_before_post_content','genesis_post_info');
remove_action('genesis_after_post_content','genesis_post_meta');
genesis();
?>

WordPress - Display Custom Field on Post - Pull Post Title and URL

Okay, I have the code pulling the custom fields URL and title of the url. Now I can't seem to get it to show the second featured blog. Here is the working code.
<?php $related = get_post_meta($post->ID, "Featured-Blog", $single=true);
$related=explode(',',$related);
$args = array_merge( array('post__in' => $related, $wp_query->query ) );
query_posts($args);
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="<?php the_ID(); ?>">
<p class="caption"><?php the_title(); ?></p>
</div>
<?php endwhile; else: ?>
<p>no related</p>
<?php endif; wp_reset_query();?>
This code example here produces two results, which is almost what I want. Which is caused by the foreach I believe. I do not want to use the code below, but I need to find a way to add the foreach I think to get it to list all of the featured-blogs if I have more than one.
<?php
$custom_fields = get_post_custom($post_id); //Current post id
$my_custom_field = $custom_fields['Featured-Blog']; //key name
foreach ( $my_custom_field as $key => $url )
echo $key ="<a href='".$url."'>TEST</a><br /><br /><br/>";
?>
Here is a screenshot showing my Custom Fields if it helps at all, and the results they are showing on the site. screenshot
Example 1: You are using the actual word 'TITLE' for the link use <?php the_title() ?> instead
Example 2: You are not building link at all. Your href attribute is empty. Cut echo $featured_blog1 and paste it to href attribute to end up like so:
Example 3: Same as 2
Also you can delete dose instructions or put them inside <?php ?> code so they are not visible to viewers.
Hope this helps.
If you need more info just ask. ;)

Preventing Display of Post Gallery when on Homepage

I would like to prevent the post's gallery from displaying when the post is listed on the homepage.
I'm thinking it will utilize add_filter and apply_filter when post in on homepage.
You can add a gallery to posts by clicking the add media button. You can select existing images or upload additional images that will create a gallery within the post. This embeds a shortcode in $post['content'] that looks like [gallery ids="37,38,39,40,41,42].
The issue is that by default it displays when the post is included on homepage as well as the individual post itself.
Update: This is what I am doing right now to achieve the requirement. I suspect there will be a more elegant way.
<div class="entry-content">
<!-- Begin Post Content -->
<?php if ( is_single() ) : ?>
<?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'faceboard' ) ); ?>
<?php else : // Filter Gallery ShortCode out ?>
<?php
$content = '';
$content = get_the_content();
$content = preg_replace('/\[gallery\sids="[0-9]+(,[0-9]+)*,?"\s?(royalslider="\d")?\]/s',"",$content);
echo wpautop( $content, 1);
?>
<?php endif; // is_single() ?>
<!-- End Post Content -->
<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'faceboard' ), 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
You can add the following to your theme's functions.php file or to a custom plugin (better, as you can disable it without touching the theme).
The filter post_gallery is used to create your own gallery, and the $content parameter comes empty by default. If it returns empty, the original [gallery] shortcode is processed.
Here, we are using a dummy empty value, so the filter is tricked into thinking that we are passing some actual gallery content, but it's just a white space.
add_filter( 'post_gallery', 'disable_home_galleries_so_17635042', 10, 2 );
function disable_home_galleries_so_17635042( $content, $atts )
{
// http://codex.wordpress.org/Conditional_Tags
if( is_home() )
return ' ';
return $content;
}

How to display page excerpt in Wordpress

I am new in using Wordpress, I created a page that contains a long list of items.
* Item 1
* Item 2
* Item 3
* Item 4 ... and so on
I am planning to embed this page with long list of items on a separate page. How am I going to do it?
I followed tutorials online and got the idea of putting this piece of code add_post_type_support( 'page', 'excerpt' ); on functions.php. After putting the code, an new option will be available when you create/edit pages. But after that, how can I display the my page excerpt?
First to put this code on your theme function.php file.
add_action( 'init', 'my_add_excerpts_to_pages' );
function my_add_excerpts_to_pages() {
add_post_type_support( 'page', 'excerpt' );
}
After that enable excerpt for page see below define image:
Using this code to get page excerpt:
<?php echo get_the_excerpt(); ?>
<?php
query_posts("page_id=36");
while ( have_posts() ) : the_post()
?>
<h1><?php echo get_the_title(); ?></h1>
<?php the_excerpt(); ?>
<?php
endwhile;
wp_reset_query();
?>

next_post_link() function give same URL of post in wordpress

When I am writing below code for recent posts and then after I write code for next and previous link then that function will give me same link of post. If I am comment out "$tags = wp_get_post_tags($post->ID);" This line then It'll print next post link. How can I resolved this error ? please help me.
<?php
//for use in the loop, list 5 post titles related to first tag on current post
$tags = wp_get_post_tags($post->ID);
if ($tags) {
echo '<div class="articlecontent font16 bold fontgray">Related Posts</div>';
$first_tag = $tags[0]->term_id;
$args=array(
'tag__in' => array($first_tag),
'post__not_in' => array($post->ID),
'showposts'=>5,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo '<div class="articlecontent"><ul>';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><?php the_title(); ?></li>
<?php
endwhile;
echo "</ul></div>";
}
}
?>
<div class="nextprevbar">
<div class="prevtopic"><?php
previous_post_link( '%link', '<img border="0" alt="" src="'.get_template_directory_uri().'/images/prev-bullet.gif">' . _x( ' ', 'Previous post link', 'twentyten' ) . ' %title' ); ?></div>
<div class="nexttopic"><?php next_post_link( '%link', '%title <img border="0" alt="" src="'.get_template_directory_uri().'/images/next-bullet.gif">' . _x( ' ', 'Next post link', 'twentyten' ) . '</span>' ); ?></div>
</div>
The problem has to be in the $post variable. Before this line is executed:
while ($my_query->have_posts()) : $my_query->the_post(); ?>
the $post var holds the current post data (I guess this code is inside single.php?). But after this line, and inside the loop, the $post var holds your various recent posts, one by one (you setup the $post variable when you call the_post() ).
After that loop (bellow the endwhile), $post will hold the data of the last post retrieved in that loop.
previous_post_link() and next_post_link() need to access $post for reference of the current post, but they are taking as reference the last post of your recent posts, instead of the post being read by your user.
I don't know what the html structure of this page is, but I would put the recent posts list AFTER the navigation links (next, previous posts). That would solve the problem if I am right, and in my opinion it would be semantically clearer.
Or you could also try this:
Add this line:
$currentPost = clone $post;
Before:
$my_query = new WP_Query($args);
And add this line:
<?php $post = $currentPost; ?>
Before you call next and previous post links functions.

Resources