{"id":372276,"date":"2023-05-12T19:05:00","date_gmt":"2023-05-12T16:05:00","guid":{"rendered":"https:\/\/themewp.inform.click\/?p=372276"},"modified":"2022-10-14T22:41:58","modified_gmt":"2022-10-14T19:41:58","slug":"markera-hett-amnesinlagg-som-innehaller-mer-an-5-kommentarer","status":"publish","type":"post","link":"https:\/\/themewp.inform.click\/sv\/markera-hett-amnesinlagg-som-innehaller-mer-an-5-kommentarer\/","title":{"rendered":"Markera hett \u00e4mnesinl\u00e4gg som inneh\u00e5ller mer \u00e4n 5 kommentarer"},"content":{"rendered":"\n<p>N\u00e4r du driver en WordPress-blogg \u00e4r det viktigaste att <strong>tillhandah\u00e5lla originalinneh\u00e5ll av h\u00f6g kvalitet som engagerar l\u00e4sarna<\/strong>. Om du har n\u00e5gra <strong>popul\u00e4ra inl\u00e4gg med m\u00e5nga kommentarer b\u00f6r du \u00f6verv\u00e4ga att lyfta fram dessa heta \u00e4mnen<\/strong>. Det \u00e4r ett bra s\u00e4tt att f\u00e5nga l\u00e4sarnas uppm\u00e4rksamhet.<\/p>\n<p>Detta \u00e4r en <strong>mycket enkel modifiering, som inte kr\u00e4ver ett plugin<\/strong>, och det kan hj\u00e4lpa dig att visuellt filtrera inneh\u00e5ll p\u00e5 en blogglista och lyfta fram viktiga inl\u00e4gg. Du kan till exempel v\u00e4lja att markera alla inl\u00e4gg som inneh\u00e5ller fler \u00e4n 5 kommentarer.<\/p>\n<p>F\u00f6rst, l\u00e5t oss dyka lite i WordPress-k\u00e4rnfiler f\u00f6r att f\u00e5 en klar f\u00f6rst\u00e5else f\u00f6r den slutliga l\u00f6sningen.<\/p>\n<p>Om du gjorde n\u00e5gra \u00e4ndringar av temafiler tidigare har du f\u00f6rmodligen sett n\u00e5got s\u00e5nt h\u00e4r:<\/p>\n<pre><code>&lt;?php\n\/**\n* The template part for displaying single posts\n*\n* @package WordPress\n* @subpackage Twenty_Sixteen\n* @since Twenty Sixteen 1.0\n*\/\n?&gt;\n&lt;article id=\"post-&lt;?php the_ID(); ?&gt;\" &lt;?php post_class(); ?&gt;&gt;\n&lt;header class=\"entry-header\"&gt;\n&lt;?php the_title( '&lt;h1 class=\"entry-title\"&gt;', '&lt;\/h1&gt;' ); ?&gt;\n&lt;\/header&gt;&lt;!-- .entry-header --&gt;\n&lt;?php twentysixteen_excerpt(); ?&gt;\n&lt;?php twentysixteen_post_thumbnail(); ?&gt;\n&lt;div class=\"entry-content\"&gt;<\/code><\/pre>\n<pre><code> post_class<\/code><\/pre>\n<p>Om du s\u00f6ker efter post_Class i WordPress-k\u00e4rnfiler kan du enkelt hitta den h\u00e4r delen som finns inuti wp-includes\/post-template.php:<\/p>\n<pre><code>$classes = array_map( 'esc_attr', $classes );\n\/**\n* Filters the list of CSS classes for the current post.\n*\n* @since 2.7.0\n*\n* @param array $classes An array of post classes.\n* @param array $class An array of additional classes added to the post.\n* @param int $post_id The post ID.\n*\/\n$classes = apply_filters( 'post_class', $classes, $class, $post-&gt;ID );\nreturn array_unique( $classes );\n}<\/code><\/pre>\n<pre><code>apply_filters<\/code><\/pre>\n<p>V\u00e5r funktion f\u00f6r att uppn\u00e5 detta kommer att se ut s\u00e5 h\u00e4r:<\/p>\n<pre><code>\/**\n* Function for adding custom css class to post_class for posts with minimum number of comments\n* Then styling of hot-topic css class can be done inside child theme style.css file or from WP Back end &gt; Appearance &gt; Customize\n*\/\nif (! function_exists('wpklik_function_css_class_for_highly_commented_posts')) {\nfunction wpklik_function_css_class_for_highly_commented_posts($classes, $class, $post_id) {\n$min_comments = 5; \/\/ change this number to your liking\nif (is_archive() || is_home()) {\nif (get_comments_number() &gt;= $min_comments) {\n$classes[] = 'hot-topic';\n}\n}\nreturn $classes;\n}\nadd_filter('post_class', 'wpklik_function_css_class_for_highly_commented_posts', 10,3);\n}<\/code><\/pre>\n<p>Med v\u00e5r funktion kommer vi helt enkelt att bearbeta antalet kommentarer p\u00e5 blogglistan och arkivsidorna f\u00f6r varje inl\u00e4gg och om det antalet \u00e4r h\u00f6gre eller lika med v\u00e5rt \u00f6nskade l\u00e4gsta antal (som standard inst\u00e4llt p\u00e5 5), skickar vi v\u00e5rt anpassade heta \u00e4mne css-klass till dessa artiklar. Effektivt kommer detta att markera alla enstaka inl\u00e4gg med 5 eller fler kommentarer i dem.<\/p>\n<p>Om du nu bes\u00f6ker bloggen och granskar inl\u00e4gg som inneh\u00e5ller mer \u00e4n 5 kommentarer, kommer du att m\u00e4rka klass med heta \u00e4mne.<\/p>\n<pre><code>style.css<\/code><\/pre>\n<p>H\u00e4r \u00e4r ett exempel p\u00e5 koden som jag har anv\u00e4nt f\u00f6r detta \u00e4ndam\u00e5l:<\/p>\n<pre><code>article.hot-topic:before {\ncontent: \"Trending !\";\nposition: absolute;\nleft: -20px;\ntop: -20px;\ntransform: rotate(-7deg);\ncolor: red;\nfont-weight: 600;\n}\narticle.hot-topic .entry-title a {\ntext-decoration: underline;\n}\narticle.hot-topic .entry-title a:hover {\ncolor: red;\n}\narticle.hot-topic span.comments-link a {\ncolor: red;\nfont-weight: 600;\n}<\/code><\/pre>\n<p>Och slutresultatet \u00e4r detta:<\/p>\n<p><a href=\"https:\/\/themewp.inform.click\/wp-content\/uploads\/2022\/10\/post-280846-633e2e7b43d6f.jpg\" data-rel=\"lightbox\" ><img decoding=\"async\" class=\"SDStudio-light-box-enable SDStudio-editor-tools-md-imp\" src=\"https:\/\/themewp.inform.click\/wp-content\/uploads\/2022\/10\/post-280846-633e2e7b43d6f.jpg\" alt=\"Markera hett \u00e4mnesinl\u00e4gg som inneh\u00e5ller mer \u00e4n 5 kommentarer\" ><\/a><\/p>\n<p>Hoppas att n\u00e5gra av er kommer att tycka att detta \u00e4r intressant och anv\u00e4ndbart, i s\u00e5 fall, gl\u00f6m inte att dela.<\/p>\n<p><div id=\"PostUnique_PostSource\" style=\"padding-top: 50px\">Inspelningsk\u00e4lla:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/wpklik.com\" class=\"external external_icon\">wpklik.com<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Markera ett hett \u00e4mnesinl\u00e4gg som inneh\u00e5ller mer \u00e4n 5 kommentarer. Det \u00e4r enkelt och praktiskt. L\u00e4ra sig hur.<\/p>\n","protected":false},"author":1,"featured_media":274625,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[635,574,288],"tags":[850],"class_list":["post-372276","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogga","category-grunderna-i-wordpress","category-seo-10","tag-affiai-sv"],"_links":{"self":[{"href":"https:\/\/themewp.inform.click\/sv\/wp-json\/wp\/v2\/posts\/372276","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themewp.inform.click\/sv\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themewp.inform.click\/sv\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themewp.inform.click\/sv\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/themewp.inform.click\/sv\/wp-json\/wp\/v2\/comments?post=372276"}],"version-history":[{"count":0,"href":"https:\/\/themewp.inform.click\/sv\/wp-json\/wp\/v2\/posts\/372276\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themewp.inform.click\/sv\/wp-json\/wp\/v2\/media\/274625"}],"wp:attachment":[{"href":"https:\/\/themewp.inform.click\/sv\/wp-json\/wp\/v2\/media?parent=372276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themewp.inform.click\/sv\/wp-json\/wp\/v2\/categories?post=372276"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themewp.inform.click\/sv\/wp-json\/wp\/v2\/tags?post=372276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}