how to create breadcrumbs using wordpress nav menu without plugin? - wordpress

trying to show breadcrumbs but i am stuck.
ABOUT US
- TEAM
- WHAT WE DO
i don't understand how to show all menus dynamically in breadcrumbs, if i am currently on what we do page then how to show in breadcrumbs kindly help me
i try this
<?php $menuID = $post->ID;
query_posts( 'post_type=page&post_parent=$menuID' );
while ( have_posts() ) : the_post();
the_title();
endwhile;
?>
this code just show child of every page but how can i find page which one is clicked

Place this code in custom_functions.php:
function the_breadcrumb() {
global $post;
echo '<ul id="breadcrumbs">';
if (!is_home()) {
echo '<li><a href="';
echo get_option('home');
echo '">';
echo 'Home';
echo '</a></li><li class="separator"> / </li>';
if (is_category() || is_single()) {
echo '<li>';
the_category(' </li><li class="separator"> / </li><li> ');
if (is_single()) {
echo '</li><li class="separator"> / </li><li>';
the_title();
echo '</li>';
}
} elseif (is_page()) {
if($post->post_parent){
$anc = get_post_ancestors( $post->ID );
$title = get_the_title();
foreach ( $anc as $ancestor ) {
$output = '<li>'.get_the_title($ancestor).'</li> <li class="separator">/</li>';
}
echo $output;
echo '<strong title="'.$title.'"> '.$title.'</strong>';
} else {
echo '<li><strong> '.get_the_title().'</strong></li>';
}
}
}
elseif (is_tag()) {single_tag_title();}
elseif (is_day()) {echo"<li>Archive for "; the_time('F jS, Y'); echo'</li>';}
elseif (is_month()) {echo"<li>Archive for "; the_time('F, Y'); echo'</li>';}
elseif (is_year()) {echo"<li>Archive for "; the_time('Y'); echo'</li>';}
elseif (is_author()) {echo"<li>Author Archive"; echo'</li>';}
elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "<li>Blog Archives"; echo'</li>';}
elseif (is_search()) {echo"<li>Search Results"; echo'</li>';}
echo '</ul>';
}
Go to your single.php page and add the following code anywhere you want to display the breadcrumbs.
<?php the_breadcrumb(); ?>

Related

Different Styling for Last Thumbnail in Advance Custom Fields Pro Gallery

I've created an image gallery using Advance Custom Fields pro with lighbox and limited it to show only 4 thumbnails, and that's working perfectly. When someone click on any thumbnail, the gallery opens up in lightbox and shows all the images in it.
Now I want to use different css styling for the 4th thumbnail but don't know how to do that.
Here's my code:
<?php
$images = get_field('menu_gallery');
$image_1 = $images[0];
if( $images ) { ?>
<ul class="gal-grid">
<?php
$i = 0;
foreach( $images as $image ) {
if ($i >= 5) {
$content = '<li class="gal-grid-zom">';
$content = '<a class="gallery_image" href="'. $image['url'] .'"></a>';
$content .= '</li>';
} else {
$content = '<li class="gal-grid">';
$content = '<li class="gal-grid"><a class="gallery_image" href="'. $image['url'] .'">';
$content .= '<img class="gallery-zom" src="'. $image['sizes']['thumbnail'] .'" alt="'. $image['alt'] .'" />';
$content .= '</a>';
$i++;
}
$content .= '</li>';
if ( function_exists('slb_activate') ) {
$content = slb_activate($content);
}
echo $content;
?>
<?php } ?>
<?php } ?> </ul>
Can someone help me regarding this issue?
You can add the $key inside your foreach loop :
foreach( $images as $key => $image ) {
if( $key === 3 ) {
// it will show the specific <li> for the 4th iteration.
<li class="fourth-grid">The Image</li>
} else {
<li class="gal-grid">The image</li>
}
}

Wordpress blog pagination error

An the bottom of the blog page of my WordPress site, there are numbers for pagination.
Assume my initial blog post page is https://example.com/blog
When I click number '2' to view more posts. My url changed as https://example.com/blogpage/2
However if i manually enter the url as https://example.com/blog/page/2 it goes to the second page of blog posts.
I only get this error when i am in page 1. When
I am in page 2 or page 3, the pagination links work fine
How can I correct this issue?
index.php file contains this code
<?php
global $wp_query, $wpl_exe_wp;
get_header();
get_template_part('part', 'breadcrumbs');
$style = $wpl_exe_wp->get_option('blog_archive_layout', 'system_layouts');
$read_more_text = $wpl_exe_wp->get_option('blog_read_more_text', 'system_layouts');
if( is_author() ) {
$style = $wpl_exe_wp->get_option('author_archive_layout', 'system_layouts');
$read_more_text = $wpl_exe_wp->get_option('author_read_more_text', 'system_layouts');
}
if( is_search() ) {
$read_more_text = $wpl_exe_wp->get_option('search_read_more_text', 'system_layouts');
if( get_query_var('post_type') == 'product' ) {
} else {
$style = $wpl_exe_wp->get_option('search_layout', 'system_layouts');
}
}
if( is_post_type_archive('wproto_portfolio') || is_tax( 'wproto_portfolio_category' ) ) {
$style = $wpl_exe_wp->get_option('portfolio_archive_layout', 'system_layouts');
$read_more_text = $wpl_exe_wp->get_option('portfolio_read_more_text', 'system_layouts');
}
?>
<section class="container" id="content">
<div class="row">
<div class="<?php echo wpl_exe_wp_front::content_classes( true ) . ' wproto-primary-content-area'; ?>">
<?php if( is_author() && $wpl_exe_wp->get_option('author_page_display_info', 'system_layouts') ): ?>
<!--
ABOUT AUTHOR INFO
-->
<?php wpl_exe_wp_front::about_author(); ?>
<?php endif; ?>
<?php if( is_post_type_archive('wproto_portfolio') || is_tax( 'wproto_portfolio_category' ) ): ?>
<!--
PORTFOLIO POSTS
-->
<?php echo do_shortcode('[wproto_portfolio read_more_text="' . esc_attr( $read_more_text ) . '" use_wp_query="1" posts_per_page="' . get_option('posts_per_page') . '" order_by="date" sort_by="DESC" style="' . esc_attr( $style ) . '" display_pagination="1" pagination_style="numeric_with_prev_next"]'); ?>
<?php else: ?>
<!--
POSTS
-->
<?php
$term_description = term_description();
if( $term_description <> '' ) {
echo wp_kses_post( $term_description );
}
?>
<?php echo do_shortcode('[wproto_blog read_more_text="' . esc_attr( $read_more_text ) . '" use_wp_query="1" posts_per_page="' . get_option('posts_per_page') . '" order_by="date" sort_by="DESC" style="' . esc_attr( $style ) . '" display_pagination="1" pagination_style="numeric_with_prev_next"]'); ?>
<?php endif; ?>
<div class="clearfix"></div>
</div>
<?php get_sidebar(); ?>
</div>
</section>

How to create wordpress shortcode by this code

Sir,
I have this code to show all post of category and thumbnail for 1st post of them.
<?php $recent = new WP_Query(); ?>
<?php $recent->query( 'cat=1&showposts=5' ); ?>
<?php $is_first_post = true; ?>
<?php while( $recent->have_posts() ) : $recent->the_post(); ?>
<ul>
<li>
<?php
if ( $is_first_post && has_post_thumbnail() ) {
the_post_thumbnail();
$is_first_post = false;
}
?>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</li>
</ul>
<?php endwhile; ?>
But I want show this using shortcode. which using category & post number
but I can not make shortcode. Please help me.
// Add Shortcode
function recentpost_shortcode_func() {
$recent = new WP_Query();
$recent->query( 'cat=1&showposts=5' );
$is_first_post = true;
$html = '';
while( $recent->have_posts() ) : $recent->the_post();
$html .='<ul><li>';
if ( $is_first_post && has_post_thumbnail() ) {
$html .=get_the_post_thumbnail();
$is_first_post = false;
}
$html .='<a href="'.get_the_permalink().'">';
$html .=get_the_title();
$html .='</a></li></ul>';
endwhile;
return $html;
}
add_shortcode( 'recentpost', 'recentpost_shortcode_func' );

Wordpress Gallery shortcode: Display one category ID only

Good Day. I am using a Gallery shortcode in my wordpress site to display images.
Problem is that I wasnt the gallery to show only images from a certain category, for example category id 35. How do I specify it in the shortcode?
Shortcode:
[custom_gallery style="1" source="**cat=%cat_id%**" link="image" description="0" size="200x200" limit="10"]
Now I have tried the following, but does not work -
cat=%35%
cat=%cat_id=35%
The shortcode code (because it is a custom shortcode):
/**
* Gallery posts shortcode
*/
function gallery_posts_func($atts, $content = null) {
extract(shortcode_atts(array(
"limit" => '5',
"cat" => '',
"thumb_width" => '',
"thumb_height" => '',
), $atts));
global $wp_query,$paged,$post;
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$query .= '&posts_per_page='.$limit;
$query .= '&post_type=gallery';
$query .= '&taxonomy=gallery_cat';
$query .= '&gallery_cat='.$cat;
$wp_query->query($query);
ob_start();
?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="gallery-holder fourthcol shortcode">
<?php
$gogo_gallery_video_url = get_post_meta($post->ID, 'gogo_gallery_video_url', true);
$gogo_gallery_links_to = get_post_meta($post->ID, 'gogo_gallery_links_to', true);
$gogo_gallery_title_links_to = get_post_meta($post->ID, 'gogo_gallery_title_links_to', true);
$gogo_gallery_custom_link = get_post_meta($post->ID, 'gogo_gallery_custom_link', true);
if ($gogo_gallery_title && $gogo_gallery_video_url && $gogo_gallery_title_links_to=="gallery_title_links_image") {
echo '<h5>';
echo '<a href="'.$gogo_gallery_video_url.'" rel="prettyPhoto[mixed]">';
echo ''.get_the_title().'';
echo '</a>';
echo '</h5>';
} elseif ($gogo_gallery_title && $gogo_gallery_title_links_to=="gallery_title_links_image") {
echo '<h5>';
echo '<a href="'.$thumbnail[0].'" rel="prettyPhoto[mixed]">';
echo ''.get_the_title().'';
echo '</a>';
echo '</h5>';
} elseif ($gogo_gallery_title && $gogo_gallery_title_links_to=="gallery_title_links_content") {
echo '<h5>';
echo '<a href="'.get_permalink().'">';
echo ''.get_the_title().'';
echo '</a>';
echo '</h5>';
} elseif ($gogo_gallery_title && $gogo_gallery_title_links_to=="gallery_title_links_link") {
echo '<h5>';
echo '<a href="'.$gogo_gallery_custom_link.'">';
echo ''.get_the_title().'';
echo '</a>';
echo '</h5>';
} elseif ($gogo_gallery_title) {
echo '<h5>';
echo ''.get_the_title().'';
echo '</h5>';
} else {
echo '';
}
?>
<div class="gallery-box">
<div class="gallery-image prettygallery">
<?php if (has_post_thumbnail()) { ?>
<?php
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
if ($gogo_gallery_video_url && $gogo_gallery_links_to=="gallery_links_image") {
echo '<a href="'.$gogo_gallery_video_url.'" rel="prettyPhoto[mixed]">';
echo '<img src="'.get_template_directory_uri().'/timthumb.php?src='.$thumbnail[0].'&w='.$thumb_width.'&h='.$thumb_height.'&zc=1&q=100&s=1" alt="'.get_the_title().'" />';
echo '</a>';
} elseif ($gogo_gallery_links_to=="gallery_links_image") {
echo '<a href="'.$thumbnail[0].'" rel="prettyPhoto[mixed]">';
echo '<img src="'.get_template_directory_uri().'/timthumb.php?src='.$thumbnail[0].'&w='.$thumb_width.'&h='.$thumb_height.'&zc=1&q=100&s=1" alt="'.get_the_title().'" />';
echo '</a>';
} elseif ($gogo_gallery_links_to=="gallery_links_content") {
echo '<a href="'.get_permalink().'">';
echo '<img src="'.get_template_directory_uri().'/timthumb.php?src='.$thumbnail[0].'&w='.$thumb_width.'&h='.$thumb_height.'&zc=1&q=100&s=1" alt="'.get_the_title().'" />';
echo '</a>';
} elseif ($gogo_gallery_links_to=="gallery_links_link") {
echo '<a href="'.$gogo_gallery_custom_link.'">';
echo '<img src="'.get_template_directory_uri().'/timthumb.php?src='.$thumbnail[0].'&w='.$thumb_width.'&h='.$thumb_height.'&zc=1&q=100&s=1" alt="'.get_the_title().'" />';
echo '</a>';
} else {
echo '<img src="'.get_template_directory_uri().'/timthumb.php?src='.$thumbnail[0].'&w='.$thumb_width.'&h='.$thumb_height.'&zc=1&q=100&s=1" alt="'.get_the_title().'" />';
}
?>
<?php } ?>
</div>
<?php if ($gogo_gallery_short_desc) { ?><em><?php echo $gogo_gallery_short_desc; ?></em><?php } ?>
</div>
</div>
<?php endwhile; ?>
<?php $wp_query = null; $wp_query = $temp;
$content = ob_get_contents();
ob_end_clean();
return $content;
}
add_shortcode("gallery_posts", "gallery_posts_func");
What you are looking for are probably:
cat="35"

Wordpress post query php custom field conditional

Here's the situation:
In wordpress I'm trying to reset a post WP_Query so that I can rewrite the post link based on whether or not a custom field exists in the post. I'm trying to give the post a NEW link in the custom field.
All I've managed to do here is kill the link entirely. Any and all help is greatly appreciated, I'm pretty green to php.
Here's my WP_Query:
<?php
$recentPosts = new WP_Query();
$recentPosts->query('showposts=3');
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<?php
$attribute = the_title_attribute();
$title = the_title();
$key = 'NewPostLink';
$newLink = get_post_meta( $post->ID, $key, TRUE );
if ($newLink != '') {
$theLink = get_permalink ($post->ID );
if (has_post_thumbnail()) {
$image = get_the_post_thumbnail( $post->ID );
echo '<div class="thumbnailbox"><div class="thumbnail">'.$image.'</div></div>';
echo '<h2>'.$title.'</h2>';
} else {
echo '<h2>'.$title.'</h2>';
}
} else {
$theLink = $newLink;
if (has_post_thumbnail()) {
$image = get_the_post_thumbnail( $post->ID );
echo '<div class="thumbnailbox"><div class="thumbnail">'.$image.'</div></div>';
echo '<h2>'.$title.'</h2>';
} else {
echo '<h2>'.$title.'</h2>';
}
}
?>
<small><?php the_time('F jS, Y') ?></small>
<div class="entry">
<?php the_excerpt(); ?>
</div>
</div>
<?php endwhile; ?>
I think this is what you need. It's hard to tell. I suppose that the first part of the if statement is what runs if there is no custom post meta? I couldn't tell. Here's what the problem was. The if statement ran the first part if there IS a value returned for the custom post meta, otherwise it ran the second part, using the empty string as the href. (The first part runs if the custom value either doesn't exist or is anything but an empty string). Changing the if statement to check if it's empty is better because it will catch it if it doesn't exist (returns false), or if it does exist but is an empty string (declared but not defined).
I've marked what I edited with comments (just one line).
<?php
$recentPosts = new WP_Query();
$recentPosts->query('showposts=3');
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<?php
$attribute = the_title_attribute();
$title = the_title();
$key = 'NewPostLink';
$newLink = get_post_meta( $post->ID, $key, TRUE );
/* EDITED */ if (empty($newLink)) {
$theLink = get_permalink ($post->ID );
if (has_post_thumbnail()) {
$image = get_the_post_thumbnail( $post->ID );
echo '<div class="thumbnailbox"><div class="thumbnail">'.$image.'</div></div>';
echo '<h2>'.$title.'</h2>';
} else {
echo '<h2>'.$title.'</h2>';
}
} else {
$theLink = $newLink;
if (has_post_thumbnail()) {
$image = get_the_post_thumbnail( $post->ID );
echo '<div class="thumbnailbox"><div class="thumbnail">'.$image.'</div></div>';
echo '<h2>'.$title.'</h2>';
} else {
echo '<h2>'.$title.'</h2>';
}
}
?>
<small><?php the_time('F jS, Y') ?></small>
<div class="entry">
<?php the_excerpt(); ?>
</div>
</div>
<?php endwhile; ?>

Resources