Closed Moniet closed 7 years ago
Can you isolate the code that is making the problem. Also in the images you added -- what should permalinks look like. Which picture shows incorrect URLs?
Sorry if the code is very scattered.
I'm using the wp_list_categories( );
function in the to get the list of categories for my sidebar.
But it's getting the wrong link. Look at the bottom left corner of the images where I've highlighted the links in the sidebar (which you get with the wp_list_categories) as well as the links within the post (which you get with the the_permalink();
function). This code is in the header.php file.
What happens when you click on the links? Do you get 404 error? Also Why are you using wp_list_categories to list posts. It's used for listing categories. Also I don't see that anywhere in your code. Can you paste that bit of code here.
The header.php File that contains the wp_list_categories(); function
You can find this function under the under the <ul id=sidebar>
tag.
<html>
<head>
<meta name="viewport" content="width=device-width">
</head>
<body>
<div id="header">
<object data="<?php echo get_stylesheet_directory_uri(); ?>/img/logo.svg" id="h1" type="image/svg+xml">
</object>
</div>
<div class="navbar">
<section>
<h3>Chapters</h3>
<ul id="sidebar">
<?php wp_list_categories('show_count=0&title_li=&hide_empty=0&exclude=1'); ?>
</ul>
</section>
</div>
<div class="home_user_buttons">
<a class="home_user_link" href="/">
<object data="<?php echo get_stylesheet_directory_uri(); ?>/img/home.svg" type="image/svg+xml" class="home_svg">
<img class="home_img" src="<?php echo get_stylesheet_directory_uri(); ?>/img/home.png" type="image/png">
</object>
</a>
<a class="home_user_link" href="/wp-login.php?">
<object data="<?php echo get_stylesheet_directory_uri(); ?>/img/user.svg" type="image/svg+xml" class="user_svg">
<img class="user_img" src="<?php echo get_stylesheet_directory_uri(); ?>/img/user.png" type="image/png">
</object>
</a>
</div>
<svg id="menu" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" xmlns:osb="http://www.openswatchbook.org/uri/2009/osb" height="64" viewBox="0 0 64 64.000002" width="64" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
<metadata id="metadata7">
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
<dc:title/>
</cc:Work>
</rdf:RDF>
</metadata>
<g stroke-width="10">
<rect id="rect4243" opacity="0.99" ry="4.339" height="9.7222" width="49.629" y="27.639" x="7.1855"/>
<rect id="rect6003" opacity="0.99" ry="4.339" height="9.7222" width="49.629" y="15" x="7.1855"/>
<rect id="rect6005" opacity="0.99" ry="4.339" height="9.7222" width="49.629" y="40.278" x="7.1855"/>
</g>
</svg>
<svg id="cross" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="64" viewBox="0 0 64 64.000002" width="64" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
<metadata id="metadata7">
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
<dc:title/>
</cc:Work>
</rdf:RDF>
</metadata>
<rect id="rect6003" opacity="0.99" transform="matrix(.70407 -.71013 .71013 .70407 0 0)" ry="4.339" height="9.7222" width="49.629" y="40.452" x="-24.257" stroke-width="10"/>
<rect id="rect4144" opacity="0.99" transform="matrix(-.71013 -.70407 .70407 -.71013 0 0)" ry="4.339" height="9.7222" width="49.629" y="-4.3034" x="-70.128" stroke-width="10"/>
</svg>
<div class="before_footer_block"></div>
<div class="jumbotron_container">
<h2>Welcome!</h2>
<p>You found us! Scroll to learn about how you can get an EliteGradJob</p>
</div>
Seems something went wrong when pasting the code :) check out your post, and try again :) .
My bad, I forgot to add the markup for syntax highlighting.
Anyways. When I click the links it gives 404 error because the links are wrong. For some reason the post name is giving example.com/category/post-slug
value. When the actual permalink of the post is example.com/post-slug
.
Could this be because I'm using the /%postname%/
function in the permalink settings on Wordpress to get the link?
Should I not be using the wp_list_categories();
function?
wp_list_categories(); is used for displaying categories not posts. So that may be a problem. Try setting permalinks to be the "Default" and see if that changes things.
I just used the get_posts();
function in the functions.php file and called it in the sidebar.php file. It's working fine now.
I think when I changed the loop to include query posts, the wp_list_cats();
function doesn't seem to work as it did with the original loop.
Thanks for pointing out the error Ivan! I appreciate your time.
After changing the loop to include the query posts, the wp_list_categories(); function is fetching the wrong link for the posts. I've tried resetting the permalink to get the /%postname%/ but it didn't work.
Example By Image
MY INDEX PHP
`<?php get_header(); ?>
<?php get_footer(); ?>`