Adding HTML to tables
-
Hi
If you look at this page:
http://www.andrew-leonard.co.uk/wordpress/ferns-2/growing/spore-exchange/spore-list/
You will see that the first entry “Acrostichum aureum” has a HTML link to do a Google search. I have put the HTML in the cell.
My question is, is there any way of arranging for the HTML code to be added to each cell without having to put it in myself – rather in the same way that you can add a CSS style to a whole row with one command in “Plugin Options”
-
Dear Ziya
Not sure what it is you want to do exactly
If you just want to show the images, you wrap your urls in html for example
<img src=”http://www.ps4home.com/wp-content/uploads/2013/10/NO-BOX-ART.jpg”/>
You do this in the TablePress cell
I have done this here:
http://ebps.org.uk/publications/special-publications
Does this answer your problem?
If not then I can explain more about add_filterDear Andrew,
Thanks for replying
I want same thing that you have done.
The only difference is that you have done for a specific column value while I want do this for all row values for 2 columns.
Thanks,
ZiyaHi Ziya,
then, you’ll just need an “or” in your
ifexpression.Can you maybe post the code that you are using now, so that we can debug it? It should be pretty similar to the code from above.
Regards,
TobiasI am using following code
add_filter( ‘tablepress_cell_content’, ‘Google_Wrap15’, 10, 4 );
function Google_Wrap15( $tablepress_cell_content, $table_id, $row_number, $column_number ) {
if ($table_id==1) {
if ($column_number==8 or $column_number==9) {
$x=strpos($tablepress_cell_content, ‘(‘);
if ($x==0) {$temp=$tablepress_cell_content;}
else {$temp=substr($tablepress_cell_content,0,$x);}
$tablepress_cell_content = ‘<img src=”‘.$tablepress_cell_content.'”/>’;
}
}
return $tablepress_cell_content;
}You want to remove these lines:
$x=strpos($tablepress_cell_content, ‘(‘);
if ($x==0) {$temp=$tablepress_cell_content;}
else {$temp=substr($tablepress_cell_content,0,$x);}The it should work
Also I think the line should be:
$tablepress_cell_content = “<img src=”.$tablepress_cell_content.”/>”;
Thanks for your help
It’s working on Mozila / Firefox but not working on chrome.
I am using following function
add_filter( ‘tablepress_cell_content’, ‘Google_Wrap15’, 2, 8 );
function Google_Wrap15( $tablepress_cell_content, $table_id, $row_number, $column_number ) {
if ($table_id==1) {
if($row_number >= 2) {
if ($column_number==8) {
$tablepress_cell_content = ‘<img width=”50″ height=”50″ src=”‘.$tablepress_cell_content.'”/>’;
} else if ($column_number==9){
$includes_images_url = includes_url().’images/buy_now.png’;
$tablepress_cell_content = ‘<img width=”72″ height=”32″ src=”‘.$includes_images_url.'”/>‘;
}
}
}
return $tablepress_cell_content;
}Whoa!
Column 8 is an image so the above code should work but column 9 is a link so you need code that looks like this:$tablepress_cell_content = “click here“;
Of course you can put anything in “click here” including a link to an image as in <img src=’http://yourpath/camera.png’>
It does not work for me in IE, Chrome or Firefox
Try this – I would copy and paste it from the email
add_filter( ‘tablepress_cell_content’, ‘ziyaindia78_table1’, 10, 4 );
function ziyaindia78_table1( $tablepress_cell_content, $table_id, $row_number, $column_number )
{
if ($table_id==1) {
if($row_number >1) {
if ($column_number==8) {
$tablepress_cell_content = “<img width=’50’ height=’50’ src='”.$tablepress_cell_content.”‘/>”;
} else if ($column_number==9){
$tablepress_cell_content = “click here“;
}
}
}
return $tablepress_cell_content;
}Hi,
nice progress here!
Please try this, which I reformatted a little bit and where I made the naming more consistent:
add_filter( 'tablepress_cell_content', 'ziya_wrap_images', 10, 4 ); function ziya_wrap_images( $cell_content, $table_id, $row_number, $column_number ) { if ( '1' == $table_id ) { if ( $row_number > 1 ) { if ( 8 == $column_number ) { $cell_content = '<img width="50" height="50" src="' . esc_url( $cell_content ) . '"/>'; } elseif ( 9 == $column_number ) { if ( 'TBA' !== $cell_content ) { $image_url = includes_url() . 'images/buy_now.png'; $image_html = '<img width="72" height="32" src="' . esc_url( $image_url ) . '"/>'; $cell_content = '<a href="' . esc_url( $cell_content ) . '">' . $image_html . '</a>'; } } } } return $cell_content; }Note that you’ll have to save the table after making changes to this code (or wait 12 hours) to clear the cache.
Regards,
TobiasDear Tobias / Andrew
Thanks for all your reply but still images are not displaying on chrome.
http://www.gamesage.co.uk/?page_id=8
Thanks in advance,
ZiyaDear Tobias / Andrew
Please check
Thanks,
ZiyaHi Ziya,
where have you added this PHP code now? Is it working in other browsers? That would be strange, as I can’t see any changes on the page here. Or are you maybe using a caching plugin that could be influencing this?
Regards,
Tobias
The topic ‘Adding HTML to tables’ is closed to new replies.