Such a problem in WordPress, I want to display on the page information about categories, as well as their image ... I added the image in the category using the ACF plugin, all data is displayed: name, description, but the picture is not, here is my code, what's wrong tell me?
<?php
$categories = get_categories(array('hide_empty' => 0, 'taxonomy' => 'authors-category'));
foreach ($categories as $cat) {
$id = $cat->cat_ID;
$term = get_queried_object();
$cat_img = get_field('category_image', $cat);
?>
<!--Author-->
<div class="author-block">
<div class="photo-author" style="background: url(<?php echo $cat_img['url']; ?>) #f3b458 no-repeat center center;background-size: cover;"></div>
<div class="name-author"><?php echo $cat->name ?></div>
<div class="count-post-author">
41 post </br>
See All Posts By The Author
</div>
<div class="content-author">
<?php echo $cat->description ?>
</div>
</div>
<!--End Block-->
<?php } ?>
This is what happened, only in place of the figure should be pictures:
Solved the problem by switching the settings in the plugin
Array to URL
enter image description here
Related
This is my footer. There is parade of categories with most articles in. I need to exclude here categories with description that starts with "XXX".
So If some categories have description that starts with "XXX", it may don´t show here.
Is it possible please? Im newbie in PHP so I dont know if can I declare category discreption here.
<?php global $teo_options;?>
<footer role="contentinfo">
<?php if(isset($teo_options['enable_popular_companies']) && $teo_options['enable_popular_companies'] == 1) { ?>
<div class="stripe-regular">
<div class="row">
<div class="column">
<h2><?php _e('Name', 'Couponize');?></h2>
</div>
</div>
<div class="row collapse">
<div class="column">
<div class="popular-companies flexslider">
<ul class="rr slides">
<?php
$args['hide_empty'] = 1;
$args['orderby'] = 'count';
$args['order'] = 'desc';
if(isset($teo_options['blog_category']) && $teo_options['blog_category'] != '')
$args['exclude'] = implode(",", $teo_options['blog_category']);
$categories = get_categories($args);
foreach($categories as $category) {
$image = get_option('taxonomy_' . $category->cat_ID);
$image = $image['custom_term_meta'];
?>
<li>
<a href="<?php echo get_category_link( $category->term_id );?>" class="wrapper-5 small">
<img src="<?php echo aq_resize($image, 130, 130, true); ?>" alt="<?php echo $category->name;?> coupons">
</a>
</li>
<?php } ?>
</ul>
</div>
</div>
</div>
</div>
<?php } ?>
Everything is possible but you're just complicating your problem.
Why would you identify a category by a piece of text in the Description?
Also, searching in the description as it's text could end to be a slow and unnecessary query, if you have a lot of categories.
To solve it, I recommend you take a look at the documentation about Including & Excluding Categories.
What I would do is to make sub-categories and either hide them manually or do a trick between the child and parent categories.
How can I get the product category's URL Key?
I can get the category name by $category->getName() but it does not work if I use this $category->getURLKey(),
$categories = $_product->getCategoryCollection()
->addAttributeToSelect('name');
foreach($categories as $category) {
$productCategoryName = $category->getName();
var_dump($category->getURLKey());
}
Return null
Any ideas?
I'm not entirely sure what your goal is, but you're not going to be able to get category information from $_product. Feel free to ask questions based upon my code below. But my code below will grab the active categories children and their info. However, this should be a good enough base for what you're looking to do regardless.
<!-- Use this section if you're trying to grab children categories and their info -->
<?php
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
$categories = $category->getCollection()
->addAttributeToSelect(array('name', 'thumbnail'))
->addAttributeToFilter('is_active', 1)
->addIdFilter($category->getChildren())
?>
<div class="subcategories">
<p>Select a category to view products:</p>
<ul class="clearfix">
<!-- Display Each Subcategory Image and Name Feel Free to remove the img src section to remove the image -->
<?php foreach ($categories as $category): ?>
<li class="grid12-3">
<a href="<?php echo $category->getUrl() ?>" class="clearfix">
<?php if($thumbFile = $category->getThumbnail()): ?>
<img src="<?php echo Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . $thumbFile;?>" alt="<?php echo $this->htmlEscape($category->getName()) ?>" />
<?php endif;?>
<span><?php echo $category->getName() ?></span></a>
</li>
<?php endforeach; ?>
</ul>
</div>
<!-- End -->
Any questions feel free to ask! Sorry, I just stole an example from a project so the HTML may not line up for a direct copy.
foreach($categories as $category) {
// for category URL key
var_dump($category->getUrlPath());
// for category URL
var_dump($category->getUrl());
}
So I've got a Magento install, with Fishpig Wordpress Integration and the ACF plugin to pull in meta values. I'm also using the repeater field here which pulls in the metadata as an array (as I understand it). The Fishpig documentation is non- existent so alot of this is guess work really but here's my code:
<?php
/**
* #category Fishpig
* #package Fishpig_Wordpress
* #license http://fishpig.co.uk/license.txt
* #author Ben Tideswell <help#fishpig.co.uk>
*/
?>
<?php $page = $this->getPage() ?>
<?php if ($page): ?>
<?php $helper = $this->helper('wordpress') ?>
<?php $author = $page->getAuthor() ?>
<div class="page-title">
<h1><?php echo $this->escapeHtml($page->getPostTitle()); ?></h1>
</div>
<?php
$lookbooks = $page->getMetaValue('lookbooks');
if($lookbooks):
foreach ($lookbooks as $lookbook) {
$title = $lookbook['title'];
$content = $lookbook['content'];
$images = array($lookbook['images']);?>
<h2><?php echo $title;?></h2>
<div class="connected-carousels">
<div class="stage">
<ul>
<?php foreach($images as $image) { ?>
<li>
<img src="<?php echo $image['image'];?>" alt="<?php echo $image['alt'];?>" />
</li>
<?php } ?>
</ul>
‹
<a href="#" class="next next-stage" >›</a>
</div>
<div class="navigation">
‹
<a href="#" class="next next-navigation" >›</a>
<div class="carousel carousel-navigation">
</div>
</div>
</div>
<?php echo $content ; ?>
<?php }
else : ?>
<div class="post-view">
<div class="entry std">
<?php if ($page->isViewableForVisitor()): ?>
<?php if ($featuredImage = $page->getFeaturedImage()): ?>
<div class="featured-image left"><img src="<?php echo $featuredImage->getAvailableImage() ?>" alt=""/></div>
<?php endif; ?>
<?php echo $page->getPostContent() ?>
<br style="clear:both;"/>
<?php else: ?>
<?php echo $this->getPasswordProtectHtml() ?>
<?php endif; ?>
</div>
</div>
<?php endif;?>
<?php endif; ?>
What I'm trying to do is use the repeater field to make a carousel using jcarousel, I'm fine with my jquery but there's some sort of PHP error here preventing the page from loading.
Here's my ACF structure with the labels:
lookbook (repeater)
--title
--content
--images (repeater)
----image
----alt
I can't see any php errors in the servers error log, nor is the page displaying any errors. It's just not echoing the $image array although it is repeating the loop the right amount of times.
Maybe I'm miles away, maybe I'm nearly there I just can't see anything wrong with it.
Thanks in advance
There is an issue in version 1.2.1.0 of the ACF extension that breaks repeater fields that are embedded inside a repeater field. I have just released version 1.2.2.0 that fixes this issue and allows you to use repeater fields inside other repeater fields.
I've recently come to a project where using custom fields would be pretty handy. It's for a restaurant and if I can get this right, I could use this bit of code for a few different sections of the site.
I'm using the Magic Fields 2 plugin and right now it's awesome, except for when it comes to displaying the fields I've created. Here's where I'm getting pretty lost.
For example, I have a post called "Specials" and that has a grouping called "Menu Item" and that group has two fields called "Name" and "Description". Basically name serves as the menu item name, and description will be a small blurb about the food item.
Here's the code in my theme for this section right now:
<div id="specials">
<?php
$query2 = get_post(28);
$title = $query2->post_title;
$itemname= get_post_meta($post->ID, 'menu_item_name', true);
$description = get_post_meta($post->ID, 'menu_item_description', true);
?>
<div id="specialstitle"><?php echo $title; ?></div>
<div class="stripebackbrown"> </div>
<div id="specialslist">
<?php while ( have_posts() ) : the_post();
echo '<span>'.$itemname.'</span>';
echo '<p>'.$description.'</p>';
endwhile;
wp_reset_query();
?>
</div>
</div><!-- end specials-->
Now there is a very good chance what I'm doing in the above code is completely wrong, if it is, please let me know.
What I'm experiencing with the above code however is it's pulling the very first group for that post.
So instead of something like:
Tomato Soup
description text here
Turkey Sandwich
description text here
Greek Salad
description text here
I'm getting:
Tomato Soup
description text here
Tomato Soup
description text here
Tomato Soup
description text here
So while the above code is technically working, it's not working properly at the same time.
Any help would be greatly appreciated!
EDIT:
I'm having some better success with this:
<div id="specials">
<?php
$query2 = get_post(28);
$title = $query2->post_title;
?>
<div id="specialstitle"><?php echo $title; ?></div>
<div class="stripebackbrown"> </div>
<div id="specialslist">
<?php $itemname = get_post_meta ($post->ID, 'menu_item_name', false); ?>
<?php $description = get_post_meta ($post->ID, 'menu_item_description', false); ?>
<?php foreach ($itemname as $itemname){
echo '<span>' .$itemname. '</span>';
echo '<p>' .$description. '</p>';
} ?>
</div>
</div><!-- end specials-->
However, I'm not sure how to add $description to that foreach loop. So right now it's listing out the menu names but adding "Array" where the description should be. Getting closer!
I think you want to do this like that:
<div id="specials">
<?php
$query2 = get_post(28);
$title = $query2->post_title;
?>
<div id="specialstitle"><?php echo $title; ?></div>
<div class="stripebackbrown"> </div>
<div id="specialslist">
<?php while ( have_posts() ) : the_post();
$itemname = get_post_meta(get_the_ID(), 'menu_item_name', true);
$description = get_post_meta(get_the_ID(), 'menu_item_description', true);
echo '<span>'.$itemname.'</span>';
echo '<p>'.$description.'</p>';
endwhile;
wp_reset_query();
?>
</div>
Found a solution:
<?php
$query2 = get_post(28);
$title = $query2->post_title;
?>
<div id="specialstitle"><?php echo $title; ?></div>
<div class="stripebackbrown"> </div>
<div id="specialslist">
<?php $itemname = get_post_meta ($post->ID, 'menu_item_name', false); ?>
<?php $description = get_post_meta ($post->ID, 'menu_item_description', false); ?>
<?php foreach (array_combine($itemname, $description) as $itemname => $description){
echo '<span>' .$itemname. '</span>';
echo '<p>' .$description. '</p>';
} ?>
</div>
</div><!-- end specials-->
This combines the two arrays created by $itemname and $description and loops them as many times as there are groups to loop.
#speccode, thanks so much for trying to help me, your reordering of my two lines got me heading in the right direction.
I know this is old but I had the same problem so I attempted to improved #speccode answers' a tiny bit and it seems to work:
<?php $itemnames = get_post_meta($post->ID, 'itemnames', false); ?>
<?php $descriptions = get_post_meta($post->ID, 'descriptions', false); ?>
<?php foreach (array_combine($itemnames, $descriptions) as $itemname => $description)
{
echo '<img src="'.$itemname.'"/>';
echo '<p>' .$description. '</p>';
}
?>
I also attempted abit of structuring in there (see below) but I can't guarantee the validity of the markup... anyone?
<?php $itemnames = get_post_meta($post->ID, 'itemnames', false); ?>
<?php $descriptions = get_post_meta($post->ID, 'descriptions', false); ?>
<?php foreach (array_combine($itemnames, $descriptions) as $itemname => $description)
{
echo '<div class="nameAndDescription"><img src="'.$itemname.'"/>';
echo '<p>' .$description. '</p></div>';
}
?>
I have a parent page that acts as menu for my portfolio.
It pulls in thumbnail images from the child pages which i have been able to accomplish with magic fields and some code. It dumps the images into a grid layout. The thumbnails are pulled into one container div like so:
div id="folio-content">
<div class="thumb-container">
<div class="thumb"><img src="/images/pic.jpg"/>
</div>JCPenny</div>
... </div>`
when the div gets filled up with 2 thumbnails I want to create a new container div and fill it with 2 images again and so on after 2 images.
So, if you had 4 images it would look like this.
<div id="folio-content"><!--/Main Container/-->
<div class="thumb-container">
<div class="thumb"><img src="/images/pic1.jpg"/>
</div>JCPenny</div>
<div class="thumb-container">
<div class="thumb"><img src="/images/pic1.jpg"/>
</div>Champ Car</div></div>
<div id="folio-content"><!--/Main Container/-->
<div class="thumb-container">
<div class="thumb"><img src="/images/pic1.jpg"/>
</div>JCPenny</div>
<div class="thumb-container">
<div class="thumb"><img src="/images/pic1.jpg"/>
</div>Champ Car</div></div>
this is the code I am using in my page.php file.
<?php get_header(); ?>
<div id="folio-content">
<?php
$projectpage = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
$count = 0;
foreach($projectpage as $page)
{
$content = $page->post_content;
if(!$content)
continue;
if ($count == 10) --- this is geting 10 images now, but I want to get them all.
break;
$count++;
$content = apply_filters('the_content', $content);
?>
<div class="thumb-container">
<div class="thumb"><a href="<?php echo get_permalink($page->ID); ?>"<?php echo get_image ("thumbnail",1,1,1,$page->ID);?></a>
</div><?php echo $page->post_title ?>
</div>
<?php
}
?>
</div><!--/close set!-->
</div>
also, how can I get ALL child pages? I have it set to 10 now with this if ($count == 10)
any help? thanks a ton again!!!!
I'm not familiar with "get_pages" but since Wordpress treats posts and pages in an identical manner you could use this.
$projectpage = get_posts('numberposts=-1&post_type=page&child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
The -1 removes the limit and gets ALL the specified pages.
I have cobbled together some code, that sort of sounds right but does not work at all! Which I am not surprised. But it is a starting point - please take a look at this code, maybe it is step in the right direction?
<?php
$projectpage = get_posts('numberposts=-1&post_type=page&child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
if (have_posts()) :
$i=0; // counter
while(get_posts()) : the_post();
if($i%2==0) { // if counter is multiple of 3, put an opening div ?>
<!-- <?php echo ($i+1).'-'; echo ($i+2); ?> -->
<div>
<?php } ?>
<div class="single_item">
<h2><?php the_title(); ?></h2>
</div>
<?php $i++;
if($i%2==0) { // if counter is multiple of 3, put an closing div ?>
</div>
<?php } ?>
<?php endwhile; ?>
<?php
if($i%2!=0) { // put closing div here if loop is not exactly a multiple of 3 ?>
</div>
<?php } ?>
<?php endif; ?>