Sticki post mai dinamic.

Majoritatea cunoasteti faptul ca in wordpress poti sa faci un articol sticki.Adica sa fie mereu primul dintre articole si ce le mai recente in continuare.Vezi foto.

Acum lucrez la o tema si am implementat cateva coduri care sa faca mai dinamic un articol sticki si as vrea sa va arat codurile…

In primul rand avem acest cod care se pune in function.php

[codesyntax lang=”php” container=”div” blockstate=”expanded”]

add_action( 'pre_get_posts', 'ebox_home_query' );
if ( ! function_exists( 'ebox_home_query' ) ) :

function ebox_home_query( $query = '' ) {
	if ( ! is_home() || ! is_a( $query, 'WP_Query' ) || ! $query->is_main_query() )
		return;

	$query->set( 'post__not_in', get_option( 'sticky_posts' ) );
}
endif;

[/codesyntax]

Urmatorul cod intra in index.php deasupra codurilor pentru afisarea articolului cat si a divurilor pentru continut,vezi foto.

[codesyntax lang=”php” container=”div” blockstate=”expanded”]

<?php
		$sticky = get_option( 'sticky_posts' );
		$featured = new WP_Query( array(
			'posts_per_page' => 1,
			'post__in'  => $sticky,
			'ignore_sticky_posts' => 1
		) );
		if ( ! empty( $sticky[0] ) && is_home() && 2 > $paged ) {
		?>

		<div id="featured">

			<div class="c12">

				<?php
				while ( $featured->have_posts() ) : $featured->the_post();

					get_template_part( 'content', get_post_format() );

				endwhile;

				wp_reset_postdata();
				?>

			</div>

		</div>

		<?php } ?>

[/codesyntax]

Atentie: unde este linia get_template_part…   trebuie modificat conform codurilor din index.php al vostru pentru articole ca sa fie functional codul.

In style.css avem acest cod.

[codesyntax lang=”css” container=”div” blockstate=”expanded”]

/* =Featured
-------------------------------------------------------------- */
#featured, #featured article {
	text-shadow: none;
        color: red;
        background: #fff;
        margin-bottom: 0;
	}

	#featured .c12 {
		margin: 10px 0 0;
		}

/* =Sticky
-------------------------------------------------------------- */
.sticky {
	background: rgba( 50,50,50,0.4);
	border: 1px solid #777;
	padding: 40px;
	color: #eee;
	border-radius: 6px;
	}

[/codesyntax]

Demo puteti sa vedeti direct din tema la care lucrez.

[symple_button color=”blue” url=”http://demo.bucurion.info/” title=”Visit Site” target=”blank” border_radius=””]Demo sticki post[/symple_button]

Recomandarea mobila la comanda ieftina si de durata http://www.tamos.ro/.
 

Lasă un răspuns

Adresa ta de email nu va fi publicată. Câmpurile obligatorii sunt marcate cu *

Alte articole Populare