Verfasste Forenbeiträge

Ansicht von 15 Antworten – 1 bis 15 (von insgesamt 15)
  • Forum: Plugins
    Als Antwort auf: Bild aus ID erzeugen (Shortcode)
    Thread-Starter raoul_k

    (@raoul_k)

    …zu früh gefreut.

    Wenn ich den Code einsetze, lädt WordPress die Seite nicht. Dies ist der komplette Code mit dem ich arbeite

    <?php
    /**
     * Shortcode for Big Hero Images
     *
     */
    if(!class_exists('\Sui\Shortcodes')) {
    	throw new Exception('');
    }
    
    use \Sui\Shortcodes as Shortcodes;
    use \Sui\Shortcode as Shortcode;
    
    // this will register the shortcode below into the factory
    $result = Shortcodes::register('HeroImage');
    
    if(!$result) {
    	throw new Exception('Failed to register this example shortcode somehow..');
    }
    
    /**
     * This is an example shortcode. The tag name of the shortcode
     * may be determined by the classname.
     *
     * For more information see the source code of \Sui\Shortcode
     * at /lib/abstract/shortcode.php
     */
    class HeroImage extends Shortcode {
    
    	/**
    	 * Will be prepended to the shortcode
    	 * its tag name followed by an underscore.
    	 *
    	 * @var string
    	 */
    	protected $_tagNamePrefix = 'img';
    
    	/**
    	 * The shortcode's description.
    	 *
    	 * @var string
    	 */
    	protected $_description = 'Dieses Bild wird über die gesamte Breite angezeigt. Wähle das Bild aus und gib eine optionale Bildunterschrift ein. Der Bereich Content muss frei bleiben.';
    
    	/**
    	 * Indicates whether this is an enclosing shortcode.
    	 *
    	 * @var boolean
    	 */
    	protected $_enclosed = true;
    
    	/**
    	 * Defines the shortcode attributes and default values.
    	 *
    	 * @var array
    	 */
    	protected $_attributes = array(
    		'image_id' => '',
    		'bildunterschrift' => '',
    	);
    
    	/**
    	 * Class constructor
    	 *
    	 * Define the schema for your shortcode attributes here.
    	 * Or set a translated description for your shortcode here.
    	 */
    	public function __construct() {
    		parent::__construct();
    
    		//$this->_description = __('translated...', '
    
    		$this->_setSchemaAttribute('image_id', '', 'image');
    		$this->_setSchemaAttribute('bildunterschrift', '', 'text');
    	}
    
    	/**
    	 * Renders this shortcode.
    	 *
    	 * @param array $atts
    	 * @param string|null $content
    	 * @return string
    	 */
    	public function render($atts, $content = null) {
    		$atts = shortcode_atts($this->_attributes, $atts);
    
    		if(!$content) {
    			$content = '';
    		}
    
    		?>
    
    		<?php
        $image_id = $atts['image_id']; // attachment ID
        $image_attributes = wp_get_attachment_image_src( $image_id, 'large'); // returns an array
        $out = '<div class="fullwidtharticleimg photoswipe_gallery gallery-columns-3 gallery-size-thumbnail photoswipe_showme" style="position: relative;" data-pswp-uid="1"><figure class="msnry_item" style="position: absolute; left: 0px; top: 0px; padding-bottom: 10px !important;"><a href="';
    	$out .= $image_attributes[0];
    	$out .= '" data-size="1280x853"><img src="';
    	$out .= $image_attributes[0];
    	$out .= '" alt="" /></a><figcaption style="display: none; height: 0;" class="photoswipe-gallery-caption">';
    	$out .= $atts["bildunterschrift"];
    	$out .= '</figcaption></figure></div><div style="color: #696f7a; font-size: 13px; padding-bottom: 50px !important;">';
    	$out .= $atts["bildunterschrift"];
    	$out .= '</div>';
    
    	return $out; ?>

    …ich kann keinen direkten Fehler finden. Allerdings bin ich mir auch nicht sicher, an welcher Stelle dieser Code am besten eingesetzt werden sollte… Er wird nur in Artikeln benutzt, daher single.php? Oder doch in der functions.php?

    Forum: Plugins
    Als Antwort auf: Bild aus ID erzeugen (Shortcode)
    Thread-Starter raoul_k

    (@raoul_k)

    Ah, das war der entscheidende Hinweis. Vielen Dank!

    Habe es jetzt so zum Laufen gebracht:

    <?php
        $image_id = $atts['image_id']; // attachment ID
        $image_attributes = wp_get_attachment_image_src( $image_id, 'large'); // returns an array
        $out = '<div class="fullwidtharticleimg photoswipe_gallery gallery-columns-3 gallery-size-thumbnail photoswipe_showme" style="position: relative;" data-pswp-uid="1"><figure class="msnry_item" style="position: absolute; left: 0px; top: 0px;"><a href="';
    	$out .= $image_attributes[0];
    	$out .= '" data-size="1280x853"><img src="';
    	$out .= $image_attributes[0];
    	$out .= '" alt="" /></a><figcaption class="photoswipe-gallery-caption">';
    	$out .= $atts["bildunterschrift"];
    	$out .= '</figcaption></figure></div>';
    	return $out; ?>
    Forum: Plugins
    Als Antwort auf: Bild aus ID erzeugen (Shortcode)
    Thread-Starter raoul_k

    (@raoul_k)

    Haha 🙂 Oje, ich hoffe du hast dich erstmal von dem Schock erholt!

    Wenn ich alle echos durch return ersetze funktioniert es leider nicht, muss ich das noch anderweitig anpassen?

    Forum: Plugins
    Als Antwort auf: Bild aus ID erzeugen (Shortcode)
    Thread-Starter raoul_k

    (@raoul_k)

    Danke für den Code.

    Der Vorteil am Plugin ist, dass es direkt im WYSIWYG Editor einen einfach weg hinzufügt um die Image ID zu ermitteln. Da ich den Blog nicht alleine benutze, bietet dies für andere Autoren eine leichteren Weg.

    Mit folgender Codeänderung habe ich es geschafft, die Bilder per ID einzufügen

    if(!class_exists('\Sui\Shortcodes')) {
    	throw new Exception('');
    }
    
    use \Sui\Shortcodes as Shortcodes;
    use \Sui\Shortcode as Shortcode;
    
    // this will register the shortcode below into the factory
    $result = Shortcodes::register('HeroImage');
    
    if(!$result) {
    	throw new Exception('Failed to register this example shortcode somehow..');
    }
    
    /**
     * This is an example shortcode. The tag name of the shortcode
     * may be determined by the classname.
     *
     * For more information see the source code of \Sui\Shortcode
     * at /lib/abstract/shortcode.php
     */
    class HeroImage extends Shortcode {
    
    	/**
    	 * Will be prepended to the shortcode
    	 * its tag name followed by an underscore.
    	 *
    	 * @var string
    	 */
    	protected $_tagNamePrefix = 'img';
    
    	/**
    	 * The shortcode's description.
    	 *
    	 * @var string
    	 */
    	protected $_description = 'Dieses Bild wird über die gesamte Breite angezeigt. Wähle das Bild aus und gib eine optionale Bildunterschrift ein. Der Bereich Content muss frei bleiben.';
    
    	/**
    	 * Indicates whether this is an enclosing shortcode.
    	 *
    	 * @var boolean
    	 */
    	protected $_enclosed = true;
    
    	/**
    	 * Defines the shortcode attributes and default values.
    	 *
    	 * @var array
    	 */
    	protected $_attributes = array(
    		'image_id' => '',
    		'bildunterschrift' => '',
    	);
    
    	/**
    	 * Class constructor
    	 *
    	 * Define the schema for your shortcode attributes here.
    	 * Or set a translated description for your shortcode here.
    	 */
    	public function __construct() {
    		parent::__construct();
    
    		//$this->_description = __('translated...', '
    
    		$this->_setSchemaAttribute('image_id', '', 'image');
    		$this->_setSchemaAttribute('bildunterschrift', '', 'text');
    	}
    
    	/**
    	 * Renders this shortcode.
    	 *
    	 * @param array $atts
    	 * @param string|null $content
    	 * @return string
    	 */
    	public function render($atts, $content = null) {
    		$atts = shortcode_atts($this->_attributes, $atts);
    
    		if(!$content) {
    			$content = '';
    		}
    
    		?>
    
    		<?php
        $image_id = $atts['image_id']; // attachment ID
        $image_attributes = wp_get_attachment_image_src( $image_id, 'large'); // returns an array
    ?>
    
    		<div class="fullwidtharticleimg photoswipe_gallery gallery-columns-3 gallery-size-thumbnail photoswipe_showme" style="position: relative;" data-pswp-uid="1">
    			<figure class="msnry_item" style="position: absolute; left: 0px; top: 0px;">
    				<a href="<?php echo $image_attributes[0]; ?>" data-size="1280x853">
    					<img src="<?php echo $image_attributes[0]; ?>" alt="" />
    				</a>
    				<figcaption class="photoswipe-gallery-caption"><?php echo $atts['bildunterschrift'] ?></figcaption>
    			</figure>
    		</div>
    
    		<?php
    
    		// if enclosement allow nested shortcodes
    		if($this->_enclosed) {
    			$content = do_shortcode($content);
    		}
    
    		return $content;
    	}
    
    }

    Nun tritt allerdings ein neues Problem auf: Der ausgegebene Code erscheint nicht an der Stelle wo der Shortcode eingegeben wird, sondern immer direkt oben auf der Seite. Nach kurzem Googlen stellt sich heraus, dass dies kein seltener Fall bei Shortcode Funktionen ist. Das Problem scheint zu sein, dass ich in der functions.php per echo ausgebe und dies eher mit return tun sollte, soweit ich das verstanden habe. Ein Lösungsansatz sei dieser:

    ob_start();
    my_func_plugin();
    $output_string=ob_get_contents();;
    ob_end_clean();
    
    return $output_string;

    Ich kriege es leider partout nicht hin, dies in meinen Code einzuarbeiten… Wäre für Hilfe unglaublich dankbar.

    Forum: Installation
    Als Antwort auf: Suche funktioniert nicht
    Thread-Starter raoul_k

    (@raoul_k)

    Aha! Wenn ich das aus der .htaccess nehme geht alles in der Tat!

    Der Hintergrund ist folgender:
    Ich möchte dass die „Home“ meiner Domain, also die ganze normale Domain weiterleitet. Sprich http://www.domain.de soll es nicht geben, sondern immer weitergeleitet werden zu http://www.domain.de/start. Artikel sollen dies allerdings nicht „mitnehmen“, sondern http://www.domain/artikel haben.

    Ich habe jetzt die Weiterleitung umgebaut und nun geht auch die Suche. Vielen dank!!

    Forum: Installation
    Als Antwort auf: Suche funktioniert nicht
    Thread-Starter raoul_k

    (@raoul_k)

    Ich habe jetzt auf die „Punkt-Lösung“ verzichtet und stattdessen mit dem Yoast Plugin „category“ aus den Permalinks entfernt.

    An der eigentlichen Problematik ändert dies allerdings nicht.

    Forum: Installation
    Als Antwort auf: Suche funktioniert nicht
    Thread-Starter raoul_k

    (@raoul_k)

    Danke für den Tipp. Ich gucke mir das mal an. Bisher hatte ich ansonsten allerdings keinerlei Probleme damit.

    Forum: Installation
    Als Antwort auf: Suche funktioniert nicht
    Thread-Starter raoul_k

    (@raoul_k)

    Hey Torsten.

    Damit versteckt WordPress den Kategorie/Tag Slug in der URL:
    http://premium.wpmudev.org/blog/removing-category-base-urls-wordpress/

    Forum: Installation
    Als Antwort auf: Suche funktioniert nicht
    Thread-Starter raoul_k

    (@raoul_k)

    Ich habe dazu folgendes online gefunden, ich schätze dass dies auch mein Problem sein könnte.

    Possibly because each blog post is in a new directory. Here’s an example. You have your root HTML directory, your homepage, where the search works fine (http://srkdesign.com/?s=search). But when you click a post, it’s the equivalent of going up a directory (http://srkdesign.com/wordpress-3-0/?s=search) which returns a 404. Adding a
    ../
    should fix it.

    Allerdings habe ich es bisher noch nicht geschafft diesen Lösungsansatz zum Laufen zu bringen. Habe in der searchform.php

    <form role="search" method="get" class="search-form" action="<?php echo home_url( '../' ); ?>">

    geändert. Dies klappt nicht. Benutze ich das „../“ an der falschen Stelle oder ist es doch ein anderes Problem?

    Meine Bloghomepage liegt auf [url]/unbekannt ([url] leitet auch hierhin um)
    Einzelne Einträge liegen in [url]/kategorie/eintrag-titel

    Die Suche sucht also auf [url]/unbekannt/?s=suche, sollte aber auf [url]/?s=suche suchen.

    Thread-Starter raoul_k

    (@raoul_k)

    Ja, vielleicht wäre das einer Überlegung wert! Und danke für den Tipp mit den Developer Tools. Leider ist auch die dort zu findende Stelle nicht sonderlich aufschlussreich. Vermutlich sind es zwei Plugins, die sich nicht miteinander verstehen… Dem muss ich wohl nochmal nachgehen. Erst einmal vielen Dank.

    Thread-Starter raoul_k

    (@raoul_k)

    Vielen Dank für den Tipp! Den Teil des Codes habe ich geändert.

    Wenn ich das Plugin deaktiviere bekomme ich keinerlei Fehler ausgespuckt, mit Plugin allerdings:

    Uncaught RangeError: Maximum call stack size exceeded
    a2a.dom.ready @ page.js:1
    h @ page.js:1

    page.js ist allerdings so komprimiert, dass alles in einer Zeile ist und ich so den Fehler nicht so einfach finden kann. Ich fürchte dass es im Javascript irgendwo quasi einen unendlichen Loop oder ähnliches gibt… Bisher konnte ich den Fehler aber partout nicht ausfindig machen.

    Ich habe zu dem Thema folgendes gefunden, bin mir aber nicht sicher ob dies wirklich den Fehler hervorruft:
    http://stackoverflow.com/questions/12426208/what-makes-an-uncaught-rangeerror-maximum-call-stack-size-exceeded-error-ch
    https://theeventscalendar.com/support/forums/topic/bug-in-mapview-uncaught-rangeerror-maximum-call-stack-size-exceeded/

    Auf einer Seite, wo nur die Map aufgerufen wird (http://bit.ly/1OXo3Ho) gibt es allerdings keine Fehler…

    Thread-Starter raoul_k

    (@raoul_k)

    …mit showposts statt posts_per_page hat es geklappt. Nun ist also alles, wie ich es mir vorgestellt hatte.

    Vielen lieben Dank für die Hilfsbereitschaft am Wochenende 😉

    Thread-Starter raoul_k

    (@raoul_k)

    … Das ist jetzt ein wenig peinlich 😉

    In der Tat habe ich einfach die ganze Zeit an der falschen Datei gearbeitet. Meine Änderung hatte ich am parent-theme gemacht, obwohl diese von einem child-theme File überschrieben wurde. Jetzt funktioniert es. 1000 Dank!! Allerdings zeigt WordPress mir nun auf einmal ALLE Beiträge an, vorher hatte ich durch $posts_per_page = '4'; die Anzahl definiert.

    Thread-Starter raoul_k

    (@raoul_k)

    Ja, diese lautet travel-directory.

    Thread-Starter raoul_k

    (@raoul_k)

    Hi Bego Mario Garde.

    Erst einmal tausend Danke für deine schnelle und ausführliche Antwort. Soweit habe ich, dass was du geschrieben hast verstanden und zum grundsätzlichen Verständnis hat mir das bereits sehr weitergeholfen (ich muss dazu sagen, dass ich – wie du vermutlich merkst – noch nicht so viel Erfahrungen mit PHP habe).

    Wenn ich das richtig verstanden habe, müsste WordPress mir dann bei diesem Code auch die travel directory Beiträge mit auswerfen… Allerdings klappt das nicht.

    $args = array (
    	'post_type'              => array( 'travel-directory' ),
    );
    
    $the_query = new WP_Query( $args );
    
    if ( $the_query->have_posts() ) {
    
    				<?php
    				while ( $the_query->have_posts() ) : $the_query->the_post();
    
    					get_template_part( 'content-post'.$template_part, get_post_format() );
    
    				endwhile;
    
    				/* Restore original Post Data */
    				wp_reset_postdata();
    
    				?>
    
    	<?php
    
    } // end have_posts()

    Was mache ich falsch?

    Danke für die Hilfe!!

Ansicht von 15 Antworten – 1 bis 15 (von insgesamt 15)