Sitemap is a page that shows the parts or links contained on the site. Sitemap devoted to two things for search engines and for the user (human). This time I will give a little tutorial on how to create a sitemap in wordpress for user. Here I am using a CMS wordpress hosting service that has the facility to use a PHP file. OK we just practice how to create a sitemap in wordpress.
The steps that you should follow the following :
- Login to cpanel your website
- Open the file manager
- Go to the directory of your website template is being actively used
example: public_html / wp-content / themes / name-theme
- Create a new file with the name sitemap.php
- Copy or type the code below in file sitemap.php
<?php
/*
Template Name: Sitemap
*/
?>
<?php get_header(); ?>
<div id="content" >
<div class="post">
<div class="title">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<?php the_title(); ?>
<!-- ----------------- Display Post with its relative category ----------------- -->
</a></h2>
</div>
<div class="entry siteMap">
<h2 id="posts">Posts</h2>
<ul>
<?php
// Add categories seprated with comma (,) you'd like to hide to display on sitemap
$cats = get_categories('exclude=');
foreach ($cats as $cat) {
echo "<li><h3>".$cat->cat_name."</h3>";
echo "<ul>";
query_posts('posts_per_page=-1&cat='.$cat->cat_ID);
while(have_posts()) {
the_post();
$category = get_the_category();
for($xi=0;$xi<=5;$xi++){
if ($category[$xi]->cat_ID == $cat->cat_ID) {
echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
}
}
}
echo "</ul>";
echo "</li>";
}
?>
</ul>
<!-- ----------------- Display Categories ----------------- -->
<h2>Categories</h2>
<ul>
<?php wp_list_cats("sort_column=name&feed_image=/wp-content/themes/wizer/images/rss-ball.jpg&optioncount=1&hierarchical=0"); ?>
</ul>
<!-- ----------------- Display Pages ----------------- -->
<h2 id="pages">Pages</h2>
<ul>
<?php
// Add pages seprated with comma[,] that you'd like to hide to display on sitemap
wp_list_pages(
array(
'exclude' => '',
'title_li' => '',
)
);
?>
</ul>
</div>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?> - Save file sitemap.php
- Login to your-domain/wp-admin
- Click the page menu
- Select add new
- Type the title "Sitemap" without quotes
- On the Page Attributes -> Template
- Select sitemap
- Click Publish
0 komentar:
Post a Comment