Pagina 1 din 4 123 ... UltimulUltimul
Rezultate 1 la 10 din 36

Subiect: Probleme custom sorting Wordpress

  1. #1
    Avatarul lui Nichita
    Nichita este deconectat Super Moderator
    Reputatie:
    94
    Data înscrierii
    19th February 2009
    Locaţie
    Bucuresti
    Vârstă
    45
    Posturi
    3.421
    Putere Rep
    94


    Implicit Probleme custom sorting Wordpress

    Folosesc acest plugin pentru a afisa la sfarsitul postului cateva posturi related. Problema este ca la fiecare refresh, posturile respective se schimba.

    As vrea ca in zona respectiva sa fie afisate cele 4 posturi anterioare din categorie. De exemplu la postul nr. 56, in zona respectiva sa fie afisate posturile 55, 54, 53, 52 etc.

    Mi-am bagat nasul prin plugin, dar fiind paralel cu php-ul mi-am cam prins nasul. Codul care banuiesc ca trebuie modificat pentru ceea ce doresc este:
    Cod:
    $order= " ORDER BY rand() LIMIT " . $posts_number;  
    $random_posts = $wpdb->get_results( $query . $join . $where  . $order );
    
    		/* Get posts by their IDs */
    		if ( !is_array( $random_posts ) || count( $random_posts ) < 1 ) {
    			return $this->finish_process( $output, $debug . 'No posts matching relationships criteria;', $time );
    		}
    
    		$posts_in = array();
    		foreach ($random_posts as $random_post)
    			$posts_in[] = $random_post->ID;
    Exista vreo solutie viabila pentru ceea ce vreau sa fac ?
    Siteul tau e in balarii, nu urca? Competitorii te bat de iti suna apa in cap? Ai fost penalizat si nu stii ce sa faci? Cel mai probabil ai nevoie de un audit SEO complet. :)

  2. #2
    Avatarul lui kleampa
    kleampa este deconectat Ambasador
    Reputatie:
    54
    Data înscrierii
    31st May 2006
    Locaţie
    Bucuresti
    Vârstă
    37
    Posturi
    1.598
    Putere Rep
    54


    Implicit

    nu ne-ai dat toata bucata de cod. teoretic trebuie sa pui in $wpdb->get_results($aici) , query-ul care sa scoata posturile publicate cu id mai mic decat cel curent in ordine descendenta dupa id si limitat la 4 rezultate

  3. #3
    Avatarul lui Nichita
    Nichita este deconectat Super Moderator
    Reputatie:
    94
    Data înscrierii
    19th February 2009
    Locaţie
    Bucuresti
    Vârstă
    45
    Posturi
    3.421
    Putere Rep
    94


    Implicit

    Cod:
    <?php /*
      Plugin Name:  Related Posts Thumbnails
      Plugin URI:   http://wordpress.shaldybina.com/plugins/related-posts-thumbnails/
      Description:  Showing related posts thumbnails under the post.
      Version:      1.3.1
      Author:       Maria Shaldybina
      Author URI:   http://shaldybina.com/
    */
    /*  Copyright 2010  Maria I Shaldybina
    
    	This program is free software; you can redistribute it and/or modify
    	it under the terms of the GNU General Public License as published by
    	the Free Software Foundation; either version 2 of the License, or
    	(at your option) any later version.
    
    	This program is distributed in the hope that it will be useful,
    	but WITHOUT ANY WARRANTY; without even the implied warranty of
    	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    	GNU General Public License for more details.
    */
    class RelatedPostsThumbnails {
    	/* Default values. PHP 4 compatible */
    	var $single_only = '1';
    	var $auto = '1';
    	var $top_text = '<h3>Related posts:</h3>';
    	var $number = 3;
    	var $relation = 'categories';
    	var $poststhname = 'thumbnail';
    	var $background = '#FFFFFF';
    	var $hoverbackground = '#EEEEEF';
    	var $border_color = '#DDDDDD';
    	var $font_color = '#333333';
    	var $font_family = 'Arial';
    	var $font_size = '12';
    	var $text_length = '100';
    	var $excerpt_length = '0';
    	var $custom_field = '';
    	var $custom_height = '100';
    	var $custom_width = '100';
    	var $text_block_height = '75';
    	var $thsource = 'post-thumbnails';
    	var $categories_all = '1';
    	var $devmode = '0';
    	var $output_style = 'div';
    	var $post_types = array('post');
    	var $custom_taxonomies = array();
    
    	function RelatedPostsThumbnails() { // initialization
    		load_plugin_textdomain( 'related-posts-thumbnails', false, basename( dirname( __FILE__ ) ) . '/locale' );
    		$this->default_image = WP_PLUGIN_URL . '/related-posts-thumbnails/img/default.png';
    		if ( get_option( 'relpoststh_auto', $this->auto ) )
    			add_filter( 'the_content', array( $this, 'auto_show' ) );
    		add_action( 'admin_menu',  array( $this, 'admin_menu' ) );
    		add_shortcode( 'related-posts-thumbnails' , array( $this, 'get_html' ) );
    		$this->wp_version = get_bloginfo('version');
    	}
    
    	function auto_show( $content ) { // Automatically displaying related posts under post body
    		return $content . $this->get_html( true );
    	}
    
    	function get_html( $show_top = false ) { // Getting related posts HTML
    		if ( $this->is_relpoststh_show() )
    			return $this->get_thumbnails( $show_top );
    		return '';
    	}
    
    	function get_thumbnails( $show_top = false ) { // Retrieve Related Posts HTML for output
    		$output = '';
    		$debug = 'Developer mode initialisation; Version: 1.2.9;';
    		$time = microtime(true);
    		$posts_number = get_option( 'relpoststh_number', $this->number );
    		if ( $posts_number <= 0 ) // return nothing if this parameter was set to <= 0
    			return $this->finish_process( $output, $debug . 'Posts number is 0;', $time );
    		$id = get_the_ID();
    		$relation = get_option( 'relpoststh_relation', $this->relation );
    		$poststhname = get_option( 'relpoststh_poststhname', $this->poststhname );
    		$text_length = get_option( 'relpoststh_textlength', $this->text_length );
    		$excerpt_length = get_option( 'relpoststh_excerptlength', $this->excerpt_length );
    		$thsource = get_option( 'relpoststh_thsource', $this->thsource );
    		$categories_show_all = get_option( 'relpoststh_show_categoriesall', get_option( 'relpoststh_categoriesall', $this->categories_all ) );
    		$onlywiththumbs = ( current_theme_supports( 'post-thumbnails' ) && $thsource == 'post-thumbnails' ) ? get_option( 'relpoststh_onlywiththumbs', false) : false;
    		$post_type = get_post_type();
    
    		global $wpdb;
    
    		/* Get taxonomy terms */
    		$debug .= "Relation: $relation; All categories: $categories_show_all;";
    		$use_filter = ( $categories_show_all != '0' || $relation != 'no' );
    
    		if ( $use_filter ) {
    			$query_objects = "SELECT distinct object_id FROM $wpdb->term_relationships WHERE 1=1 ";
    
    			if ( $relation != 'no' ) { /* Get object terms */
    				if ( $relation == 'categories' )
    					$taxonomy = array( 'category' );
    				elseif ( $relation == 'tags' )
    					$taxonomy = array( 'post_tag' );
    				elseif ( $relation == 'custom') {
    					$taxonomy = get_option( 'relpoststh_custom_taxonomies', $this->custom_taxonomies );
    				}
    				else {
    					$taxonomy = array( 'category', 'post_tag' );
    				}
    				$object_terms = wp_get_object_terms( $id, $taxonomy, array( 'fields' => 'ids' ) );
    				if ( empty( $object_terms ) || !is_array( $object_terms ) ) // no terms to get taxonomy
    					return $this->finish_process( $output, $debug . 'No taxonomy terms to get posts;', $time );
    
    				$query = "SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id in ('". implode( "', '", $object_terms ) . "')";
    				$object_taxonomy = $wpdb->get_results( $query );
    				$object_taxonomy_a = array();
    				if ( count( $object_taxonomy ) > 0 ) {
    					foreach ( $object_taxonomy as $item )
    						$object_taxonomy_a[] = $item->term_taxonomy_id;
    				}
    				$query_objects .= " AND term_taxonomy_id IN ('". implode( "', '", $object_taxonomy_a ) . "') ";
    			}
    
    			if ( $categories_show_all != '1' ) { /* Get filter terms */
    				$select_terms = get_option( 'relpoststh_show_categories',
    											get_option( 'relpoststh_categories' ) );
    				if ( empty( $select_terms ) || !is_array( $select_terms ) ) // if no categories were specified intentionally return nothing
    					return $this->finish_process( $output, $debug . 'No categories were selected;', $time );
    
    				$query = "SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id in ('". implode( "', '", $select_terms ) . "')";
    				$taxonomy = $wpdb->get_results( $query );
    				$filter_taxonomy_a = array();
    				if ( count( $taxonomy ) > 0 ) {
    					foreach ($taxonomy as $item)
    						$filter_taxonomy_a[] = $item->term_taxonomy_id;					
    				}
    				if ($relation != 'no') {
    					$query_objects .= " AND object_id IN (SELECT distinct object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN ('". implode( "', '", $filter_taxonomy_a ) . "') )";
    				}
    				else {
    					$query_objects .= " AND term_taxonomy_id IN ('". implode( "', '", $filter_taxonomy_a ) . "')";
    				}
    			}
    
    			$relationships = $wpdb->get_results( $query_objects );
    			$related_objects = array();
    			if ( count( $relationships ) > 0 ) {
    				foreach ($relationships as $item)
    					$related_objects[] = $item->object_id;
    			}
    		}
    
    		$query = "SELECT distinct ID FROM $wpdb->posts ";
    		$where = " WHERE post_type = '" . $post_type . "' AND post_status = 'publish' AND ID<>" . $id; // not the current post
    		$startdate = get_option( 'relpoststh_startdate' );
    		if ( !empty( $startdate ) && preg_match( '/^\d\d\d\d-\d\d-\d\d$/', $startdate ) ) { // If startdate was set
    			$debug .= "Startdate: $startdate;";
    			$where .= " AND post_date >= '" . $startdate . "'";
    		}
    		if ( $use_filter ) {
    			$where .= " AND ID IN ('". implode( "', '", $related_objects ) . "')";
    		}
    		$join = "";
    		if ( $onlywiththumbs ) {
    			$debug .= "Only with thumbnails;";
    			$join = " INNER JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)";
    			$where .= " AND $wpdb->postmeta.meta_key = '_thumbnail_id'";			
    		}
    Asta e prima parte a codului, dupa care urmeaza ceea ce deja am postat.
    Siteul tau e in balarii, nu urca? Competitorii te bat de iti suna apa in cap? Ai fost penalizat si nu stii ce sa faci? Cel mai probabil ai nevoie de un audit SEO complet. :)

  4. #4
    Avatarul lui Toto
    Toto este deconectat Ambasador
    Reputatie:
    48
    Data înscrierii
    14th June 2005
    Locaţie
    Bucuresti
    Posturi
    1.905
    Putere Rep
    48


    Implicit

    Nu cumva acel:
    $order= " ORDER BY rand()
    iti sorteaza random astfel incat iti returneaza 4 posturi random, nu ordonate dupa id, data, desccrescator cum ai vrea tu.. ?!

    Incearca cu:
    ORDER BY ID DESC
    sau

    ORDER BY post_date DESC

  5. #5
    Avatarul lui Nichita
    Nichita este deconectat Super Moderator
    Reputatie:
    94
    Data înscrierii
    19th February 2009
    Locaţie
    Bucuresti
    Vârstă
    45
    Posturi
    3.421
    Putere Rep
    94


    Implicit

    Acel rand sorteaza posturile din categorie, random, la fiecare refresh. Daca modific cu ceea ce mi-ai dat tu, nu mai functioneaza, adica nu mai afiseaza nici un post related.
    Siteul tau e in balarii, nu urca? Competitorii te bat de iti suna apa in cap? Ai fost penalizat si nu stii ce sa faci? Cel mai probabil ai nevoie de un audit SEO complet. :)

  6. #6
    Avatarul lui puthre
    puthre este deconectat Ambasador
    Reputatie:
    83
    Data înscrierii
    21st February 2011
    Locaţie
    București
    Posturi
    2.154
    Putere Rep
    83


    Implicit

    Citat Postat în original de Nichita Vezi Post
    Acel rand sorteaza posturile din categorie, random, la fiecare refresh. Daca modific cu ceea ce mi-ai dat tu, nu mai functioneaza, adica nu mai afiseaza nici un post related.
    Ai gresit tu ceva. Probabil ca ai uitat sa pui si LIMIT. Pune aici codul cum l-ai modificat.
    Caut cu jingle.ro.

  7. #7
    Avatarul lui Nichita
    Nichita este deconectat Super Moderator
    Reputatie:
    94
    Data înscrierii
    19th February 2009
    Locaţie
    Bucuresti
    Vârstă
    45
    Posturi
    3.421
    Putere Rep
    94


    Implicit

    Codul este prea lung ca sa incapa intr-un post. L-am atasat ca si txt.
    Fișiere atașate Fișiere atașate
    Siteul tau e in balarii, nu urca? Competitorii te bat de iti suna apa in cap? Ai fost penalizat si nu stii ce sa faci? Cel mai probabil ai nevoie de un audit SEO complet. :)

  8. #8
    Avatarul lui Toto
    Toto este deconectat Ambasador
    Reputatie:
    48
    Data înscrierii
    14th June 2005
    Locaţie
    Bucuresti
    Posturi
    1.905
    Putere Rep
    48


    Implicit

    Nichita, am instalat pluginul la mine pe un WP, am modificat linia:

    $order= " ORDER BY rand() LIMIT " . $posts_number;
    cu

    $order = " ORDER BY ID DESC LIMIT " . $posts_number;
    Si imi afiseaza mereu aceleasi 3 posturi ... fara random ... Deci, ar trebui sa mearga si la tine fara probleme...

  9. #9
    Avatarul lui robciucioan
    robciucioan este deconectat Membru SeoPedia
    Reputatie:
    29
    Data înscrierii
    22nd December 2010
    Locaţie
    Suceava
    Vârstă
    31
    Posturi
    304
    Putere Rep
    29


    Implicit

    @Nichita - Cum vrei să afișeze acele posturi? După o categorie sau tag? Daca da, atunci te-aș putea ajuta cu o funcție WP, fără să mai instalezi vreun plugin.
    Nimic interesant...

  10. #10
    Avatarul lui Toto
    Toto este deconectat Ambasador
    Reputatie:
    48
    Data înscrierii
    14th June 2005
    Locaţie
    Bucuresti
    Posturi
    1.905
    Putere Rep
    48


    1 out of 1 members found this post helpful.

    Implicit

    Citat Postat în original de robciucionut Vezi Post
    @Nichita - Cum vrei să afișeze acele posturi? După o categorie sau tag?
    Suntem si noi un pic atenti si citim posturile celorlalti?

    As vrea ca in zona respectiva sa fie afisate cele 4 posturi anterioare din categorie.

Pagina 1 din 4 123 ... UltimulUltimul

Informații subiect

Utilizatori care navighează în acest subiect

Momentan este/sunt 1 utilizator(i) care navighează în acest subiect. (0 membrii și 1 vizitatori)

Thread-uri Similare

  1. Tema wp custom
    De Claudiu B în forumul Servicii web / Jobs
    Răspunsuri: 4
    Ultimul Post: 7th February 2012, 11:30
  2. Excerpt-uri custom
    De Antonie George în forumul Discutii generale privind optimizarea si motoarele de cautare
    Răspunsuri: 3
    Ultimul Post: 2nd April 2011, 16:37
  3. Răspunsuri: 2
    Ultimul Post: 25th January 2011, 17:13
  4. Caracterul " in Custom field WordPress
    De ConstantinLG în forumul Server side
    Răspunsuri: 4
    Ultimul Post: 26th September 2009, 14:59
  5. Custom AdSense For Wordpress
    De Nosfer în forumul Adsense
    Răspunsuri: 6
    Ultimul Post: 9th March 2009, 00:54

Permisiuni postare

  • Nu puteţi posta subiecte noi.
  • Nu puteţi răspunde la subiecte
  • Nu puteţi adăuga ataşamente
  • Nu puteţi modifica posturile proprii
  •