Show background image through php plugin command - php

I have i guess a bit dirty code. This is a function php with custom wp_nav code.
$output .= $indent . '<div class="categories-wrapper"><li' . z_taxonomy_image($cat->term_id) . $id . $class_names .'>';
So i have plugin that gives images to categories. What i need is that image will apply to the 'li' block and can be seen as a 'background:url(plugin url)' in css if it possible. this one does nothing.
Not sure which should i even use though.
z_taxonomy_image($cat->term_id)
Plugin documentation list - categories image
Rest of the code i think don't that matter. If not , i will add.
EDIT
Found a useful post that i think will solve my problem but i still don't know how to properly use it. How do i inster it in the <li>?
if (function_exists('z_taxonomy_image_url')) $background_url = 'background:url(' . z_taxonomy_image_url() . ')';
echo '<div class="' . $tax_term->slug . '" style="display:none; ' . $background_url . '">';
full help thread stackoverflow
EDIT 2
Figured out myself a proper code
$output .= $indent . '<div class="categories-wrapper"><li style="background: url(' . z_taxonomy_image_url($cat->term_id) . ')"' . $id . $class_names .'>';
it now shows in inspector url of my site instead of picture given by plugin.
EDIT 3
if i add foreach (get_categories() as $cat) it's working, i got the images
foreach (get_categories() as $cat)
$output .= $indent . '<div class="categories-wrapper"><li style="background:url(' . (function_exists('z_taxonomy_image') ? z_taxonomy_image_url($cat->term_id) : '') . ')"' . $id . $class_names .'>';
But it messed up the whole html code, added tons of <li> block and others so it overrides each other. Maybe i should put it somewhere else?
Small edit - code is not working on a index page (it's a block with categories-sidebar), but when you enter any post, it shows you correct picture of category, but also it shows it for EVERY block of categories on a sidebar same picture.
So maybe i ask something imposible and that plugin can't do that.

you need to insert the image in style=""
like this maybe:
'<li style="url('z_taxonomy_image($cat->term_id) ')"' . $id . $class_names .'>';
another solution
Why not use json response and append dom elements? insert each picture to the required element.
In the following example, I am receiving a json array of pictures and inset them to a specific element.
you could retrieve the picture and the picture type for instance and inset to elements by type.
this is my first attempt to help, be gentle.
for your example you could set the css of each li element using .css()
$.ajax({
type: "POST",
data: {text: text, images: images, images_big: images_big},
url: "/ajax/" + $(this).attr('data-post') + "/createPostComment",
dataType: 'json',
error: function () {
$el.remove();
return;
},
success: function (r) {
$el.attr('data-id',r.comment_id);
if(typeof r.pictures != 'undefined'){
for(var i=0; i < r.pictures.length; i++){
el.find('.comment-pictures-container').append('<img src="'+ r.pictures[i] +'" data-big="'+ r.pictures_big[i] +'" />');
}
}
bindCommentGallery($el);
bindCommentMenu($el);
}
});

Related

Send static data from one php to another

I have a php file results.php with a grid of different items (each item is a row from the result of a certain query). When I click an item it takes me to another php file details.php where I want to show more details in the new page about the specific item I clicked.
function showAsItem($row) {
$defaultValue = $row[1];
$itemClassname="item";
$titleClassname="title";
$imageClassname="image";
$infoClassname="infolist";
$link="details.php";
$target="_top";
$img="https://barcelonando.com/es/wp-content/uploads/2012/12/barceloneta.jpg";
$alt="Imagen de $row";
echo '<div class="'.$itemClassname.'">';
echo '<div class="' .$titleClassname. '">';
echo '' .ucfirst($row[0]). '';
echo '</div>';
echo '<div class="' .$imageClassname. '">';
echo '<a href="' .$link. '" target="' .$target. '">';
echo '<img src="' .$img. '" alt="' .$alt. '"/>';
echo '</a>';
echo '</div>';
echo '<div class="' .$infoClassname. '">';
echo '<ul>';
echo '<li> PoblaciĆ³n: ' .$row[1]. '</li>';
echo '<li> Esperanza de vida: ' .$defaultValue. '</li>';
echo '<li> Inmigrantes: ' .$defaultValue. '</li>';
echo '<li> Transportes: ' .$defaultValue. '</li>';
echo '<li> Accidentes: ' .$defaultValue. '</li>';
echo '</ul>';
echo '</div>';
echo '</div>';
}
I only know how to send info from one webpage to another when it is an input type, but in this case I want to send the item static info (I just need to send the name of the item I clicked). Any idea about how to do it?
As #pavel pointed out, using a URL parameter should work for you. Every item must have a unique number or name associated with them.
Do not use their array index or similar, because that will change in the future.
Your example code has $row use numeric indexes - whichever one of them is unique you can use as a URL parameter. If you don't have one, you have to create one. Preferably one that will not change when the data is updated. That is where databases will use numeric IDs, but you can use a string as well, as long as you can identify the item from the details.php.
Example link: $link="details.php?id=" . $row[2];. Replace 2 with whatever is a unique number / name for every row.
Instead of only supplying the $row in your function, you can supply the row's ID as a separate parameter if that is what you need. Depends on how you organized this outside of your example code.
In this case you change the function as well:
function showAsItem($row, $rowId) {
// ...
$link="details.php?id=" . $rowId;
// ...
}
In details.php you can access this variable with $_GET: https://www.php.net/manual/en/reserved.variables.get.php
$id = $_GET['id'];

How to reinsert a value on onclick inside a page?

I would know how to take the value on onclik for inject inside a sql request.
This code below create a link. When I click on the link a specific table appear
$value can two elements
$value['name']
$value['option_id']
$i = 0;
foreach($option_attributes_name as $value) {
$content .= '<li class="col-md-12"><a class="showTabOption nav-link" data-tableid="' . $i . '" data-toggle="tooltip" data-target="#section_ProductsOptionApp_content" href="'. CLICSHOPPING::link('index.php?&pID='. $_GET['pID'] .'#tab-option'. $i .'&toto=' . $value['option_id']) .'"><i class="fas fa-minus-circle"></i> '. $value['name'] .'</a></li>';
$i++;
}
In my table I have a specific dropdown to display information.
Currently it take all informations by the mysql request, but than I tried to make, it's a dropdown must take only the information on the value onclick ( .'&toto=' . $value['option_id'])
On onclick, how to take the value '&toto=' . $value['option_id'] to reinject inside the request.
Ajax page ?
I don't know if I am clear. If not I will complete this explanation.
Thank you.

display particular image associated with tag

I'm new with wordpress and I tried to look for an answer but everything I found and tried didn't work. So let's start from the beginning I added this code to functions.php in my child theme:
function wptp_add_tags_to_attachments() {
register_taxonomy_for_object_type( 'post_tag', 'attachment' );
}
add_action( 'init' , 'wptp_add_tags_to_attachments' );
Now I can add tags to images in admin section.
The problem is that I want to display those images on post and category page next to the tags assigned to the post at the bottom where they appear in default. I added the category to the main navigation so after I click on it a page with all the post excerpts in the category are displayed. And at the bottom are shown tags associated with given post.
An example cause I'm not sure I explained it so that it's easy to understand.
I have 3 posts: project1, project2 and project3 which are in category Projects. Every one of those three projects has assigned one or more of these tags: company1, company2, company3. For every company tag there is an image with the same company tag assigned to an image (logo of the company). And I want to display not only the tag name but also the image associated with the tag.
Is there some way to do this?
Thanks in advance.
I used this code snippet which I found here:
<?php
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo '<img src="http://example.com/images/' . $tag->term_id . '.jpg"
alt="' . $tag->name . '" />';
}
}
?>
So the final product is this:
<?php
$posttags = get_the_tags();
$templPath = get_stylesheet_directory_uri() .'/images/';
if ($posttags) {
foreach($posttags as $tag) {
$html = '<div class="projectLinkWrap">';
$html .= '<a href="'. get_the_permalink() .'#projectpartner"/>';
$html .= '<div class="thumbLogoWrapper">';
$html .= '<img src="'.$templPath . $tag->name.'.png"
alt="' . $tag->name . '" /></div>';
$html .= '<span class="tagName">'. $tag->name .'</span></a></div>';
echo $html;
}
}
?>
Hope it helps someone one day.

How to echo an output in a specific div

I have a page full of products and when the page reloads after the add to cart button has been clicked i want to display a check mark next to the product that was added.
Using the rows and columns count i have assigned each product it's own class, for example
<div class = "location12">
I passed the location via post when the add to cart button is pressed so i can tell which div the button press was from and i can then use that data as an identifier.
I can get the page to scroll back to this position by referencing the div, but i'm struggling to get the image to only display on that one product. It will display on that product and then every product after it because it echoes on every time it loops after the first output.
Already added to the individual product page, but they want the same function as here: http://confettibox.ch/1-NEWSTORE/index.php?main_page=product_info&cPath=576_578&products_id=1265&language=en
on this page here:
http://confettibox.ch/1-NEWSTORE/index.php?main_page=index&cPath=4_586
Add to cart button submit is coded here, and you can see where i added the hidden field to pass the id of the div
$lc_button= '<div class="back">' . zen_draw_form_prod_list('cart_quantity', preg_replace($pattern, $replacement, $string), 'post', 'enctype="multipart/form-data"') . '</div><div class="back qty_bg"><input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($listing->fields['products_id'])) . '" maxlength="6" size="4" /><br />' . zen_draw_hidden_field('products_id', $listing->fields['products_id']) . zen_draw_hidden_field('div_id', $colcount.$rows) . '</div><div class="forward">' . zen_image_submit('button_add.jpg', BUTTON_IN_CART_ALT) . '</form></div><br class="clearBoth">';
I added the $_POST result to a session var here:
$_SESSION['location'] = (int)$_POST['div_id'];
And then used:
if ($messageStack->size('listing') > 0 && $_SESSION['location'] == $colcount.$rows) {
so that the messageStack output (success checkmark) would only display for that one product... except it displays for everything after it too :|
Products are output using this code:
if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns') {
$lc_text = implode('<br />', $product_contents);
$list_box_contents[$rows][$column] = array('params' => 'class="centerBoxContentsProducts centeredContent back featured'. $column .'"' . ' ' . 'style="width:235px;"',
'text' => $lc_text = '
<div class="prod_table">
<div class="prod_image">' . zen_image(DIR_WS_IMAGES . $listing->fields['products_image'], $listing->fields['products_name'], IMAGE_PRODUCT_LISTING_WIDTH, IMAGE_PRODUCT_LISTING_HEIGHT, 'class="listingProductImage"') . '</div>
<div class="prod_name">' . $listing->fields['products_name'] . '</div>
<div class="prod_price back">'. zen_get_products_display_price($listing->fields['products_id']) .'</div>
<div class = "location'. $colcount.$rows .'">'.$success.' </div>
<div class="prod_content forward">'. $the_button .'</div>
</div>
');
$column ++;
$colcount=$column;
if ($column >= PRODUCT_LISTING_COLUMNS_PER_ROW) {
$column = 0;
$rows ++;
}
}
// End of Code fragment for Column Layout (Grid Layout) option in add on module
$listing->MoveNext();
$success is where i want the check to be output.
How can i echo the success message to only 'location12' ?
Is it even possible?
You haven't posted much code but I'll try answering.
You can do it either with Javascript or PHP.
With Javascript/jQuery you can set the background image of any div you want:
$('.location12').css("background-image", "url(/myimage.jpg)");
With PHP you need to count your iterations and only echo the image on $index==12.
I do not know if you are using foreach, for, while or any other method.
Assuming it is a foreach loop you can do the following:
$index = 1;
foreach ($products as $product) {
if ($index == 12) {echo "<img src=''/>"}
$index++;
}
As you can see, the jQuery method is easier.
Hope this helps!

How to dynamic loadind dojo's 1.8 modules with PHP?

I have in my main page dojox/layout/ContentPane widget. This widget dynamically load any Hrefs with content which have Javascript & HTML the being formed by PHP.
Javascript
$scriptCode .= 'require(["' . $scriptFile . '", "dojo/ready"], function(PageScript, ready){' . "\n";
$scriptCode .= ' ready(function(){' . "\n";
$scriptCode .= ' setTimeout(function(){new PageScript(' . $scriptOptions . '); }, 0);' . "\n";
$scriptCode .= ' });' . "\n";
$scriptCode .= '});' . "\n";
PageScript() is a dojo class drawing widgets and logic of page. The problem consists in that that when loading other href the object of old page partially gains properties of new objects. Removal of object of page after an drawing , destruction of widgets don't help to solve a problem.
PageScript
define(['dojo/_base/declare', 'common/widget/Card'], function (declare, pageWidget) {
return declare(pageWidget, {
constructor: function(options){
}
});
});
PS. Sorry for my bad english
Um, your code and question don't make a lot of sense. If you want to load dynamically created content into a ContentPane the easiest way is to pass in a dojo template. Just use data-dojo-type to create any widgets that you need. If you need to run code on widget load, put it in the widget's startup function.

Categories