Witam.
Mam problem z kodem, który został mi dostarczony przez developera. Gość pojechał na wakacje i zostawił mnie z problemem. Chodzi o to, żeby wyświetlić obrazki znajdujące się w tablicy image w miejscu, gdzie pojawia się link na drugiej stronie php.
Wydaje mi się, że trzeba użyć htmlowego tagu <img src= i podać ścieżkę do tablicy. Nie wiem jednak jak to zrobić.
Uprzejmie proszę o jakąś podpowiedź.
Pozdrawiam
PS: oryginalny kod z tablicami poniżej:
<?php
/*
* Custom Post: SWOT Analyses
*/
// Register post type.
function swots_post() {
$args = array(
'labels' => array(
'name' => 'SWOT Analyses',
'singular_name' => 'SWOT',
'add_new_item' => 'Add New SWOT',
'edit_item' => 'Edit SWOT',
'new_item' => 'New SWOT',
'view' => 'View SWOT',
'view_item' => 'View SWOT',
'search_items' => 'Search swots',
'not_found' => 'No swots found',
'not_found_in_trash' => 'No swots found in Trash',
'parent' => 'Parent SWOT'
),
'public' => true,
'rewrite' => array('slug' => 'swots'),
'capability_type' => 'post',
'hierarchical' => true,
'supports' => array('title', 'editor',)
);
register_post_type('swots', $args);
}
add_action('init', 'swots_post');
// Assign the category taxonomy (Not the post category one).
function create_swots_taxonomy() {
$labels = array(
'name' => _x('SWOT Category', 'taxonomy general name'),
'singular_name' => _x('Category', 'taxonomy singular name'),
'search_items' => __('Search SWOT Categories'),
'popular_items' => __('Popular SWOT Categories'),
'all_items' => __('All SWOT Categories'),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __('Edit SWOT Category'),
'update_item' => __('Update SWOT Category'),
'add_new_item' => __('Add New SWOT Category'),
'new_item_name' => __('New SWOT Category Name'),
'separate_items_with_commas' => __('Separate categories with commas'),
'add_or_remove_items' => __('Add or remove categories'),
'choose_from_most_used' => __('Choose from the most used categories'),
'menu_name' => __('SWOT Categories'),
);
register_taxonomy('swotcategory', 'swots', array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array('slug' => 'swot-category'),
));
}
add_action('init', 'create_swots_taxonomy');
// Add the meta box.
function add_custom_meta_box() {
add_meta_box(
'swots_meta_box',
'SWOT Details',
'show_custom_meta_box',
'swots',
'normal',
'default'
);
}
add_action('add_meta_boxes', 'add_custom_meta_box');
// Meta box array.
$prefix = 'bs_';
$custom_meta_fields = array(
array(
'label' => 'Author',
'desc' => 'Author to show on the SWOT',
'id' => $prefix.'author',
'type' => 'text'
), array(
'label' => 'Market',
'desc' => 'What is the market of the SWOT analysis',
'id' => $prefix.'market',
'type' => 'text'
), array(
'label' => 'Stake',
'desc' => 'What is the stake for the SWOT analysis',
'id' => $prefix.'stake',
'type' => 'text'
), array(
'label' => 'Starts',
'desc' => 'When is the event in play',
'id' => $prefix.'inplay',
'type' => 'text'
), array(
'label' => 'Odds',
'desc' => 'What are the suggested odds',
'id' => $prefix.'suggested',
'type' => 'text'
), array(
'label' => 'Bookmakers',
'desc' => 'What bookmakers will you be linking to',
'id' => $prefix.'bookmakers',
'type' => 'checkbox_group',
// tutaj są obrazki
'options' => array(
/*
* To add bookmakers:
* - Add a label with their name
* - Add the link in the value field
* - Add the image filename (not the directory) to the image field.
*/
'118bet' => array(
'label' => '118BET',
'value' => 'http://aff.188bet.com/Accept.aspx?sID=33829cf8-a5ab-48a7-8815-8ecda148928f&localeCode=en-gb&aID=94967&cID=dd42096e-d0a0-4e62-b842-921af6f02b14',
'image' => '118bet.png'
),
'betFred' => array(
'label' => 'BetFred',
'value' => 'http://partners.betfredaffiliates.com/processing/clickthrgh.asp?btag=a_14158b_798',
'image' => 'betfred.png'
),
'skybet' => array(
'label' => 'SkyBet',
'value' => 'http://affiliatehub.skybet.com/processing/clickthrgh.asp?btag=a_9588b_1&aid={betswot}',
'image' => 'skybet.png'
),
)
)
);
// Output meta box.
function show_custom_meta_box() {
global $custom_meta_fields, $post;
// Use nonce for verification.
echo '<input type="hidden" name="swots_meta_box_nonce" value="'.wp_create_nonce(basename(__FILE__)).'" />';
echo '<table class="form-table">';
foreach ($custom_meta_fields as $field) {
$meta = get_post_meta($post->ID, $field['id'], true);
echo '<tr>
<th><label class="custom-label" for="'.$field['id'].'">'.$field['label'].'</label></th>
<td>';
switch ($field['type']) {
case 'text':
echo '<input type="text" class="custom-text" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$meta.'" />
<br /><span class="custom-description description">'.$field['desc'].'</span>';
break;
case 'checkbox_group':
foreach ($field['options'] as $option) {
echo '<input type="checkbox" value="'.$option['value'].' '.$option['image'].'" name="'.$field['id'].'[]" id="'.$option['value'].'"',$meta && in_array($option['value'], $meta) ? ' checked="checked"' : '',' />
<label for="'.$option['value'].'">'.$option['label'].'</label><br />';
}
echo '<span class="description">'.$field['desc'].'</span>';
break;
}
echo '</td></tr>';
}
echo '</table>';
}
// Save the data.
function save_custom_meta($post_id) {
global $custom_meta_fields;
// Verify nonce
if (!wp_verify_nonce($_POST['swots_meta_box_nonce'], basename(__FILE__)))
return $post_id;
// Check autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return $post_id;
// Check permissions
if ('page' == $_POST['post_type']) {
if (!current_user_can('edit_page', $post_id))
return $post_id;
elseif (!current_user_can('edit_post', $post_id))
return $post_id;
}
// Loop through the fields and save the data.
foreach ($custom_meta_fields as $field) {
$old = get_post_meta($post_id, $field['id'], true);
$new = $_POST[$field['id']];
if ($new && $new != $old) {
update_post_meta($post_id, $field['id'], $new);
} else if ('' == $new && $old) {
delete_post_meta($post_id, $field['id'], $old);
}
}
}
add_action('save_post', 'save_custom_meta');
// Style custom post.
function swots_styling() {
?>
<style type="text/css" media="screen">
#menu-posts-swots .wp-menu-image {
background: url(<?php bloginfo('template_url') ?>/img/admin/swots-icon.png) no-repeat 6px 6px !important;
}
#menu-posts-swots:hover .wp-menu-image, #menu-posts-swots.wp-has-current-submenu .wp-menu-image {
background-position: 6px -16px !important;
}
#icon-edit.icon32-posts-swots {
background: url(<?php bloginfo('template_url') ?>/img/admin/swots-32x32.png) no-repeat;
}
.custom-text {
width: 300px;
padding: 5px;
}
</style>
<?php
}
add_action('admin_head', 'swots_styling');
?>
a tu strona z linkiem:
<?php
/*
* Template Name: Home
*/
get_header();
?>
<div class="wrapper main-content">
<?php get_sidebar(); ?>
<div class="content">
<ul class="swot-carousel">
<?php
// Get the custom post type.
$swots = new WP_Query(array(
'post_type' => 'swots',
'posts_per_page' => 10,
'orderby' => 'date',
'order' => 'DESC'
));
while ($swots->have_posts()) : $swots->the_post();
if (!is_permitted_by_s2member())
continue;
// Get any meta-data.
$metadata = get_post_custom();
$author = $metadata['bs_author'][0];
$market = $metadata['bs_market'][0];
$stake = $metadata['bs_stake'][0];
$inplay = $metadata['bs_inplay'][0];
$suggested = $metadata['bs_suggested'][0];
$bookmakers = unserialize($metadata['bs_bookmakers'][0]);
?>
<li class="swot">
<div class="metadata">
<ul>
<li><span class="title">Market:</span> <?php echo $market; ?></li>
<li><span class="title">Selection:</span> <?php the_title(); ?></li>
<li><span class="title">Event Starts:</span> <?php echo $inplay; ?></li>
<li><span class="title">Author:</span> <?php echo $author; ?></li>
</ul>
<ul class="right-meta">
<li><span class="title">Date:</span> <?php the_time('F j, Y'); ?></li>
<li><span class="title">Odds:</span> <?php echo $suggested; ?></li>
<li><span class="title">Advised Stake:</span> <?php echo $stake; ?></li>
<li>
<span class="title alignleft">Bet Now:</span>
<?php
// Show the images which were linked in metadata.
foreach ($bookmakers as $bookmaker) {
// Tutaj jest link
echo '<a href="'.$bookmaker.'">Link</a>';
}
?>
</li>
</ul>
<span class="category">
<?php
$categories = get_the_terms($post->ID, 'swotcategory');
foreach ($categories as $category) {
if ($category->name != "Latest Swots")
echo $category->name;
}
?>
</span>
<div class="clear"></div>
</div>
<div class="blackboard">
<?php the_content(); ?>
</div>
</li>
<?php endwhile; ?>
<li class="swot">
<div class="metadata">
<p class="no-margin textcenter">Our membership packages and registration process will be online soon.</p>
<p class="textcenter">If you would like to be alerted when the site is complete, please submit your details below. We will be in touch with you shortly.</p>
</div>
<div class="blackboard no-chalk">
<?php echo do_shortcode('[contact-form-7 id="95" title="Contact form 1"]'); ?>
</div>
</li>
</ul>
</div>
<div class="clear"></div>
</div>
<?php get_footer(); ?>