• Resolved toxiccosmos

    (@toxiccosmos)


    Hi I’m hoping someone can help me figure out the best way to solve this problem.

    https://varriaga.com/portfolio/

    In my site, I have pages that pull posts from specific categories and arrange them to show an image, a description and thumbnail. Problem is, you can still find the single pages of those posts in a search engine, that when clicked on, only shows the description info and none of the pictures since those are shown through custom fields.

    I know I can disable the posts from showing up in a search engine, but what I would prefer to do is when it is searched for and found, that it redirects to the category page (above link) instead of the single page.

    Is this possible? What would be the best way to accomplish this?

    If it’s not possible, what are my alternatives?

    Thanks in advance for the help.

Viewing 14 replies - 1 through 14 (of 14 total)
  • Alwyn Botha

    (@123milliseconds)

    >>I know I can disable the posts from showing up in a search engine

    Apply this to your posts.php

    https://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=164734&from=35301&rd=1

    Thread Starter toxiccosmos

    (@toxiccosmos)

    So there’s no way to do what I’m looking for?

    Alwyn Botha

    (@123milliseconds)

    Thread Starter toxiccosmos

    (@toxiccosmos)

    Thanks for the link, but I’m actually hoping to avoid having to use noindex.

    a mix of php and javascript can do it,
    try this just bellow the body tag of single.php:

    <?php
    	foreach((get_the_category()) as $category) {
    	    if ($category->category_nicename=='portada') {
    			$url= get_bloginfo('url')."/category/".$category->category_nicename;
    			?>
    			<script type="text/javascript">
    			<!--
    			window.location = "<?php echo $url; ?>";
    			//-->
    			</script>
    			<?php
    			exit();
    		}
    	}
    ?>

    probably you’d add more conditions on the if clause
    like:
    if ($category->category_nicename=='portada' || $category->category_nicename=='another-category' || $category->category_nicename=='yet-another-cat')

    anyway, it’d be nice if you print the custom fields inside single.php too

    edit: added an exit to the code, just in case…

    Are all of these posts in a specific category or of a custom post type? If so, you could easily run a check in your theme to see if the page currently being loaded is a single item in that category/post type, then redirect to the archive page (or whatever you’re trying to direct them to) if so.

    Thread Starter toxiccosmos

    (@toxiccosmos)

    All the posts go to one of three pages; portfolio, artwork, and writing – each having their own category. The writing page does use the single.php to format chapter text and whatnot. The others aren’t suppose to open into single pages, instead loading the posts in their respective pages as I stated above.

    Of course search engines can find the single pages anyway and when clicked on, we end up seeing something like this https://varriaga.com/portfolio/american-river-review-2010-2/
    Obviously the single.php isn’t formated for them, just for the writing posts.

    I know I can create another single.php file specifically for those posts, but it wasn’t my intention that they be viewed that way.

    @curtiss – how would I do what you mentioned?

    @brasofilo – I would definitely like to try that out. How would I add the additional clauses? Would I use what you listed as is – with || ? I’m still somewhat new to php. :]

    Thanks a lot for the replies. I really appreciate the help. :]

    Thread Starter toxiccosmos

    (@toxiccosmos)

    @brasofilo – what content, if any, in that script do I need to edit?

    what are the categories you want to redirect ?

    || means or

    for what i saw you’ll write it like this:
    if ($category->category_nicename=='web' || $category->category_nicename=='print' || $category->category_nicename=='logos')

    so, when someone arrives in a post whose category is web or logos or print, the javascript will redirect to the /category/ONE-OF-THE-THREE/

    only problem is if a post have 2 categories, it’ll redirect to the first one

    Thread Starter toxiccosmos

    (@toxiccosmos)

    All the posts have two or three categories (artwork, portfolio, web, print, etc.), but they all belong to one of two pages (artwork, portfolio).

    I basically just need to direct the posts to either varriaga.com/portfolio/ or varriaga.com/artwork/

    Hmm. Is there a way to list the categories in the script but tell them where to redirect to instead of taking its name and adding it to a url?

    Thread Starter toxiccosmos

    (@toxiccosmos)

    Ok, your method worked nicely brasofilo. In the script I only listed “artwork” and “portfolio” as the categories to look for. My guess is that it searches all the categories, and since the posts all contain one of those, then when it finds it, it redirects it. It takes a few seconds, but it works.

    Thank you. :]

    to redirect somewhere specific you do:
    window.location = “https://you-redirection&#8221;;

    another configuration could be:

    foreach((get_the_category()) as $category) {
        if ($category->category_nicename=='your-category') {
    		?>
    		<script type="text/javascript">
    		<!--
    		window.location = "https://your-redirection";
    		//-->
    		</script>
    		<?php
    		exit();
    	}
    
        if ($category->category_nicename=='another-category') {
    		?>
    		<script type="text/javascript">
    		<!--
    		window.location = "https://another-redirection";
    		//-->
    		</script>
    		<?php
    		exit();
    	}
    
    }

    and for testing purposes you could do:

    foreach((get_the_category()) as $category) {
        if ($category->category_nicename=='your-category') {
    		echo "i am in your-category";
    		exit();
    	}
    
        if ($category->category_nicename=='another-category') {
    		echo "i am in another-category";
    		exit();
    	}
    
    }

    Thread Starter toxiccosmos

    (@toxiccosmos)

    That’s perfect. Thank you! :]

    :o]

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘redirect single post link for search engine?’ is closed to new replies.