Hi all.
I have this code in my wordpress blog
$action='permalink';
Basically I want to know if I can change it to something like
$action="www.mysite.com/newpage.html";
I have tried this but it doesnt work.
What I would like to happen is, when the user clicks I dont want them directed to the permalink, but I want them directed to a website instead.
Thanks in advance, Adam
shadowvkc
New php-forum User
Posts: 1
Joined: Fri Jul 01, 2011 2:00 pm
Top
PHP coding help
Moderator: General Moderators
Re: PHP coding help
Not enough information.
Re: PHP coding help
Hi,
What other information would your require?
The PHP page which I would like to change looks like this:
Basically at the moment, when someone clicks on a item in the gallery they are taken to the permalink of that post.. but I would like them all to be taken to a URL instead but I cant figure out the syntax of what the $action= should be to do this?
Thanks, Adam
What other information would your require?
The PHP page which I would like to change looks like this:
Code: Select all
<?php
/**
* This file generates the portfolio items HTML.
*/
//display the category filter if enabled
if($show_cat=='true'){
echo('<div id="portfolio-categories">');
$cats=pexeto_get_taxonomy_children('portfolio_category', $cat_id);
echo '<h6>'.get_opt('_showme_text').'</h6>';
echo '<ul><li>'.get_opt('_all_text').'</li>';
for($i=0; $i<count($cats); $i++){
echo('<li id="'.$cats[$i]->term_id.'" class="category">'.$cats[$i]->name.'</li>');
}
echo('</ul></div>');
}
echo '<div class="loading"></div><div class="items">';
//set the query_posts args
$args= array(
'posts_per_page' =>-1,
'post_type' => 'portfolio'
);
if($cat_id!='-1'){
$slug=pexeto_get_taxonomy_slug($cat_id);
$args['portfolio_category']=$slug;
}
//set the order arguments
if($order=='custom'){
$args['orderby']='rand';
$args['order']='asc';
}else{
$args['orderby']='rand';
$args['order']='desc';
}
query_posts($args);
$html='';
$imgWidth=$pexetoImageSizes[$column_number]['width'];
$imgHeight=$pexetoImageSizes[$column_number]['height'];
if(have_posts()) {
while (have_posts()) {
the_post();
$permalink=get_permalink();
if($title_link=='on'){
$title='<a href="'.$permalink.'">'.get_the_title().'</a>';
}else{
$title=get_the_title();
}
$description=get_post_meta($post->ID, 'description_value', true);
$descHtml=$show_desc=='true'?'<div class="item-desc" style="width:'.$imgWidth.'px;"><h4>'.$title.'</h4><hr/><p>'.$description.'</p></div>':'';
//insert the description in the lightbox if descriptions are disabled
$lightHtml=$show_desc=='true'?'':$description;
$preview=get_post_meta($post->ID, 'preview_value', true);
$thumbnail=get_post_meta($post->ID, 'thumbnail_value', true);
if($auto_thumbnail=='on'){
$thumbnail=pexeto_get_resized_image($preview, $imgWidth, $imgHeight);
}
$action='permalink'; **************THIS IS THE LINE I THINK NEEDS CHANGING******************
$customlink=get_post_meta($post->ID, 'custom_value', true);
//set the link of the image depending on the action selected
if($action=='nothing'){
$openLink='';
$closeLink='';
}else if($action=='permalink'){
$openLink='<a href="'.$permalink.'">';
$closeLink='</a>';
}else if($action=='custom'){
$openLink='<a href="'.$customlink.'" target="_blank">';
$closeLink='</a>';
}else{
$preview=$action=='video'?$customlink:$preview;
$openLink='<a rel="lightbox[group]" class="single_image" href="'.$preview.'" title="'.$lightHtml.'">';
$closeLink='</a>';
}
//get the category IDs to which the items belong and generate a string
//containing them, separated by commas, for example: 1,2,3
$terms=wp_get_post_terms($post->ID, 'portfolio_category');
$term_string='';
foreach($terms as $term){
$term_string.=($term->term_id).',';
}
$term_string=substr($term_string, 0, strlen($term_string)-1);
//generate the final item HTML
$html.= '<div class="portfolio-item" title="'.$term_string.'">'.$openLink.'<img src="'.$thumbnail.'" class="img-frame" width="'.$imgWidth.'" height="'.$imgHeight.'"/>'.$closeLink.$descHtml.'</div>';
}
}
echo $html;
echo '</div>';
Thanks, Adam
Re: PHP coding help
Ideally, you would provide enough details that someone could reproduce your problem. Helpful details would be WordPress version and what theme and relevant plugins are installed.shadowvkc wrote:What other information would your require?
If you mean a URL of the same domain, you could leave $action = 'permalink' and change the permalink settings through the WordPress Dashboard. That affects every permalink across the site, so it might not be a good idea.shadowvkc wrote:I would like them all to be taken to a URL instead
A better idea might be to set $action = 'custom' and add custom fields named "custom_value". Notice that the line after the $action assignment reads the custom field with get_post_meta() and later uses $customlink to build the link.