Wordpress SEO - What are you looking for?

If you're looking for answers to SEO or wordpress related questions, type in a phrase and wait for hints or click enter! The results also show links to external sources.

161 articles in the database

How to change the appearance of a page depending on the category in WP?

[ Article content is protected by Plagiashield ]

wp-category

Sometimes it is so, that we need to distinguish in an individual way a given category, its heading, color, font, category or maybe even width websites. In this section I would like to show, like can be to do it in a very simple way, and how to manage it so that our files do not have thousands of lines of code in a moment.

We want to be able to create a custom look relative to the category we are in, to do this we will use the code below:

category) { $category->cat_name . ' '; } ?>
cat_name == 'category1') { ?>

As we can see, this code is relatively understandable. It takes categories, checks if we are in the category named "category1", then if it is true, it displays us the contents of the if. Why did I put php tags everywhere? Thereforethat it will make it easier to add more elements that are not already php code.

We display the category name as follows:

cat_name . ' '; } ?>

We can see that we are once again fetching everything and displaying the categories. I'm leaving it this way because this way the above code can be pasted into your theme/code.

In other words, if we want only the category "category1" to display in red, we just need to create the following code:

cat_name . ' '; } ?>
cat_name == 'category1') { ?>
	cat_name . ' '; } ?>

And in the stylesheet you add:

span.red {
  color: red;
}

If we have 2 categories, the code looks like thisco:

cat_name . ' '; } ?>
cat_name == 'category1') { ?>
	cat_name . ' '; } ?>


cat_name . ' '; } ?>
cat_name == 'category2') { ?>
	cat_name . ' '; } ?>

Now we're going to get problemWhat if we have 5 categories and there are 10 files to paste them into? What if I need to change something?
Well, the easiest way is to close the above code in an additional file named e.g. colorcategory.php, so the content of the file is:

amendment colours for the category
 */
?>

cat_name . ' '; } ?>
cat_name == 'category1') { ?>
	cat_name . ' '; } ?>
.


cat_name . ' '; } ?>
cat_name == 'category2') { ?>
	cat_name . ' '; } ?>
.

Put it in the root folder with the file and refer to it where we need it, using the code below:

There is a simpler method, we can just style by category, just after downloading the category, apply the code below:

name; ?>

This makes it much simpler to change the color of a category and puts less strain on the base. Thanks to this everywhere, where paste this code, we will be able to call the contents of the colorcategory.php file, which will make our work much easier. We will be able to use it multiple times by copying one line and it will be easier for us to make changes.

For example, with this solution we can display graphic headers for each category different, just add:

address.jpg">

Suddenly, everything is as simple as adding picture at pagesę. We can put anything we want in an if.

If necessary, we can also display entries only from a given category, just add the code below. By using "(is_category() || is_single())" the content will be displayed only on the subpage of the category or single entry.

    cat_ID; $current_name = $category->cat_name; $myposts = get_posts(array('category__in' => array($current))) } } foreach($myposts as $post) : setup_postdata($post); ?>

The link will be, of course, the title of the entry. You must remember about " ", so we can avoid problems when there will be more than one similar loop on one subpage.

 The code presented is not the most optimal. I tried to make it the most readable and versatile.  

Avatar

O Karol Trybulski

He started his adventure with creating websites when HTML 3 was fashionable. Now he creates not only websites, but also effectively positions them. Since the end of 2014 he has been managing his own brand InBulb
  • Internal Links and Sematics

  • Link building
  • Sematics
  • Link building has never been easier. Hundreds of link possibilities in one click.
  • See

[ Article content is protected by Plagiashield ]

SEMRush - the best tool for SEO and PPC.

en_USEnglish
Read previous post:
senuto
15 SEO problems that SENUTO will solve

SENUTO and SEO is not one bit problematic. Anyone who has run an SEO campaign at least once knows that control over...

Close