How to show caption in Gallery images in wordpress - php

hi I have portfolio blog and under portfolio page, I show my images as image feed and add via gallery its show simply no hyperlink no title no caption
I want to show the only caption on every image
here is code use to display image in my theme
<?php
global $post;
$header_images = get_post_meta($post->ID, '_ebor_gallery_images', 1);
if( is_array($header_images) ) :
?>
<ul class="basic-gallery text-center">
<?php
foreach( $header_images as $id => $content ){
echo '<li>'. wp_get_attachment_image($id, 'large') .'</li> ';
}
?>
</ul>
how add caption in this help me out for this
thanks !

Try this...
<ul class="basic-gallery text-center">
<?php
$output = '';
foreach( $header_images as $id => $content ){
$output .= '<li>'. wp_get_attachment_image($id, 'large');
$image = get_post($id);
$output .= '<span class="caption>'.$image->post_excerpt.'</span>';
$output .= .'</li> ';
}
echo $output;
$output = '';
?>
</ul>
Output your caption in whatever container you want, I just used a span as an example.

In your foreach:
$attachment_title = get_the_title($id)
should get you the title.

Related

Display Wordpress blog article category

I'm using Wordpress theme Bridge, here's the reference.
I'm using the masonry blog shortcode on my website's homepage. It currently only shows the blog title, excerpt, metadata, and comments and I would like to show the blogs category/categories.
The below shows the code that displays the title, blog excerpt, metadata and comments, so any help to display blog category would be appreciated.
$html .= '<div class="q_masonry_blog_post_text">';
$html .= '<'.$title_tag.' itemprop="name" class="q_masonry_blog_title
entry_title"><a itemprop="url" href="' . get_permalink() . '">' .
get_the_title() . '</a></'.$title_tag.'>';
$excerpt = ($text_length > 0) ? substr(get_the_excerpt(), 0,
intval($text_length)) : get_the_excerpt();
$html .= '<p itemprop="description"
class="q_masonry_blog_excerpt">'.$excerpt.'...</p>';
$html .= '<div class="q_masonry_blog_post_info">';
if ($display_time != "0") {
$html .= '<span itemprop="dateCreated" class="time entry_date updated">'.
get_the_time('d F, Y') .'<meta itemprop="interactionCount"
content="UserComments: <?php echo get_comments_number(qode_get_page_id());
?>"/>.</span>';
}
You can use the get_the_category.
Here you find it link.
$categories = get_the_category();
if ( ! empty( $categories ) ) {
$html .= '' . esc_html( $categories[0]->name ) . ''
}
$html .= '</div>'; //closing class q_masonry_blog_post_info
Can use this code to get category in post.
<?php
foreach((get_the_category()) as $category){
echo $category->name;
}
?>

Magento: Show left category nav on sub-sub-sub category page

I am working with a Magento Porto theme and need the left-side category navigation (category_nav.html) to show on sub-sub-sub category pages. I managed to get it to show up on sub-sub category pages, but can't figure out how to get passed there.
Here is my current code:
<?php
$_categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('level', 2)
->addAttributeToFilter('is_active', 1);
?>
<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>
<?php
function cmpCatPosition($a, $b) {
if ($a->position == $b->position)
return 0;
return ($a->position > $b->position) ? 1 : -1;
}
function getChildrenCategoriesHtml($_category){
$children = explode( ",", $_category->getChildren() );
//usort($children, 'cmpCatPosition');
$content = '';
$content .= '<li class="';
if(!$children[0])
$content .= 'has-no-children';
else
$content .= 'has-children';
$content .= '">';
$content .= '<a href="'.$_category->getUrl().'" ';
$content .= '>'.$_category->getName().'</a>';
if($children[0]){
$content .= '<i class="icon-plus-squared"></i>';
$content .= '<ul>';
foreach($children as $child){
$_subcat = Mage::getModel( 'catalog/category' )->load( $child );
$content .= getChildrenCategoriesHtml($_subcat);
}
$content .= '</ul>';
}
$content .= '</li>';
return $content;
}
?>
<?php if($_count): ?>
<div class="block block-category-nav">
<div class="block-title">
<strong><span><?php echo Mage::registry('current_category')->getName(); ?></span></strong>
</div>
<div class="block-content">
<ul class="category-list">
<?php foreach ($_categories as $_category): ?>
<?php
if($_category->getIsActive()){
echo getChildrenCategoriesHtml($_category);
}
?>
<?php endforeach ?>
</ul>
</div>
</div>
The code that I made actually works. I just missed adding "Is Anchor -> Yes" in the back end.
There is a code where this can be done globally, but I want control over what shows and what does not, so selecting Yes/No on the anchor solves the issue.
This was (after all the pulling my hair out trying to make it work) not a programming issue.

upload categorie to woocommerce

hello I am new to programing. I am creating a simple RSS feed plugin for wordpress to upload some products to WooCommerce and need to upload the category to wordpress . In plugin the category is visible but they are not showing like the url link. I need the category to show like checkbox. Can anybody have any idea ?
File number 1
* Init feed with information from DB
private function load()
{
if ($this->id) {
$post = get_post( $this->id );
if (!$post) {
$this->id = null;
return;
}
$this->title = $post->post_title;
$this->id = $post->ID;
$meta = get_post_meta($post->ID);
foreach ($meta as $key=>$item) {
$newKey = substr($key, 1);
$this->properties[$newKey] = $item[0];
if ($newKey == 'post_category') {
$this->properties[$newKey] = unserialize($item[0]);
}
}
}
}
..................
$fields = array( 'post_category');
..................
// Create post
$post = array('post_category' => $this->post_category);
And the file number 2 have this
<div class="postbox">
<div class="handlediv" title="<?php esc_html_e('Click to toggle', 'rss-autopilot'); ?>"><br></div>
<h3 class="hndle ui-sortable-handle"><span><?php esc_html_e('Categories', 'rss-autopilot'); ?></span></h3>
<div class="inside">
<ul class="rssap-categories-list">
<?php wp_category_checklist( 0, 0, $feed->post_category, false, null, true ); ?>
</ul>
<div class="clear"></div>
</div>
</div>
Here is your code.
$terms = get_terms( 'product_cat', $args );
if ( $terms ) {
echo '<ul class="product-cats">';
foreach ( $terms as $term ) {
echo '<li class="category">';
echo '<h2>';
echo '<input name="product_category[]" type="checkbox" value="'. $term->term_id.'"';
echo $term->name;
echo '</a>';
echo '</h2>';
echo '</li>';
}
echo '</ul>';
}

How to get each parent page, and display its children as separate divs in Wordpress

Right now I have the following PHP:
<?php
$pages = get_pages( array( 'sort_column'=>'menu_order', 'parent'=>'0') );
foreach ($pages as $page_data) {
$content = apply_filters('the_content', $page_data->post_content);
$title = $page_data->post_title;
$slug = $page_data->post_name;
$pageid=$page_data->ID;
echo '<div class="section'.(($title=='intro')?' intro-section':"").'">';
echo $content;
echo "</div>";
}
?>
There are 5 Pages, 2 of which have many child Pages. I want to take the above code further one level, so that each page will have its own wrapper, and, if a Page has children Pages, those pages will be placed within the same .section, but each within a separate div. Any advice? I'm a bit inexperienced in Wordpress so any help would be great. Below should give an example of what I want:
<div class="section">
<div class="page parent"></div>
</div>
<div class="section">
<div class="page parent"></div>
<div class="page child"></div>
<div class="page child"></div>
</div>
<div class="section">
<div class="page parent"></div>
</div>
Below is the code I'm working with right now.
<?php while (have_posts()) : the_post(); ?>
<?php
$pages = get_pages( array( 'sort_column'=>'menu_order', 'parent'=>'0') );
foreach ($pages as $page_data) {
$content = apply_filters('the_content', $page_data->post_content);
$title = $page_data->post_title;
$slug = $page_data->post_name;
$pageid=$page_data->ID;
//Put a container around every page's content
if (count(get_pages('child_of=' . $page_data->ID.''))) {
// Loop through $page_data array to print the div you want
echo '<div class="section">';
echo '<div class="slide">';
echo $content;
echo "</div>";
$children = get_pages('child_of=' . $page_data->ID.'');
foreach( $children as $child ) {
$childcontent = apply_filters('the_content', $child->post_content);
echo '<div class="slide">';
echo $childcontent;
echo "</div>";
}
echo "</div><!--end section-->";
} else {
echo '<div class="section'.(($title=='intro')?' intro-section':"").'">';
echo $content;
echo "</div>";
}
}
?>
<?php endwhile ?>
Use child_of parameter of get_pages() function inside the loop. This parameter lists the sub-pages of a single Page only. It uses the ID for a Page as the value.
Eg.
if (count(get_pages('child_of=' . $page_data->ID))) {
// Loop through $page_data array to print the div you want
}

Wordpress category page not returning array correctly

I am editing my category page. Using some custom fields I am defining an image. For each post within a category I want to add this custom image to an array which I am turning into a gallery of images. I'm using the below code, but for some reason when it comes to imploding the array all I get back is one image (which corresponds to the last post that's loaded in). I'm sure there is probably just something I've put in the wrong place but I just can't figure it out. Any help would be much appreciated.
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$gallery_images = get_custom_field('catImage:to_array');
$thumbs_html = array();
foreach ($gallery_images as $galleryID) {
$attachment = get_post( $galleryID );
$description = get_custom_field('catIntro:do_shortcode'); //get pages introductory text
$caption = get_the_title(); //get page title
$button_html .= '<div id="description-button-' . $gallery_images_count . '" class="show-description-button">Show Caption</div>';
$description_html .= '<div id="description-' . $gallery_images_count . '" class="photoDescription" style="display:none;">' . $description . '</div>';
$caption_html .= '<div id="caption-' . $gallery_images_count . '" class="photoCaption" style="display:none;">' . $caption . '</div>';
$thumb_img = wp_get_attachment_image_src( $galleryID, 'thumbnail' ); //thumbnail src
$full_img = wp_get_attachment_image_src( $galleryID, 'full' ); //full img src
$thumbs_html[] = '<div class="indvlThumbCont"><img class="thumbImg" src="' . $thumb_img[0] .'"></div>';
$gallery_images_count++;
}//end forEach
//calculate the width of the thumbar
$widthPerImg = 157;
$thumbBarWidth = $gallery_images_count * $widthPerImg;
print $gallery_images_count;
?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<div id="thumbsBar">
<div id="left" class="scrollCtrl left desktopOnly"><span></span></div>
<div class="toHideScrollBar" id="toHideScrollBar">
<div class="moveCanvas" style="width:<?php echo $thumbBarWidth; ?>px;">
<?php echo implode("\n", $thumbs_html); ?>
</div>
</div>
<div id="right" class="scrollCtrl right desktopOnly"><span></span></div>
<span id="total_number_in_gallery " class="<?php echo $gallery_images_count; ?>"></span>
</div>
If you are using a theme like TwentyTwelve (which by default only displays one post on the category page) then that's where the issue is. You'll solve this by (if you are fine with modifying the main loop), adding this just before your code:
query_posts('showposts=y&cat=x');

Categories