WordPress.org

Ready to get started?Download WordPress

Forums

Problem navigation with #link (8 posts)

  1. fxbenard
    Member
    Posted 3 years ago #

    Hello, i'm using a theme with this snippet to create a #link to my pages in my index page.
    It uses the page link for the navigation.

    It works great when my page title is exactly the same as my page permalink but as soon as my page title include a space or two words the pag and the post_title get different and the #link doesn't work anymore.

    $new_title = str_replace(" ", "", $pag->post_title);
    echo '
    <li><a href="#'.$new_title.'">post_title.'">'.$pag->post_title.'</a></li>
    ';

    Does someone have a idea to make it work another way?
    thanks in advance
    bye

  2. MandyWhite
    Member
    Posted 3 years ago #

    Is the target using your permalink? If yes, don't use page title after the #. Use your permalink so it matches that target link. If your permalink includes directory names, then simply using the permalink may not work. There's no way I can know the target so first, you need to figure out how the target name is determined, and then use the same method in your menu link..

  3. fxbenard
    Member
    Posted 3 years ago #

    the structure is okay for the page except that i give you an example:

    my about page title is "about" and my permalink is going to be :
    "http://mysite.com/about/"

    like that my #link works great

    I got a problem when :
    my problem page title is "problem page" and my permalink is automatically going to be :
    "http://mysite.com/problem_page/"

    Then my page title and the permalink are different and then the #link doesn't work anymore.

    My knowledge of php is really basic but i'm sure there is a way to change this snippet so it doesn't use the post title but the permalink

    if someone want to see the full index page i can send it directly.
    Thanks

  4. MandyWhite
    Member
    Posted 3 years ago #

    The # link is an achor. It must have a target on the page, and it must match. What's being put in the target? It's normally inside YourTagetHitsHere w/in the page.

  5. MandyWhite
    Member
    Posted 3 years ago #

    Sorry.. that didn't work b/c I used html. It should be a link with ID="YOURTARGET"

  6. MandyWhite
    Member
    Posted 3 years ago #

    You might not be able to see the link with your target but it's there in the code. At times, it's wrapped around a title or image. Your menu #TARGETWORD must match the A tag with ID=TARGETWORD. It must be the same word. It's obviously doing something different, and it's not the same. You want to duplicate it to match the page's target A ID='' link. Actually, if you can view source on a page that's working, open it in norepad, and search the page for the exact same word. Then find the PHP code that writes the A link's target, and make sure the format and field match.

  7. MandyWhite
    Member
    Posted 3 years ago #

    Sorry, I just read your comment re: the index code. If you can post a link to the template file that has the PHP code the writes the target link (not your menu link but the spot the menu link targets, as in the anchor), I can tell you what you need to put in the menu after #. It's good to check just in case it's not the permalink. It's possible that the anchor has id="problem_page" or id="problem-page". The code could be replacing a space in the title with something else. That's why I wanted you to check the code that write that actual target for the link in your menu. The two words must match for the page to hit the right target when someone clicks it.

  8. fxbenard
    Member
    Posted 3 years ago #

    <!-- NAVIGATION -->
    <ul class="side_navigation">
    	<li><a href="#page-single" id="page-top">Top</a></li>
    	<?php
    	$pages = get_pages('sort_order=asc&sort_column=menu_order&depth=1');
    	foreach ($pages as $pag) {
    	$new_title = str_replace(" ", "", $pag->post_title);
    	echo '<li><a href="#'.$new_title.'"title="'.$pag->post_title.'">'.$pag->post_title.'</a></li>';}
    		?>
    </ul>
    </div>

    and in the content i have this :

    <?php
    	$pages = get_pages('sort_order=asc&sort_column=menu_order&depth=1');
    	foreach ($pages as $pag) {
    	setup_postdata($pag);
    	$new_title = str_replace(" ", "", $pag->post_title);
    		?>
    
    <div class="content-wrap" id="<?=$pag->post_title;?>">
    	<h3 class="sub-title"><?=$pag->post_title?></h3>
    	<div class="break-page"></div>
    	<div class="break-delta"></div>
    
    <?php the_content(); ?>
    </div>
    <? } ?>

    There is only one page and the menu links get to the #

    thanks for your help

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags