• jshebester

    (@jshebester)


    I think this may be a more suitable location to ask my question. I have a news page set up biggovernmentreport.com and I have it looking about how I want it to look. However, when you click the title of a story, it takes you to the post page. Once you are on the post page, if you click the title there, it then takes you to the source of the story. I want it so when you click the title on the main page it takes you directly to the source of the news story. I’m thinking a redirect would work best as the stories are also posting to the corresponding facebook and twitter pages. That way, if you click the link on facebook or twitter, it takes you directly to the source of the story, rather than to a page with an excerpt and a link to the source. Any wordpress ninjas out there know how I can accomplish this in a way that doesn’t require manually plugging in URLs with every single post?

Viewing 15 replies - 1 through 15 (of 18 total)
  • frizax

    (@frizax)

    This can be easily done by using wp_redirect() function on single.php template.

    I believe you are using custom field for source link. You just need retrieve source link in single.php and pass to wp_redirect(<source_url>).

    For more detail about wp_redirect() function: http://codex.ww.wp.xz.cn/Function_Reference/wp_redirect

    Thread Starter jshebester

    (@jshebester)

    I’ll have to check that out. I was hoping for a plugin, but beggars can’t be choosers! Would this fix apply to every post automatically?

    frizax

    (@frizax)

    yes, this will work for each post.

    Thread Starter jshebester

    (@jshebester)

    Would it just be a matter of editing the file to redirect to the URL that is in the title on the post page? PHP has never been a strong point. Where could I find what that is labeled as?

    frizax

    (@frizax)

    You need to edit single.php and add the following code just above get_header() function.

    $source_url = get_post_meta($post->ID, 'source_url', true);
    if (!empty($source_url)) {
      wp_redirect($source_url);
      exit;
    }

    In the above code just change the custom field name (<source_url>).

    The code will redirect browser to the source url provided. If source url in not mentioned it render the normal page (as currently on site).

    Thread Starter jshebester

    (@jshebester)

    I’m not sure what a custom field name is or where it can be found. Is that something imported by RSS multi importer? I think I see where you’re going, I’m just missing a piece or two!

    frizax

    (@frizax)

    Can you share the code written in single.php?

    Thread Starter jshebester

    (@jshebester)

    Sure thing.

    [Excessive and un-code buttoned code removed]

    Thread Starter jshebester

    (@jshebester)

    Thanks for all of your efforts btw.

    frizax

    (@frizax)

    No luck with single.php code, it calling other files to display the title.

    Please share the code of page custom/post-header.php

    Hope this help to resolve your query.

    Thread Starter jshebester

    (@jshebester)

    <?php
    /**
     * Shows the title of the post along with the meta information. This file should not be loaded by itself, but should instead be included using get_template_part or locate_template.
     * Users can override this in a child theme. If you want a different style of title and meta for a different custom post type, you can create a file
     * called post-header-<post-type>.php. E.g. post-header-book.php. If you want a different structure for posts / pages, you could use post-header-post.php and/or
     * post-header-page.php.
     *
     * @since 3.8.3
     * @package Suffusion
     * @subpackage Custom
     */
    
    global $post, $suf_page_show_comment, $suf_page_show_posted_by, $suf_page_meta_position, $suf_byline_before_permalink, $suf_byline_after_permalink,
           $suf_byline_before_category, $suf_byline_after_category, $suf_byline_before_tag, $suf_byline_after_tag, $suf_byline_before_edit, $suf_byline_after_edit;
    $format = suffusion_get_post_format();
    if ($format == 'standard') {
    	$format = '';
    }
    else {
    	$format = $format . '_';
    }
    $meta_position = 'suf_post_' . $format . 'meta_position';
    $show_cats = 'suf_post_' . $format . 'show_cats';
    $show_posted_by = 'suf_post_' . $format . 'show_posted_by';
    $show_tags = 'suf_post_' . $format . 'show_tags';
    $show_comment = 'suf_post_' . $format . 'show_comment';
    $show_perm = 'suf_post_' . $format . 'show_perm';
    $with_title_show_perm = 'suf_post_' . $format . 'with_title_show_perm';
    
    global $$meta_position, $$show_cats, $$show_posted_by, $$show_tags, $$show_comment, $$show_perm, $$with_title_show_perm;
    $post_meta_position = $$meta_position;
    $post_show_cats = $$show_cats;
    $post_show_posted_by = $$show_posted_by;
    $post_show_tags = $$show_tags;
    $post_show_comment = $$show_comment;
    $post_show_perm = $$show_perm;
    $post_with_title_show_perm = $$with_title_show_perm;
    
    if (is_singular()) {
    	$header_tag = "h1";
    }
    else {
    	$header_tag = "h2";
    }
    
    if ($post->post_type == 'post') {
    	?>
    <header class='post-header title-container fix'>
    	<div class="title">
    		<<?php echo $header_tag;?> class="posttitle"><?php echo suffusion_get_post_title_and_link(); ?></<?php echo $header_tag;?>>
    	<?php
     			if ($post_meta_position == 'corners') {
    	?>
    	<div class="postdata fix">
    		<?php
    		$title = get_the_title();
    		if (($post_show_perm == 'show-tleft' || $post_show_perm == 'show-tright') && (($title == '' || !$title) || (!($title == '' || !$title) && $post_with_title_show_perm != 'hide'))) {
    			$permalink_text = apply_filters('suffusion_permalink_text', __('Permalink', 'suffusion'));
    			$prepend = apply_filters('suffusion_before_byline_html', do_shortcode($suf_byline_before_permalink), 'permalink');
    			$append = apply_filters('suffusion_after_byline_html', do_shortcode($suf_byline_after_permalink), 'permalink');
    			echo "<span class='permalink'><span class='icon'> </span>".$prepend.suffusion_get_post_title_and_link($permalink_text).$append."</span>\n";
    		}
    
    		if (($post_show_posted_by == 'show-tleft' || $post_show_posted_by == 'show-tright') && $post_meta_position == 'corners') {
    			suffusion_print_author_byline();
    		}
    		if ($post_show_cats == 'show' || $post_show_cats == 'show-tright') {
    			$prepend = apply_filters('suffusion_before_byline_html', do_shortcode($suf_byline_before_category), 'category');
    			$append = apply_filters('suffusion_after_byline_html', do_shortcode($suf_byline_after_category), 'category');
    			?>
    			<span class="category"><span class="icon"> </span><?php echo $prepend; the_category(', '); echo $append; ?></span>
    			<?php
    
    		}
    		if (is_singular()) {
    			if (is_attachment()) {
    				$mime = get_post_mime_type();
    				if (strpos($mime, '/') > -1) {
    					$mime = substr($mime, 0, strpos($mime, '/'));
    				}
    				$comments_disabled_var = "suf_{$mime}_comments";
    				global $$comments_disabled_var;
    				if (isset($$comments_disabled_var)) {
    					$comments_disabled = $$comments_disabled_var;
    				}
    				else {
    					$comments_disabled = false;
    				}
    			}
    			else {
    				$comments_disabled = false;
    			}
    
    			if ('open' == $post->comment_status && ($post_show_comment == 'show' || $post_show_comment == 'show-tleft') && !$comments_disabled) {
    				?>
    				<span class="comments"><span class="icon"> </span><a href="#respond"><?php _e('Add comments', 'suffusion'); ?></a></span>
    				<?php
    
    			}
    		}
    		else if ($post_show_comment == 'show' || $post_show_comment == 'show-tleft') {
    			?>
    			<span class="comments"><span class="icon"> </span><?php comments_popup_link(__('No Responses', 'suffusion') . ' »', __('1 Response', 'suffusion') . ' »', __('% Responses', 'suffusion') . ' »'); ?></span>
    			<?php
    		}
    		if (get_edit_post_link() != '') {
    			$prepend = apply_filters('suffusion_before_byline_html', do_shortcode($suf_byline_before_edit), 'edit');
    			$append = apply_filters('suffusion_after_byline_html', do_shortcode($suf_byline_after_edit), 'edit');
    			?>
    			<span class="edit"><span class="icon"> </span><?php edit_post_link(__('Edit', 'suffusion'), $prepend, $append); ?></span>
    			<?php
    
    		}
    		if ($post_show_tags == 'show-tleft' || $post_show_tags == 'show-tright') {
    			$tags = get_the_tags();
    			$prepend = apply_filters('suffusion_before_byline_html', do_shortcode($suf_byline_before_tag), 'tag');
    			$append = apply_filters('suffusion_after_byline_html', do_shortcode($suf_byline_after_tag), 'tag');
    			if (is_array($tags) && count($tags) > 0) {
    			?>
    			<span class="tags tax"><span class="icon"> </span><?php the_tags($prepend, ', ', $append); ?></span>
    			<?php
    			}
    		}
    		?>
    	</div><!-- /.postdata -->
    		<?php
    
    }
    	?>
    </div><!-- /.title -->
    	<?php
     		if ("post" == $post->post_type) {
    		?>
    	<div class="date"><span class="month"><?php the_time('M'); ?></span> <span
    			class="day"><?php the_time('d'); ?></span><span class="year"><?php the_time('Y'); ?></span></div>
    	<?php
    
    	}
    	?>
    </header><!-- /.title-container -->
    	<?php
    
    }
    else {
    	if (!is_singular()) {
    		?>
    <header class="post-header fix">
    	<<?php echo $header_tag; ?> class="posttitle"><?php echo suffusion_get_post_title_and_link(); ?></<?php echo $header_tag; ?>>
    </header>
    	<?php
    	}
    	else {
    		$hide_title = suffusion_get_post_meta($post->ID, 'suf_hide_page_title', true);
    		if (!$hide_title) {
    			?>
    <header class="post-header fix">
    	<<?php echo $header_tag; ?> class="posttitle"><?php the_title(); ?></<?php echo $header_tag; ?>>
    </header>
    		<?php
    		}
    	}
    
    	if ($post->post_type == 'page' && $suf_page_meta_position == 'corners') {
    		?>
    	<div class="postdata fix">
    		<?php
    		if ($suf_page_show_posted_by == 'show-tleft' || $suf_page_show_posted_by == 'show-tright') {
    			suffusion_print_author_byline();
    		}
    
    		if (is_attachment()) {
    			$mime = get_post_mime_type();
    			if (strpos($mime, '/') > -1) {
    				$mime = substr($mime, 0, strpos($mime, '/'));
    			}
    			$comments_disabled_var = "suf_{$mime}_comments";
    			global $$comments_disabled_var;
    			if (isset($$comments_disabled_var)) {
    				$comments_disabled = $$comments_disabled_var;
    			}
    			else {
    				$comments_disabled = false;
    			}
    		}
    		else {
    			$comments_disabled = false;
    		}
    
    		if ('open' == $post->comment_status && ($suf_page_show_comment == 'show' || $suf_page_show_comment == 'show-tleft') && !$comments_disabled) {
    			?>
    			<span class="comments"><span class="icon"> </span><a href="#respond"><?php _e('Add comments', 'suffusion'); ?></a></span>
    			<?php
    
    		}
    		if (get_edit_post_link() != '') {
    			$prepend = apply_filters('suffusion_before_byline_html', do_shortcode($suf_byline_before_edit), 'edit');
    			$append = apply_filters('suffusion_after_byline_html', do_shortcode($suf_byline_after_edit), 'edit');
    			?>
    			<span class="edit"><span class="icon"> </span><?php edit_post_link(__('Edit', 'suffusion'), $prepend, $append); ?></span>
    			<?php
    
    		}
    		?>
    	</div>
    		<?php
    
    	}
    }
    ?>
    WPyogi

    (@wpyogi)

    Posting code without the code buttons causes problems on these forums and may corrupt your code. You should also be using a pastebin for this much code.

    Please see this: http://codex.ww.wp.xz.cn/Forum_Welcome#Posting_Code

    Thread Starter jshebester

    (@jshebester)

    My bad, I’m a bit new here.

    frizax

    (@frizax)

    Here is the code to be placed in single.php, just before get_header() function:

    $source_url = get_post_meta($post->ID, 'rssmi_source_link', true);
    if (!empty($source_url)) {
      wp_redirect($source_url);
      exit;
    }

    Hope this works 🙂

    frizax

    (@frizax)

    The code mentioned above will redirect post to the source_url but it will open in same window. (when you click from home page it load source_url in same window).

    Do the following edit in custom/post-header.php to open links in new window when you click from the home page or other archive pages:

    replace #50

    <<?php echo $header_tag;?> class="posttitle"><?php echo suffusion_get_post_title_and_link(); ?></<?php echo $header_tag;?>>

    with

    <?php
          $source_url = get_post_meta($post->ID, 'rssmi_source_link', true);
          if (!empty($source_url)) { ?>
            <h1 class="posttitle"><a href='<?php echo $source_url;?>' class='entry-title' rel='bookmark' title='<?php echo $source_url;?>' target="_blank"><?php echo $post->post_title;?></a></h1>
          <?php } else { ?>
            <<?php echo $header_tag;?> class="posttitle"><?php echo suffusion_get_post_title_and_link(); ?></<?php echo $header_tag;?>>
          <?php }
        ?>
Viewing 15 replies - 1 through 15 (of 18 total)

The topic ‘link redirection’ is closed to new replies.